5.4 Example

The following code defines equation x2 + sin(1∕x3) = 0 together with the search that finds all 318 solutions.

FloatDomain.setPrecision(1.0e-14); 
FloatDomain.intervalPrint(false); 
Store store = new Store(); 
 
FloatVar x = new FloatVar(store, "x", 0.1, 1.0); 
FloatVar zero = new FloatVar(store, 0,0); 
FloatVar one = new FloatVar(store, 1,1); 
 
// x*x + sin(1.0/(x*x*x)) = 0.0; 
FloatVar[] temp = new FloatVar[4]; 
for (int i=0; i<temp.length; i++) 
    temp[i] = new FloatVar(store, "temp["+i+"]", -1e150, 1e150); 
store.impose(new PmulQeqR(x, x, temp[0])); 
store.impose(new PmulQeqR(x, temp[0], temp[1])); 
store.impose(new PdivQeqR(one, temp[1], temp[2])); 
store.impose(new SinPeqR(temp[2], temp[3])); 
store.impose(new PplusQeqR(temp[0], temp[3], zero)); 
 
DepthFirstSearch<FloatVar> search = new DepthFirstSearch<FloatVar>(); 
SplitSelectFloat<FloatVar> s = new SplitSelectFloat<FloatVar>(store, 
                                   new FloatVar[] {x}, null); 
search.setSolutionListener(new PrintOutListener<FloatVar>()); 
search.getSolutionListener().searchAll(true); 
 
search.labeling(store, s);

The last solution is x = 0.65351684593772.