FRAMES NO FRAMES

Macro IlcChooseIndex2

Definition file: ilsolver/critmac.h
IlcChooseIndex2

This macro defines a new choice function (a criterion) in Solver for setting parameters on the search for a solution; you use this macro if you have two integer criteria.

This macro defines a choice function for constrained variables of type varType. The name of the function will be name. The second and third arguments, criterion1 and criterion2, should be C++ expressions of type IlcInt. In these expressions, the constrained variable to evaluate must be denoted byvar. The index of the variable in the array is varIndex. The function named name returns the index of the constrained variable of type varType that minimizes the expressions criterion1 and criterion2. If more than one constrained variable minimizes the first criterion, then the second criterion will be used to distinguish between them. If all the constrained variables have already been bound, then this function returns -1.

Implementation

Here's how this macro might be implemented.

#define IlcChooseIndex2(name, criterion1, criterion2, type) 
 IlcInt name (IlcInt theIlcChooseIndexSize, 
           name2(type, I**) vars) { 
     IlcInt varIndex; 
     type var; 
     name2(type,I**) tmp=vars;
     IlcInt indexBest = -1; 
     IlcInt value1, min1 = IlcIntMax; 
     IlcInt value2, min2 = IlcIntMax; 
     for (varIndex=0; varIndex < theIlcChooseIndexSize; varIndex++, tmp++)
 {
      var = type(*tmp); 
      if (!var.isBound()) { 
          value1 = criterion1; 
          if (value1 < min1) { 
              min1 = value1; 
              indexBest = varIndex; 
              min2 = criterion2; 
          } 
          else { 
              if (value1 == min1) { 
                  value2 = criterion2; 
                  if (value2 < min2) { 
                      min2 = value2; 
                      indexBest = varIndex; 
                  } 
              } 
          } 
      } 
     } 
     return indexBest; 
 } 
 IlcInt name (const name2(type,Array) array){ 
     return name (array.getSize(), array.getImpl()->getArray()); 
 }

See Also: