Originally posted by: SystemAdmin
[aroso said:]
You need to tell CPLEX what variable you want to get:
#include <ilcplex/ilocplex.h>
ILOSTLBEGIN
ILOMIPCALLBACK1(MyCallback) {
if ( getObjValue() >= 20 ) {
IloNumVar DVar(env);
DVar = opl.getElement("d").asNumVar();
cout << "Objective = " << getObjValue() << endl;<br /> cout<< "d = "<<getValue(DVar)<<endl;<br /> }
}
int main()
{
IloEnv env;
try {
...........
Rest OF the Program code
............
cplex.use(MyCallback(env));
cplex.solve();
// To ouput final result
env.out() << "Solution status = " << cplex.getStatus() << endl;<br />env.out() << "Solution value = " << cplex.getObjValue() << endl;<br />
}
return 0;
}
Also, be careful with the way you use values returned by CPLEX, as they are rarely integer - CPLEX considers values within a tolerance, so 20 can be either 19.999999999999998 or 20.000000000000002. However, C++ has no tolerance at all, so it is a good practice to either round the values (when storing them) or accept them within a certain interval (in if-then-else statements).
Antonio
#CPLEXOptimizers#DecisionOptimization