Originally posted by: Joce22
Hi,
I am new to cplex and I want to use cplex to solve the linear relaxation of the restricted master problem (RMP) for a branch and price procedure. However, I am having some difficulties with extracting the dual values from the rmp. The initial model in lp format is in the attached. Below is the code where I initialised the model and subsequently added one new column to the model (as I only let my code to loop through twice and obtained 2 sets of dual values).
try {
IloModel model(env);
IloNumVarArray route(env); // variables
IloObjective obj = IloMaximize(env); // obj function
IloRangeArray constraints(env); // N+1 constraints
constraints.add(IloRange(env, -IloInfinity, 4)); // number of providers
for (int i = 1; i <= N; i++) {
constraints.add(IloRange(env, -IloInfinity, 1));
}
for (size_t i = 0; i != routeset.size(); i++) {
IloNumColumn column = obj(routeprofit[i]);
column += constraints[0](1);
for (int j = 1; j <= N; j++) {
column += constraints[j](vertexpathvisit[j][i]);
}
IloNumVar var(column, 0, 1);
route.add(var);
column.end();
}
model.add(constraints);
model.add(obj);
IloCplex cplex(model);
cplex.exportModel("model.lp");
// solve pricing problem
vector<int> bestpathseq;
for (int j = 0; j<2; j++) { // loop through twice
if (!cplex.solve()) {
env.error() << "Failed to optimize LP." << endl;
throw(-1);
}
for (int i = 0; i <= N; i++) {
modi_profit[i] = profit[i] - cplex.getDual(constraints[i]);
//cout << " " << cplex.getDual(constraints[i]) << endl;
}
env.out() << "Solution value = " << cplex.getObjValue() << endl;
if (solve_priceproblem(modi_profit, bestpathseq) < 0) break;
IloNumColumn column = obj(profit_bestpath);
column += constraints[0](1);
for (int j = 1; j <= N; j++) {
column += constraints[j](vertexpathvisit[j][routeprofit.size() - 1]);
}
IloNumVar var(column, 0, 1);
route.add(var);
column.end();
}
}
At the first iteration, I obtained the dual values from cplex and used it to solve the pricing problem where a new decision variable x51 will be created with a coefficient of 270 in the objective function.
At the second iteration, the dual values given by the cplex do not seem to be correct. I think it has something to do with using devex in the second iteration. This is because the dual values obtained (if I were to sum them all up) correspond to the objective value given by devex instead of the objective value given by cplex.getObjValue(). May I know what devex is, and why the objective value given by devex is different from the objective value given by cplex.getObjValue() (in the output.png file). I am not sure if I am making myself clear but will appreciate a lot if anyone can help to answer my question. Thank you!
#CPLEXOptimizers#DecisionOptimization