From: Hadrien C. <had...@em...> - 2004-10-27 06:41:18
|
Hello, That's true, the "solver.setFirstSolution(true)" should be a "solver.setFirstSolution(false);". we need to quickly define the api to avoid such mistakes. public static void main(String[] args) { Problem pb =3D new Problem(); IntVar fctObj =3D pb.makeBoundIntVar("objectif",-10,1000); IntVar v1 =3D pb.makeEnumIntVar("v1",1,10); IntVar v2 =3D pb.makeEnumIntVar("v2",-3,10); IntVar v3 =3D pb.makeEnumIntVar("v3",1,10); pb.post(pb.eq(pb.sum(new IntVar[]{v1,v2,v3}),fctObj)); Solver solver =3D pb.getSolver(); solver.setDoMaximize(false); solver.setObjective(fctObj); solver.setRestart(false); solver.setFirstSolution(false); solver.setValIterator(new DecreasingDomain()); solver.generateSearchSolver(pb); solver.launch(); } You will finally obtain : ... solution with cost objectif:-1 0[+15] millis. 0[+3] nodes Pb[4 vars, 1 cons] objectif[-1, -1] v1{1} v2{-3} v3{1} Hadrien ----- Original Message -----=20 From: "coletta" <co...@li...> To: <cho...@li...> Sent: Tuesday, October 26, 2004 6:03 PM Subject: Re: [Choco-users] maximize/minimize > Le lun, 25/10/2004 =E0 14:08 +0200, Hadrien Cambazard a =E9crit : > > > The api concerning minization and maximization in not yet available o= n the > > Problem object. However, you can look at the following code which giv= e you > > an example of minimization. You only need to use the Solver object an= d > > specify a couple of options : > > > > public static void main(String[] args) { > > Problem pb =3D new Problem(); > > IntVar fctObj =3D pb.makeBoundIntVar("objectif",-10,1000); > > IntVar v1 =3D pb.makeEnumIntVar("v1",1,10); > > IntVar v2 =3D pb.makeEnumIntVar("v2",-3,10); > > IntVar v3 =3D pb.makeEnumIntVar("v3",1,10); > > > > pb.post(pb.eq(pb.sum(new IntVar[]{v1,v2,v3}),fctObj)); > > > > > > Solver solver =3D pb.getSolver(); > > solver.setDoMaximize(false); > > solver.setObjective(fctObj); > > solver.setRestart(false); > > solver.setFirstSolution(true); > > solver.generateSearchSolver(pb); > > solver.launch(); > > } > > Hello guys, > > I'm sorry, but i don't seem to work :-( > By selecting another Value Ordering, for instance: > inserting the line "solver.setValIterator(new DecreasingDomain());", > i obtain: > > $ java Test > ... solution with cost objectif:30 > Pb[4 vars, 1 cons] > objectif[30, 30] > v1{10} > v2{10} > v3{10} > > Do i miss something ? > > -- > R=E9mi > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJourna= l > Use IT products in your business? Tell us what you think of them. Give = us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Choco-users mailing list > Cho...@li... > https://lists.sourceforge.net/lists/listinfo/choco-users > |