Originally posted by: Selectedbetter
if our problem is:
initial master
min c x + eta
A x >= b
x >= 0, integer
Dual subproblem
max u (q - T x*)+v (q - T x*)
u Q <= d
v Q <= d
u >= 0
v >= 0
Then, in our code, we write:
IloInt separate(.......)
{
........
cplex.solve();
if ( cplex.getStatus() == IloAlgorithm::Unbounded )
{
IloNumVarArray var(env);
IloNumArray val(env);
cplex.getRay(val,var);
for (w = 0; w < val.getSize(); ++w)
{
IloInt *index_p = (IloInt*) var[w].getObject();
IloInt index = *index_p;
if (index<uNumVars)
{
cutLhs+=val[w]*(q - T x);
}
else if(index>=uNumVars && index<(uNumVars+vNumVars))
{
cutLhs+=val[w]*(q - T x);
}
var.end();
val.end();
violatedCutFound = 1;
}
else if(cplex.getStatus() == IloAlgorithm::Optimal)
{
IloNumArray U(env,uNumVars);
IloNumArray V(env,vNumVars);
cplex.getValues(U,u);
cplex.getValues(V,v);
cutLhs+=U*(q - T x);
cutLhs+=V*(q - T x);
violatedCutFound = 2;
}
return violatedCutFound ;
}
And by the value of violatedCutFound:
ILOLAZYCONSTRAINTCALLBACK(......)
{
IloInt sepStat = separate(......);
if (sepStat = 1)
{
add(cutLhs <=0).end();
}
else if(sepStat = 2)
{
add(cutLhs <= eta).end();
}
}
#CPLEXOptimizers#DecisionOptimization