From: Varun J. <jai...@ho...> - 2006-11-17 23:47:35
|
Hi,Thanks again for your reply. Actually I included SolveAll() later in an = attempt to try and understand whats wrong. Basically, I wanted to extract a= ll solutions if any exists. So I did the following: System.out.println("= Choco Solutions"); if(chocoCSP.solve() =3D=3D Boolean.TRUE) { do { = for(int i =3D 0; i < chocoCSP.getNbIntVars(); i ++) { Syste= m.out.print(((IntDomainVar)chocoCSP.getIntVar(i)).getVal() + ", "); = } System.out.println(); } while(chocoCSP.nextSolution() =3D=3D = Boolean.TRUE); }And the output was still the following:Choco Solutions1,= 2,2,3,5,3,2,2,3,5,4,2,2,3,5,I included the SolveAll() and isFeasible() meth= ods later since the above was not working. So even in the absence of SolveA= ll() I get the strange behaviour.-Varun.> Date: Sat, 18 Nov 2006 00:28:23 += 0100> From: Gui...@em...> To: cho...@li...= > Subject: Re: [Choco-users] solveAll() bug?> > Hi,> > This strange behavio= r is due to the fact that you use SolveAll() before > Solve(). SolveAll() = and Solve()+nextSolution()'s loop are equivalents > (in other words you s= earch for all the solutions twice), so usually we > don't do that :) What = do you want to do ?> > -Guillaume> > Varun Jain a =E9crit :> > Hi,> >> > Th= ank you very much for your quick reply. I guess the real question I > > wan= ted to ask was that if choco could return results even when the > > problem= is infeasible. I did my experiment with the following problem:> >> > -----= -------------------------------------------> > Variables:> > Variable0, Dom= ain: {3, 1, 4}> > Variable1, Domain: {2, 4, 6}> > Variable2, Domain: {2, 1}= > > Variable3, Domain: {3, 1}> > Variable4, Domain: {6, 2, 5}> >> > Constra= ints:> > Constraint0, on variables 2 , Allowed values:> > 2> > Constraint1,= on variables 2, 4 , Allowed values:> > 1, 6> > 2, 2> > Constraint2, on var= iables 4, 2 , Allowed values:> > 5, 2> > Constraint3, on variables 1, 3 , A= llowed values:> > 2, 3> > -------------------------------------------------= -----> >> > All the constraints were created using Problem.makeTupleFC(IntV= ar[] > > varList, ArrayList tuples, boolean feasible). For example, the fir= st > > constraint can be created as follows:> >> > ------------------------= ------------------> > Problem chocoCSP;> > /**> > * Set up the variables u= sing chocoCSP.makeEnumIntVar()> > */> > IntVar[] varList =3D new IntVar[1]= ;> > varList[0] =3D variables[2];> > ArrayList<int[]> tuples =3D new ArrayL= ist<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.isFe= asible());> > 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(((IntDoma= inVar) > > chocoCSP.getIntVar(i)).getVal() + ", ");> > }> > = System.out.println();> > } while(chocoCSP.nextSolution() =3D=3D Bool= ean.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,> >> >> > Clearl= y, the solutions do not satisfy all the constraints. For > > instance, none= of the solutions satisfy Constraint1. Is this expected > > behaviour??> >>= > Thanks again,> > -Varun.> >> >> >> >> > --------------------------------= ----------------------------------------> > > Date: Fri, 17 Nov 2006 11:31:= 40 +0100> > > From: Gui...@em...> > > To: jai...@ho...= m> > > Subject: Re: [Choco-users] solveAll() bug?> > >> > > Hi,> > >> > > I= am not sure to understand what you try to do but i have some > > 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;> > > solv= er.generateSearchSolver(this);> > > solver.launch();> > > return Boolean.TR= UE;> > > }> > >> > > -What kind of error do you have ? How do you implement= the> > > nextSolution() loop ?> > > BTW, if you use nextSolution() to disp= lay solutions, you can use > > instead:> > >> > > "Solver.setVerbosity(Solv= er.SOLUTION);" before to begin to solve> > > and "Solver.flushLogs();" to p= rint solutions> > >> > > else:> > >> > > if (pb.solve() =3D=3D Boolean.TRUE= ) {> > >> > > do {> > > //Code> > > }> > > } while(pb.nextSolution() =3D=3D= Boolean.TRUE);> > > }> > >> > >> > > I hope it helps you... :)> > > -Guill= aume> > >> > > Varun Jain a =E9crit :> > > > Hi..> > > > Is there any reaso= n why the solveAll() method will return true > > even if> > > > there is no= solution that satisfies all constraints. I was getting> > > > this behavio= ur so I did a little experiment: I set up a simple > > problem> > > > and e= xecuted the following:> > > >> > > > Problem chocoCSP;> > > > //...........= ....> > > > //-----Set up the problem> > > > //...............> > > > Syste= m.out.println("SolveAll says: " + chocoCSP.solveAll());> > > > System.out.p= rintln("isFeasible says: " + chocoCSP.isFeasible());> > > >> > > > The foll= owing was the output> > > >> > > > SolveAll says: true> > > > isFeasible sa= ys: false> > > >> > > > I thought solveAll() returns false if no solution e= xists. Also, for> > > > this problem, the solutions I get from the nextSolu= tion() method do> > > > not satisfy all constraints. Any explainations woul= d be really > > helpful?> > > >> > > > Thanks,> > > > -Varun.> > >> > -----= -------------------------------------------------------------------> > Be o= ne of the first to try Windows Live Mail. > > <http://ideas.live.com/progra= mpage.aspx?versionId=3D5d21c51a-b161-4314-9b0e-4911fb2b2e6d> > >> > -------= -----------------------------------------------------------------> >> > ---= ----------------------------------------------------------------------> > T= ake 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.techsa= y.com/default.php?page=3Djoin.php&p=3Dsourceforge&CID=3DDEVDEV> > ---------= ---------------------------------------------------------------> >> > _____= __________________________________________> > Choco-users mailing list> > C= hoc...@li...> > https://lists.sourceforge.net/lists/lis= tinfo/choco-users> > > > > ----------------------------------------------= ---------------------------> Take Surveys. Earn Cash. Influence the Future = of IT> Join SourceForge.net's Techsay panel and you'll get the chance to sh= are your> opinions on IT & business topics through brief surveys - and earn= cash> http://www.techsay.com/default.php?page=3Djoin.php&p=3Dsourceforge&C= ID=3DDEVDEV> _______________________________________________> Choco-users m= ailing list> Cho...@li...> https://lists.sourceforge.n= et/lists/listinfo/choco-users _________________________________________________________________ Be one of the first to try Windows Live Mail. http://ideas.live.com/programpage.aspx?versionId=3D5d21c51a-b161-4314-9b0e-= 4911fb2b2e6d= |