IBM ILOG Solver User's Manual > Extending the Library > Writing a Constraint: Allocating Frequencies > Writing a constraint: Frequency allocation > Defining the Instantiate goal

Now you can define the goal Instantiate this way:

IlcInt bestFreq(IlcIntVar var) {
  IlcInt max = -1;
  IlcInt maxIndex = 0;
  IlcInt i;
  for(IlcIntExpIterator iter(var);iter.ok();++iter){
    i=*iter;
    if (*freqUsage[i] > max){
      max = *freqUsage[i];
      maxIndex = i;
    }
  }
  return maxIndex;
}

ILCGOAL1(Instantiate, IlcIntVar, var) {
  if (var.isBound()) return 0;
  IlcInt val = bestFreq(var);
  return IlcOr(var == val,
               IlcAnd(var != val,
                      this));
}

For more information on writing your own goal and using a goal wrapper, see Chapter 18, Writing a Goal: Car Sequencing.