From: Hadrien C. <had...@em...> - 2004-11-15 16:39:18
|
Hi, The limits are updated and checked each time a new node is created. So the difference between the maximum and the time printed is due to the fact that time is needed to go up in the search tree. The current version is not completely implemented but in the next version (already in the cvs but not yet published), '35[+10] nodes' will mean that a total of 35 nodes were needed to reach the previous solution and 10 more nodes were explored to get the next one. To define your own limits/statitistics, don't use a varselector :) (bad idea) but instead create a limit object. Documentation will be available asap but for the moment, you can have look to the following code which give you an example of your depth statistic and how to use it (in the main on the nqueen problem). hope it helps Hadrien and Guillaume import choco.search.AbstractGlobalSearchLimit; import choco.search.AbstractGlobalSearchSolver; import choco.Problem; import choco.Solver; import choco.integer.IntVar; import java.util.logging.Logger; public class DepthLimit extends AbstractGlobalSearchLimit { public DepthLimit(AbstractGlobalSearchSolver theSolver,int theLimit) { super(theSolver,theLimit); unit = "deep"; } public boolean newNode(AbstractGlobalSearchSolver solver) { nb = Math.max(nb, this.getProblem().getWorldIndex() - this.getProblem().getSolver().getSearchSolver().baseWorld); return (nb < nbMax); } public boolean endNode(AbstractGlobalSearchSolver solver) { return true; } public void reset(boolean first) { if (first) { nbTot = 0; } else { nbTot = Math.max(nbTot, nb); } nb = 0; } public static void main(String[] args) { Problem pb = new Problem(); int n = 10; IntVar[] queens = new IntVar[n]; for (int i = 0; i<n; i++) { queens[i] = pb.makeEnumIntVar("Q" + i,1,n); } for (int i=0; i<n; i++) { for (int j=i+1; j<n; j++) { int k = j - i; pb.post(pb.neq(queens[i], queens[j])); pb.post(pb.neq(queens[i], pb.plus(queens[j], k))); // diagonal constraints pb.post(pb.neq(queens[i], pb.minus(queens[j], k))); // diagonal constraints } } Solver s = pb.getSolver(); s.setFirstSolution(false); s.generateSearchSolver(pb); s.getSearchSolver().limits.add(new DepthLimit(s.getSearchSolver(),Integer.MAX_VALUE)); s.launch(); Logger.getLogger("choco").getHandlers()[0].flush(); } } |