6.5 Combining search

JaCoP offers, through its plug-ins, possibility to combine several search methods into a single complex search. For example, the following code presents a search that is build as consecutive invocation of two search methods.

   Search<IntVar> slave = new DepthFirstSearch<IntVar>(); 
   SelectChoicePoint<IntVar> selectSlave = 
          new SimpleSelect<IntVar>(vars2, 
                                   new SmallestMin<IntVar>(), 
                                   new SmallestDomain<IntVar>(), 
                                   new IndomainMin<IntVar>()); 
   slave.setSelectChoicePoint(selectSlave); 
 
   Search<IntVar> master = new DepthFirstSearch<IntVar>(); 
   SelectChoicePoint<IntVar> master = 
          new SimpleSelect<IntVar>(vars1, 
                                   new SmallestMin<IntVar>(), 
                                   new SmallestDomain<IntVar>(), 
                                   new IndomainMin<IntVar>()); 
   master.addChildSearch(slave); 
 
   boolean result = master.labeling(store, selectMaster);

When several search methods is combined to form a sequential search and the minimization is done one has to set for each sub-search a flag informing this search that it is a part of minimization. It is achieved by the following instruction.

   slave.setOptimize(true);