From: Varun J. <jai...@ho...> - 2006-11-18 00:34:44
|
Hi again,I thought I should give you my test code so that you can run it yo= urself. I have included the code at the bottom. Note that the CSP problem I= was experimenting with has changed a bit (however, the strange behaviour s= till remains) Heres the new CSP problem:Variables:Variable0, Domain: {4, 2}= Variable1, Domain: {5, 1, 4}Variable2, Domain: {3, 4, 6}Variable3, Domain: = {1, 2}Variable4, Domain: {7, 8, 6, 1}Constraints:Constraint0, on variables = 3 , Allowed tuples:1Constraint1, on variables 2, 4 , Allowed tuples:6, 7Con= straint2, on variables 2 , Allowed tuples:34Constraint3, on variables 4, 1 = , Allowed tuples:7, 18, 16, 51, 5Heres the output of running the program gi= ven below:Choco Solutions2, 1, 3, 1, 8, 4, 1, 3, 1, 8, As you can see, none= of the solutions satisfy constraint1. Still choco returns these solutions.= Heres my code (BTW, Thanks for taking time out to help me.. I really apprec= iate it :-)):import choco.Problem;import choco.Constraint;import choco.inte= ger.IntDomainVar;import choco.integer.IntVar;import java.util.ArrayList;/**= * @author Varun Jain (vj) * @version $Revision$, $Date$ * @created Nov 17,= 2006 */public class ChocoTest { public static void main(String args[]) { = Problem chocoCSP =3D new Problem(); IntDomainVar[] vars =3D new IntDo= mainVar[5]; Constraint[] cons =3D new Constraint[4]; //-----Construct= all variables int id =3D 0; vars[id] =3D chocoCSP.makeEnumIntVar("v"= + id++, new int[]{4, 2}); vars[id] =3D chocoCSP.makeEnumIntVar("v" + id= ++, new int[]{5, 1, 4}); vars[id] =3D chocoCSP.makeEnumIntVar("v" + id++= , new int[]{3, 4, 6}); vars[id] =3D chocoCSP.makeEnumIntVar("v" + id++, = new int[]{1, 2}); vars[id] =3D chocoCSP.makeEnumIntVar("v" + id++, new i= nt[]{7, 8, 6, 1}); id =3D 0; ArrayList<int[]> tuples; //-----Now c= onstruct all constraints //-----Constraint0 tuples =3D new ArrayList<= int[]>(); tuples.add(new int[]{1}); cons[id] =3D chocoCSP.makeTupleFC= (new IntVar[]{vars[3]}, tuples, true); chocoCSP.post(cons[id++]); //-= ----Constraint1=0A= tuples =3D new ArrayList<int[]>(); tuples.add(new int[]{6, 7}); c= ons[id] =3D chocoCSP.makeTupleFC(new IntVar[]{vars[2], vars[4]}, tuples, tr= ue); chocoCSP.post(cons[id++]); //-----Constraint2=0A= tuples =3D new ArrayList<int[]>(); tuples.add(new int[]{3}); tupl= es.add(new int[]{4}); cons[id] =3D chocoCSP.makeTupleFC(new IntVar[]{var= s[2]}, tuples, true); chocoCSP.post(cons[id++]); //-----Constraint3= =0A= tuples =3D new ArrayList<int[]>(); tuples.add(new int[]{7, 1}); t= uples.add(new int[]{8, 1}); tuples.add(new int[]{6, 5}); tuples.add(n= ew int[]{1, 5}); cons[id] =3D chocoCSP.makeTupleFC(new IntVar[]{vars[4],= vars[1]}, tuples, true); chocoCSP.post(cons[id++]); //-----Now get s= olutions System.out.println("Choco Solutions"); if(chocoCSP.solve() = =3D=3D Boolean.TRUE) { do { for(int i =3D 0; i < chocoCSP.getNb= IntVars(); i ++) { System.out.print(((IntDomainVar)chocoCSP.getInt= Var(i)).getVal() + ", "); } System.out.println(); } whil= e(chocoCSP.nextSolution() =3D=3D Boolean.TRUE); } }}> Date: Sat, 18 Nov= 2006 00:28:23 +0100> From: Gui...@em...> To: choco-users@lists= .sourceforge.net> Subject: Re: [Choco-users] solveAll() bug?> > Hi,> > This= strange behavior is due to the fact that you use SolveAll() before > Solve= (). SolveAll() and Solve()+nextSolution()'s loop are equivalents > (in o= ther words you search for all the solutions twice), so usually we > 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 qu= estion I > > wanted to ask was that if choco could return results even when= the > > problem is infeasible. I did my experiment with the following prob= lem:> >> > ------------------------------------------------> > 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> > Con= straint2, on variables 4, 2 , Allowed values:> > 5, 2> > Constraint3, on va= riables 1, 3 , Allowed values:> > 2, 3> > ---------------------------------= ---------------------> >> > All the constraints were created using Problem.= makeTupleFC(IntVar[] > > varList, ArrayList tuples, boolean feasible). For = example, the first > > 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[]> tupl= es =3D new ArrayList<int[]>();> > tuples.add(new int[]{2});> > chocoCSP.mak= eTupleFC(varList, tuples, true);> > ---------------------------------------= ----------> >> > To obtain solutions, I did the following:> >> > ----------= -------------------------------------> > System.out.println("SolveAll s= ays: " + chocoCSP.solveAll());> > System.out.println("isFeasible says: = " + chocoCSP.isFeasible());> > System.out.println("Choco Solutions");> = > if(chocoCSP.solve() =3D=3D Boolean.TRUE) {> > do {> > f= or(int i =3D 0; i < chocoCSP.getNbIntVars(); i ++) {> > System.ou= t.print(((IntDomainVar) > > chocoCSP.getIntVar(i)).getVal() + ", ");> > = }> > System.out.println();> > } while(chocoCSP.nextSolut= ion() =3D=3D Boolean.TRUE);> > }> > -----------------------------------= ------------> >> > Here is the output:> >> > SolveAll says: true> > isFeasi= ble 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 >= > instance, none of the solutions satisfy Constraint1. Is this expected > = > behaviour??> >> > Thanks again,> > -Varun.> >> >> >> >> > ---------------= ---------------------------------------------------------> > > Date: Fri, 1= 7 Nov 2006 11:31:40 +0100> > > From: Gui...@em...> > > To: jain= _v...@ho...> > > Subject: Re: [Choco-users] solveAll() bug?> > >> > = > Hi,> > >> > > I am not sure to understand what you try to do but i have s= ome > > answers :)> > > -SolveAll still return true (it is hardcoded) but y= ou can modify the> > > function solveAll() in choco.Problem> > >> > > In ch= oco.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 nextS= olution() to display solutions, you can use > > instead:> > >> > > "Solver.= setVerbosity(Solver.SOLUTION);" before to begin to solve> > > and "Solver.f= lushLogs();" to print solutions> > >> > > else:> > >> > > if (pb.solve() = =3D=3D Boolean.TRUE) {> > >> > > do {> > > //Code> > > }> > > } while(pb.ne= xtSolution() =3D=3D Boolean.TRUE);> > > }> > >> > >> > > I hope it helps yo= u... :)> > > -Guillaume> > >> > > Varun Jain a =E9crit :> > > > Hi..> > > >= Is there any reason why the solveAll() method will return true > > 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 > > p= roblem> > > > 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 fal= se if no solution exists. Also, for> > > > this problem, the solutions I ge= t from the nextSolution() method do> > > > not satisfy all constraints. Any= explainations would be really > > helpful?> > > >> > > > Thanks,> > > > -V= arun.> > >> > -------------------------------------------------------------= -----------> > Be one of the first to try Windows Live Mail. > > <http://id= eas.live.com/programpage.aspx?versionId=3D5d21c51a-b161-4314-9b0e-4911fb2b2= e6d> > >> > ---------------------------------------------------------------= ---------> >> > -----------------------------------------------------------= --------------> > Take Surveys. Earn Cash. Influence the Future of IT> > Jo= in 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-user= s mailing list> > Cho...@li...> > https://lists.source= forge.net/lists/listinfo/choco-users> > > > > ---------------------------= ----------------------------------------------> Take Surveys. Earn Cash. In= fluence the Future of IT> Join SourceForge.net's Techsay panel and you'll g= et the chance to share your> opinions on IT & business topics through brief= surveys - and earn cash> http://www.techsay.com/default.php?page=3Djoin.ph= p&p=3Dsourceforge&CID=3DDEVDEV> ___________________________________________= ____> Choco-users mailing list> Cho...@li...> https://= lists.sourceforge.net/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= |