Customizing the search

By writing an execute block.

Before writing constraints, you can customize the CP Optimizer search strategy by writing an execute block. In this time tabling problem, this is done by selecting variables by increasing the domain size, and by selecting random values. The method consisting in selecting random values helps the search process to distribute the courses homogeneously over the scheduling period.

   var f = cp.factory;
   var selectVar = f.selectSmallest(f.domainSize());
   var selectValue = f.selectRandomValue();
   var assignRoom = f.searchPhase(room, selectVar, selectValue);
   var assignTeacher = f.searchPhase(teacher, selectVar, selectValue);
   var assignStart = f.searchPhase(Start, selectVar, selectValue);
   cp.setSearchPhases(assignTeacher, assignStart, assignRoom);

Note that the phases are assigned in a specific order:

  1. Teachers, because there are only a few to choose from.

  2. Start times, because once teachers are determined, there is only a limited number of possible start times for courses.

  3. Rooms.

To specify search method and time limits, you can either use a scripting block, like this:

   var p = cp.param;
   p.logPeriod = 10000;
   p.searchType = "DepthFirst";
   p.timeLimit = 600;

or edit the Constraint Programming/Search Control page in the project settings file (timetabling.ops) from the IBM ILOG CPLEX Optimization Studio IDE. See Setting programming options in IDE Reference.