Logical constraints in the C++ API
Describes logical constraints in the C++ API.
In C++ applications, the class IloCplex
can extract modeling objects to solve a wide variety of MIPs, as you
see in Solving the model,
summarized in the table in Overview.
In fact, the C++ class IloCplex can extract
logical constraints as well as some logical expressions. The logical
constraints that IloCplex can extract
are these:
IloAndIloOrIloNotIloIfThenIloDiff
==that is, the equivalence relation
Among those extractable objects, IloAnd IloOr , IloNot ,
and IloDiff can also be represented in
your application by means of the overloaded C++ operators:
||(forIloOr)&&(forIloAnd)!(forIloNot)!=that is, the exclusive-or relation (forIloDiff)
All those extractable objects accept as their arguments other linear constraints or logical constraints, so you can combine linear constraints with logical constraints in complicated expressions in your application.
For example, to express the idea that two jobs with starting
times x1 and x2
and with duration d1 and d2
must not overlap, you can either use overloaded C++ operators, like
this:
model.add((x1 >= x2 + d2) || (x2 >= x1 + d1));
or you can express the same idea, like this:
IloOr or(env)
or.add(x1 >= x2 + d2);
or.add(x2 >= x1 + d1);
model.add(or);
Since IloCplex can also extract
logical constraints embedded in other logical constraints, you can
also write logical constraints like this:
IloIfThen(env, (x >= y && x >= z), IloNot(x <= 300 || y >= 700))
where x , y ,
and z are variables in your application.