Originally posted by: SystemAdmin
Hi,
I'm using the C++ API Cplex 12.2. When I build and solve a model, I end up with a 'mystery variable' id## that equals zero. It doesn't affect the result, but I don't like not knowing why it's happening. Here's an example model:
\Problem name: IloCplex
Maximize
obj: x1 + 2 x2 + 3 x3 + id10
Subject To
c1: - x1 + x2 + x3 <= 20
c2: x1 - 3 x2 + x3 <= 30
Bounds
0 <= x1 <= 40
id10 = 0
End
Generated by the code:
IloEnv env;
try {
IloModel model(env);
IloNumVarArray var(env);
IloRangeArray con(env);
var.add(IloNumVar(env, 0.0, 40.0));
var.add(IloNumVar(env));
var.add(IloNumVar(env));
model.add(IloMaximize(env, var[0] + 2 * var[1] + 3 * var[2]));
con.add( - var[0] + var[1] + var[2] <= 20);
con.add( var[0] - 3 * var[1] + var[2] <= 30);
var[0].setName("x1");
var[1].setName("x2");
var[2].setName("x3");
con[0].setName("c1");
con[1].setName("c2");
model.add(con);
IloCplex cplex(model);
// Optimize the problem and obtain solution.
if ( !cplex.solve() ) {
env.error() << "Failed to optimize LP" << endl;
throw(-1);
}
IloNumArray vals(env);
env.out() << "Solution status = " << cplex.getStatus() << endl;
env.out() << "Solution value = " << cplex.getObjValue() << endl;
cplex.getValues(vals, var);
env.out() << "Values = " << vals << endl;
cplex.getSlacks(vals, con);
env.out() << "Slacks = " << vals << endl;
cplex.getDuals(vals, con);
env.out() << "Duals = " << vals << endl;
cplex.getReducedCosts(vals, var);
env.out() << "Reduced Costs = " << vals << endl;
cplex.exportModel("test.lp");
}
catch (IloException& e) {
cerr << "Concert exception caught: " << e << endl;
}
catch (...) {
cerr << "Unknown exception caught" << endl;
}
I don't have this variable when using the Python API. Any help would be much appreciated. Thanks!
#CPLEXOptimizers#DecisionOptimization