double[] coefficients = new double[nWarehouses + nCustomers];
sub.dualFarkas(constraints, coefficients);
double temp = 0; // sum of cut terms not involving primal variables
// process all elements of the Farkas certificate
for (int i = 0; i < constraints.length; i++) {
IloConstraint c = constraints[i];
expr = master.sum(expr, master.prod(coefficients[i], rhs.get(c)));
}
// add a feasibility cut
IloConstraint r = add(master.le(master.sum(temp, expr), 0));
System.out.println("\n>>> Adding feasibility cut: " + r + "\n");
} 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])));
}
// add the optimality cut
IloConstraint r = add((IloRange) master.ge(flowCost, expr));
System.out.println("\n>>> Adding optimality cut: " + r + "\n");
} else {
System.out.println("\n>>> Accepting new incumbent with value "
+ getObjValue() + "\n");
// the master and subproblem flow costs match