Originally posted by: Hosssein
Hi,
I am testing IncumbentCallbackI on a very very simple MIP model in C++ that is solved in the root node by MIP presolve. It looks that the IncumbentCallbackI is not called when an incumbent is found. You can find my code in the following. Could you please help me? I expected to see that "hello" is printed in the output (see SolutionFilterCallbackI::main()), but it never happens. (Please check the P.S. after the code)
#include<ilcplex/ilocplex.h>
#include<iostream>
#include<queue>
#include<vector>
usingnamespace std;
#include<ctime>
#include<cmath>
classSolutionFilterCallbackI : public IloCplex::IncumbentCallbackI {
IloNumVarArray xVar;
public:
IloCplex::CallbackI* duplicateCallback() const {
return (new (getEnv()) SolutionFilterCallbackI(*this));
}
SolutionFilterCallbackI (IloEnv env, IloNumVarArray x) :
IloCplex::IncumbentCallbackI(env), xVar(x) {
}
void main();
};
IloCplex::Callback
SolutionFilterCallback(IloEnv env, IloNumVarArray xVar){
return (IloCplex::Callback(new(env) SolutionFilterCallbackI(env, xVar)));
}
voidSolutionFilterCallbackI::main() {
cout << "hello" << endl;
if (getValue(xVar[0])==5){
reject();
}
}
intmain(int argc, char **argv)
{
IloEnv env;
IloNumVarArray X(env,10);
for(int i=0; i< 10; i++) {
X[i] = IloNumVar(env, 0, 5, ILOINT);
}
IloModel model (env);
IloExpr MyObjectiveFunction(env);
for(int i=0; i< 10; i++) {
MyObjectiveFunction += X[i];
}
model.add(IloMaximize(env, MyObjectiveFunction));
IloCplex Mycplex(model);
Mycplex.use(SolutionFilterCallback(env, X));
Mycplex.solve();
cout << "Finished" << endl;
system("Pause");
return0;
}
P.S
I just tested the IncumbentCallbackI on a more complicated MIP model (that is not presented here) in which to get the optimal solution some branchings are required. I can see that "hello" is printed whenever a new incumbent is found, except when the first incumbent is found in the root node. It looks the reason that SolutionFilterCallbackI::main() was not called in the above code is that the optimal solution is found by MIP presolve in the root node. Is it right? Is there any way for filtering incumbents found in the root node?
#CPLEXOptimizers#DecisionOptimization