Originally posted by: SystemAdmin
>
> Could you please tell me how to compare the values of two elements of IloVarNumArray T[i] and T[j]? and two elements values of IloExprArray TT[i] and TT[j]?
This is a somewhat complicated question. If you want to enforce a weak inequality (say
T[i] >= T[j]
for example), you just add that to the model as a constraint. If you want to
test whether an inequality is satisfied (and make something else in the model contingent on it), you introduce a binary variable, and you usually also need one or possibly two constants that represent valid upper and/or lower bounds on the difference. For instance, letting z be the new binary variable, a constraint like
T[i] <= T[j] + M*z
with M a sufficiently large constant says that
either T[i] <= T[j] or z = 1 (or both).
Forcing
z = 0 if and only if T[i] <= T[j]
is trickier, and in fact is usually impossible unless T is integer-valued. For continuous T, the best you can do is introduce some small positive constant epsilon and another large positive constant L, and use two constraints:
T[i] <= T[j] + M*z
T[i] >= T[j] + epsilon*z - L*(1 - z).
With this,
z = 1 implies "infinity" > T[i] >= T[j] + epsilon > T[j]
and
z = 0 implies "-infinity" < T[i] <= T[j]
(where L and M are surrogates for infinity). Note that this precludes
T[j] < T[i] < T[j] + epsilon.
If you drop the epsilon term, you almost get the if and only if, the catch being that z = 0 and z = 1 both allow
T[i] = T[j].
/Paul
Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
#CPLEXOptimizers#DecisionOptimization