Enhancing the model

Shows how to declare a search phase or use the pack constraint.

You can enhance the carseq.mod model in two ways:

  • Declare a search phase

  • Use the pack constraint

Search phase

You can declare a search phase that

  • Branches on the slot variables in sequence

  • Allocates more complex cars first

The valueEval expression defines the cars that are hard to sequence (for the search phases). The larger the value, the harder it is to sequence a car. For each car type, the measure is a combination of how difficult the option requirements are to satisfy, and of the number of cars to build.


int values[i in 0..nbConfs] = i;
int valueEval[i in 0..nbConfs] = sum(o in Options) option[o,maxl(i,1)]*
             (capacity[o].u div capacity[o].l)*(i!=0)+
             (demand[maxl(i, 1)]*nbConfs*(i!=0)) div nbSlots + (i > 0);

The execute block defines the search phase.

The selectSmallest function decides the type of car in the order of the sequence.

The selectLargest function selects first the cars that are considered hard to sequence.


execute {
   var f = cp.factory;

   var phase1 = f.searchPhase(slot, 
              f.selectSmallest(f.varIndex(slot)), 
              f.selectLargest(f.explicitValueEval(values, valueEval, 0)));
                                                                                                     
   cp.setSearchPhases(phase1);
   
}

The pack constraint

For more efficiency, you can also enhance the car sequencing model by modeling the demandCt constraint as the specialized constraint pack, which expresses the same constraint but propagates better.

demandCt: pack(demandV, slot, one);