/**純記錄用。不是完整的程式碼。**/

#include "glpk.h"

struct MBdata;

void MILPsolver(MBdata &file){ 
READ file;
int row_num = 4 * i - 2; //constraint numbers
int col_num = 5 * i; // var numbers
//Begin Setting Maxband Problem
 
//Setting up the optimization problem
glp_prob *mip = glp_create_prob();
glp_set_prob_name(mip, "sample");
glp_set_obj_dir(mip, GLP_MAX); //設立求解問題為Max/Min
glp_add_rows(mip, row_num); //以Matrix表示問題
glp_add_cols(mip, col_num);
int count = 0;
double RHS;
/**row set**/ //限制式設置
for (int a = 0; a < i; a++){
RHS = gt[a];
glp_set_row_name(mip, count, NULL); //該行(row)名稱
glp_set_row_bnds(mip, count, GLP_UP, 0.0, RHS); //(問題, 標號, 大於/小於Right hand side, 下界, 上界)
count++;
}
/**column set**/ //變數設置(variable bounds)
count = 0;
for (int a = 0; a < i; a++){ 
glp_set_col_name(mip, count, NULL);
glp_set_col_bnds(mip, count, GLP_LO, 0.0, 0.0); //bound
glp_set_obj_coef(mip, count, 0); //coef in obj. function
count++;
}
/**matrix set**/ //限制式參數設置
int coef_num = 12 * i - 10; //問題矩陣內各限制式係數個數總和
int ia[coef_num], ja[coef_num]; //ia: 該係數的row count, ja: 該係數的column count
double ar[coef_num]; //係數值
count = 0;
int w_start = 0;
int wb_start = i;
int b_start = 2*i;
int bb_start = 2*i+1;
int offset_start = 2*i+2;
int m_start = 3*i+2;
int x = 0;
int y = 0;
int z = 0;
int w = 0;
x = w_start;
for (int a = 0; a < i; a++){ //w + b <= g
ia[count] = a; //w
ja[count] = x;
ar[count] = 1;
x++;
count++;
ia[count] = a; //b
ja[count] = b_start;
ar[count] = 1;
count++;
}
//---Runing---
glp_load_matrix(mip, coef_num, ia, ja, ar);
glp_iocp parm;
glp_init_iocp(&parm);
parm.presolve = GLP_ON;
int err = glp_intopt(mip, &parm);
   
double sol_val[col_num];
for (int a = 0; i < col_num; a++)
sol_val[a] = glp_mip_col_val(mip, a);


}

朝歌 發表在 痞客邦 PIXNET 留言(0) 人氣()