From: Guillaume R. <Gui...@em...> - 2006-11-17 23:29:33
|
Hi, This strange behavior is due to the fact that you use SolveAll() before=20 Solve(). SolveAll() and Solve()+nextSolution()'s loop are equivalents=20 (in other words you search for all the solutions twice), so usually we=20 don't do that :) What do you want to do ? -Guillaume Varun Jain a =E9crit : > Hi, > > Thank you very much for your quick reply. I guess the real question I=20 > wanted to ask was that if choco could return results even when the=20 > problem is infeasible. I did my experiment with the following problem: > > ------------------------------------------------ > Variables: > Variable0, Domain: {3, 1, 4} > Variable1, Domain: {2, 4, 6} > Variable2, Domain: {2, 1} > Variable3, Domain: {3, 1} > Variable4, Domain: {6, 2, 5} > > Constraints: > Constraint0, on variables 2 , Allowed values: > 2 > Constraint1, on variables 2, 4 , Allowed values: > 1, 6 > 2, 2 > Constraint2, on variables 4, 2 , Allowed values: > 5, 2 > Constraint3, on variables 1, 3 , Allowed values: > 2, 3 > ------------------------------------------------------ > > All the constraints were created using Problem.makeTupleFC(IntVar[]=20 > varList, ArrayList tuples, boolean feasible). For example, the first=20 > constraint can be created as follows: > > ------------------------------------------ > Problem chocoCSP; > /** > * Set up the variables using chocoCSP.makeEnumIntVar() > */ > IntVar[] varList =3D new IntVar[1]; > varList[0] =3D variables[2]; > ArrayList<int[]> tuples =3D new ArrayList<int[]>(); > tuples.add(new int[]{2}); > chocoCSP.makeTupleFC(varList, tuples, true); > ------------------------------------------------- > > To obtain solutions, I did the following: > > ----------------------------------------------- > System.out.println("SolveAll says: " + chocoCSP.solveAll()); > System.out.println("isFeasible says: " + chocoCSP.isFeasible()); > System.out.println("Choco Solutions"); > if(chocoCSP.solve() =3D=3D Boolean.TRUE) { > do { > for(int i =3D 0; i < chocoCSP.getNbIntVars(); i ++) { > System.out.print(((IntDomainVar)=20 > chocoCSP.getIntVar(i)).getVal() + ", "); > } > System.out.println(); > } while(chocoCSP.nextSolution() =3D=3D Boolean.TRUE); > } > ----------------------------------------------- > > Here is the output: > > SolveAll says: true > isFeasible says: false > Choco Solutions > 1,2,2,3,5, > 3,2,2,3,5, > 4,2,2,3,5, > > > Clearly, the solutions do not satisfy all the constraints. For=20 > instance, none of the solutions satisfy Constraint1. Is this expected=20 > behaviour?? > > Thanks again, > -Varun. > > > > > -----------------------------------------------------------------------= - > > Date: Fri, 17 Nov 2006 11:31:40 +0100 > > From: Gui...@em... > > To: jai...@ho... > > Subject: Re: [Choco-users] solveAll() bug? > > > > Hi, > > > > I am not sure to understand what you try to do but i have some=20 > answers :) > > -SolveAll still return true (it is hardcoded) but you can modify the > > function solveAll() in choco.Problem > > > > In choco.Problem: > > public Boolean solveAll() { > > solver.firstSolution =3D false; > > solver.generateSearchSolver(this); > > solver.launch(); > > return Boolean.TRUE; > > } > > > > -What kind of error do you have ? How do you implement the > > nextSolution() loop ? > > BTW, if you use nextSolution() to display solutions, you can use=20 > instead: > > > > "Solver.setVerbosity(Solver.SOLUTION);" before to begin to solve > > and "Solver.flushLogs();" to print solutions > > > > else: > > > > if (pb.solve() =3D=3D Boolean.TRUE) { > > > > do { > > //Code > > } > > } while(pb.nextSolution() =3D=3D Boolean.TRUE); > > } > > > > > > I hope it helps you... :) > > -Guillaume > > > > Varun Jain a =E9crit : > > > Hi.. > > > Is there any reason why the solveAll() method will return true=20 > even if > > > there is no solution that satisfies all constraints. I was getting > > > this behaviour so I did a little experiment: I set up a simple=20 > problem > > > and executed the following: > > > > > > Problem chocoCSP; > > > //............... > > > //-----Set up the problem > > > //............... > > > System.out.println("SolveAll says: " + chocoCSP.solveAll()); > > > System.out.println("isFeasible says: " + chocoCSP.isFeasible()); > > > > > > The following was the output > > > > > > SolveAll says: true > > > isFeasible says: false > > > > > > I thought solveAll() returns false if no solution exists. Also, for > > > this problem, the solutions I get from the nextSolution() method do > > > not satisfy all constraints. Any explainations would be really=20 > helpful? > > > > > > Thanks, > > > -Varun. > > > -----------------------------------------------------------------------= - > Be one of the first to try Windows Live Mail.=20 > <http://ideas.live.com/programpage.aspx?versionId=3D5d21c51a-b161-4314-= 9b0e-4911fb2b2e6d>=20 > > -----------------------------------------------------------------------= - > > -----------------------------------------------------------------------= -- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share= your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3D= DEVDEV > -----------------------------------------------------------------------= - > > _______________________________________________ > Choco-users mailing list > Cho...@li... > https://lists.sourceforge.net/lists/listinfo/choco-users > =20 |