Hello everyone,
I'm diving into concert technology for the first time and I'm currently navigating through the process of extracting the solution after solving a problem. I've managed to read the formulation from a .mod file using C++, but I could use some guidance on retrieving the values of decision variables. Additionally, I'm curious about the approach for extracting values if my dvar is a multi-dimensional array.
Appreciate any insights or advice!
dvar float+ x1;
dvar float+ x2;
maximize
12*x1 + 9*x2;
subject to {
x1 <= 1000;
x2 <= 1500;
x1 +x2 <= 1750;
4*x1 + 2*x2 <= 4800;
}
Here is my C++ program.
try {
IloNum curr = IloInfinity;
IloOplErrorHandler errHandler(env, cout);
IloOplSettings settings(env, errHandler);
settings.setWithWarnings(IloFalse);
IloOplModelSource masterSource(env, "C:\\LOCATION.mod");
IloOplModelDefinition masterDef(masterSource, settings);
IloCplex masterCplex(env);
IloOplModel oplModel(masterDef, masterCplex);
masterCplex.setOut(env.getNullStream());
masterCplex.setParam(IloCplex::TiLim, 30);
IloOplRunConfiguration masterRC(masterDef);
masterRC.setCplex(masterCplex);
IloOplModel masterOpl = masterRC.getOplModel();
masterOpl.generate();
cout << masterCplex.getModel() << endl;
cout << "Solve master." << endl;
if (masterCplex.solve()) {
curr = masterCplex.getObjValue();
cout << endl
<< "MASTER OBJECTIVE: " << fixed << setprecision(2) << curr
<< endl;
//cout << masterOpl.getElement("x1") << endl;
// cout << masterCplex.getValue(x2) << endl;
status = 0;
}
else {
cout << "No solution!" << endl;
status = 1;
}
}
------------------------------
Dheeban Kumar Srinivasan Sampathi
------------------------------