5.3 Search

Floating point variables will require special search definition. Basically, a domain split search (bisection) is used together with consistency checking to find a solution.

JaCoP standard search for floating point variables still uses DepthFirstSearch but needs to use specific methods for selection of choice points as well as variable selection. org.jacop.floats.search.SplitSelectFloat is used to define how intervals of floating point variables will be split. Default behavior of this method is to split an interval in a middle and try the left part first. If variable leftFirst is set to false the right interval will be checked first. The variables will be selected based on the variable selection heuristic defined as a parameter for SplitSelectFloat class. There exist several methods to select variables specific for FloatVar. They are defined in org.jacop.floats.search. Other general methods that are not specific for a given domain can also be used here, for example org.jacop.search.MostConstrainedStatic.

An example search can be specified as follows.

DepthFirstSearch<FloatVar> search = new DepthFirstSearch<FloatVar>(); 
SplitSelectFloat<FloatVar> select = new SplitSelectFloat<FloatVar>( 
                               store, x, 
                               new LargestDomainFloat<FloatVar>()); 
search.setSolutionListener(new PrintOutListener<FloatVar>()); 
 
boolean result = search.labeling(store, select);

Minimization, using DepthFirstSearch class, is done as for other variables by calling labeling method with the third parameter defining cost variable. Both IntVar and FloatVar can be used to defined cost criteria for minimization.

JaCoP offers also another minimization method. This method uses cost variable to lead the minimization. The method splits the domain of cost variable into two parts and then checks, using standard DepthFirstSearch labeling method if there is a solution in this part. If there is a solution in this part it continues to split the current interval and checks the left interval again. If there is no solution in this part (depth-first-search return false) it will try the right interval. The search finishes when the cost variable is ground (the difference between max and min is lower or equal epsilon). An example code is presented below.

DepthFirstSearch<FloatVar> search = new DepthFirstSearch<FloatVar>(); 
SplitSelectFloat<FloatVar> select = new SplitSelectFloat<FloatVar>( 
                           store, x, 
                           new LargestDomainFloat<FloatVar>()); 
 
Optimize min = new Optimize(store, search, select, cost); 
boolean result = min.minimize();

It is also possible to define SplitSelectFloat with variable selection heuristic (the last parameter) equal null. In this case a default method will be used that is round-robin selection. The variables are selected in a round-robin fashion until their domains will not become ground.