FRAMES NO FRAMES

Macro ILOCOMPARATOR0

Definition file: ilsolver/iloselector.h
ILOCOMPARATOR0(comparatorName, tx, nx1, nx2)
ILOCOMPARATOR1(comparatorName, tx, nx1, nx2, td, nd)
ILOCOMPARATOR2(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2)
ILOCOMPARATOR3(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2, td3, nd3)
ILOCOMPARATOR4(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2, td3, nd3, td4, nd4)
ILOCOMPARATOR5(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5)
ILOCOMPARATOR6(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6)
ILOCOMPARATOR7(comparatorName, tx, nx1, nx2, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6, td7, nd7)
ILOCTXCOMPARATOR0(comparatorName, tx, nx1, nx2, tu, nu)
ILOCTXCOMPARATOR1(comparatorName, tx, nx1, nx2, tu, nu, td, nd)
ILOCTXCOMPARATOR2(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2)
ILOCTXCOMPARATOR3(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2, td3, nd3)
ILOCTXCOMPARATOR4(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4)
ILOCTXCOMPARATOR5(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5)
ILOCTXCOMPARATOR6(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6)
ILOCTXCOMPARATOR7(comparatorName, tx, nx1, nx2, tu, nu, td1, nd1, td2, nd2, td3, nd3, td4, nd4, td5, nd5, td6, nd6, td7, nd7)

The ILOCOMPARATORi macros can be used to generate comparators over arbitrary objects.

The macros take four mandatory parameters which are:

After this, depending on the macro used, optional parameters can be provided as argument pairs of type and name.

The body of the macro must return a Boolean value (IloBool) which is IloTrue if the comparator's left-hand side is better than its right-hand side.

Using ILOCOMPARATORi

For example, the following code defines a comparator that compares the value of two IlcFloatVar variables (provided the variables are bound):

 ILOCOMPARATOR0(CompareGreaterThan, IlcFloatVar, v1, v2) {
   return v1.getValue() > v2.getValue();
 }

This comparator can be invoked as follows:

 IloComparator<IlcFloatVar> cmp = CompareGreaterThan(getSolver());
 IloBool value = cmp(var1, var2);

Using ILOCTXCOMPARATORi

The macro ILOCTXCOMPARATORi can be used to handle a user-given context (name nu and type tu) at comparison time. The following comparator uses a contextual tolerance factor:

 ILOCTXCOMPARATOR0(CompareGreaterThanWithTolerance,IlcFloatVar, v1, v2, IlcFloat, tolerance) {
   return (v1.getValue() - v2.getValue() > tolerance);
 }

This comparator can be invoked as follows:

 IloComparator<IlcFloatVar> cmp = CompareGreaterThanWithTolerance(getSolver());
 IlcFloat tolerance = 0.8;
 IloBool value = cmp(var1, var2, (IloAny)&tolerance);

For more information, see Selectors.