}
// generate a feasibility cut
IloRange r = master.le(master.sum(temp, expr), 0);
//test the cut against the current solution
IloLinearNumExpr rexpr = (IloLinearNumExpr) r.getExpr();
IloLinearNumExprIterator it = rexpr.linearIterator();
double lhs = 0;
double rhs = r.getUB();
while (it.hasNext()) {
IloNumVar v = it.nextNumVar();
lhs += it.getValue()*msol.get(v);
}
// if a violation occurs, add a feasibility cut
if (lhs > rhs + FUZZ) {
System.out.println("!!! Adding user feasibility cut: " + r);
add(r);
}
} else if (status == IloCplex.Status.Optimal) {
if (zMaster < sub.getObjValue() - FUZZ) {
// the master problem surrogate variable underestimates the actual
// flow cost -- add an optimality cut
double[] lambda = sub.getDuals(cDemand);
double[] mu = sub.getDuals(cSupply);
// compute the scalar product of the RHS of the demand constraints
// with the duals for those constraints
for (int j = 0; j < nCustomers; j++) {
expr = master.sum(expr, master.prod(lambda[j], rhs.get(cDemand[j])));
}
// repeat for the supply constraints
for (int i = 0; i < nWarehouses; i++) {
expr = master.sum(expr, master.prod(mu[i], rhs.get(cSupply[i])));
}
// generate an optimality cut
IloRange r = (IloRange) master.le(master.diff(expr, flowCost), 0);
//test the cut against the current solution
IloLinearNumExpr rexpr = (IloLinearNumExpr) r.getExpr();
IloLinearNumExprIterator it = rexpr.linearIterator();
double lhs = 0;
double rhs = r.getUB();
while (it.hasNext()) {
IloNumVar v = it.nextNumVar();
lhs += it.getValue()*msol.get(v);
}
// if a violation occurs, add an optimality cut
if (lhs - rhs > FUZZ) {
System.out.println("!!! Adding user optimality cut: " + r);
add(r);