From: <gro...@em...> - 2005-03-16 16:56:15
|
Dear Patrick, In order to limit the memory used for storing solutions, the number of stored solutions is limited to 5 (right now it is hard-coded, but accesors could be added to change this behaviour). If you want to have all solutions, the simplest way is to use incremental solving (nextSolution()). Indeed, you can for instance use the following code : if (pb.solve()) { do { // ... display the solution } while (pb.nextSolution()); } Hope it helps, Guillaume Selon Patrick Prosser <pa...@dc...>: > How do I get hold of all of the solutions? > > The code below only returns 5 of the 60 possible solutions. > > import choco.ContradictionException; > import choco.Problem; > import choco.integer.IntVar; > import choco.integer.search.*; > import choco.search.AssignVar; > import choco.Solver; > import choco.Solution; > > > public class Sample2 { > > public static void main(String[] args) { > int n = 3; > Problem pb = new Problem(); > IntVar x = pb.makeEnumIntVar("X",1,5); > IntVar y = pb.makeEnumIntVar("Y",1,5); > IntVar z = pb.makeEnumIntVar("Z",1,5); > Constraint c1 = pb.neq(x,y); > Constraint c2 = pb.neq(y,z); > Constraint c3 = pb.neq(z,x); > pb.post(c1);pb.post(c2);pb.post(c3); > > Solver s = pb.getSolver(); > s.setVarSelector(new DomOverDeg(pb)); > s.setValIterator(new DecreasingDomain()); > pb.solve(true); > > System.out.println("feasible: " + pb.isFeasible()); > System.out.println("nbSol: " + s.getNbSolutions()); > > for(int sol = 0; sol < s.getSearchSolver().solutions.size(); sol ++) > { > Solution solution = (Solution) > s.getSearchSolver().solutions.get(sol); > for(int i = 0; i < n; i++) System.out.print(solution.getValue(i) + > " "); > System.out.println("*****"); > } > } > } > > > > -- > Patrick Prosser tel: +44 141 330 4934 > Computing Science fax: +44 141 330 4913 > Glasgow University mail: pa...@dc... > G12 8RZ > http://www.dcs.gla.ac.uk/~pat > > > ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program. |