12.07.2015 Views

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

ILOG CPLEX 11.0 User's Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Formulating Logical ConstraintsYou have already seen how to represent the logical constraints of this problem in What Arethe Constraints? on page 362. However, they deserve a second glance because they illustratean important point about logical constraints and automatic transformation in <strong>ILOG</strong> <strong>CPLEX</strong>.// Logical constraints// The food cannot use more than 3 oils// (or at least two oils must not be used)model.add((use[i][v1] == 0) + (use[i][v2] == 0) + (use[i][o1] == 0) +(use[i][o2] == 0) + (use[i][o3] == 0) >= 2);// When an oil is used, the quantity must be at least 20 tonsfor (p = 0; p < nbProducts; p++)model.add((use[i][p] == 0) || (use[i][p] >= 20));// If products v1 or v2 are used, then product o3 is also usedmodel.add(IloIfThen(env, (use[i][v1] >= 20) || (use[i][v2] >= 20),use[i][o3] >= 20));Consider, for example, the constraint that the blended product cannot use more than threeoils in a batch. Given that constraint, many programmers might naturally write the followingstatement (or something similar) in C++:model.add ( (use[i][v1] != 0)+ (use[i][v2] != 0)+ (use[i][o1] != 0)+ (use[i][o2] != 0)+ (use[i][o3] != 0)=, || thatappear in these logical constraints.Solving the ProblemThe following statement solves the problem to optimality:if (cplex.solve()) {<strong>ILOG</strong> <strong>CPLEX</strong> <strong>11.0</strong> — USER’ S MANUAL 365

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!