From: Michael P. <mpr...@ex...> - 2008-02-20 18:37:36
|
I'm having a problem with RealVar and the Problem.implies() - it doesn't seem to get applied. Here's a test with integer bound variables: public static void main(String[] args) { Problem p = new Problem(); p.setPrecision(0.01); IntDomainVar height = p.makeBoundIntVar("Height", 1, 100); IntDomainVar weight = p.makeBoundIntVar("Weight", 1, 100); Constraint weightIsDoubleHeight = p.geq(weight, p.mult(2, height)); Constraint tall = p.geq(height,44); Constraint weightIsTripleHeight = p.geq(weight, p.mult(3, height)); Constraint tallImpliesHeavy = p.implies(tall,weightIsTripleHeight); p.post(weightIsDoubleHeight); p.post(tallImpliesHeavy); System.out.println(p.pretty()); if (p.maximize(height, false)) { System.out.println(height.pretty()); System.out.println(weight.pretty()); } else { System.out.println("No solution."); } } This works correctly, producing a solution of height=43 and weight=86. When I switch over to RealVar, the implies constraint, 'tallImpliesHeavy', no longer works. public static void main(String[] args) { Problem p = new Problem(); p.setPrecision(0.01); RealVar height = p.makeRealVar("Height", 1, 100); RealVar weight = p.makeRealVar("Weight", 1, 100); Constraint weightIsDoubleHeight = p.geq(weight, p.mult(p.cst(2), height)); Constraint tall = p.geq(height,44); Constraint weightIsTripleHeight = p.geq(weight, p.mult(p.cst(3), height)); Constraint tallImpliesHeavy = p.implies(tall,weightIsTripleHeight); p.post(weightIsDoubleHeight); p.post(tallImpliesHeavy); System.out.println(p.pretty()); if (p.maximize(height, false)) { System.out.println(height.pretty()); System.out.println(weight.pretty()); } else { System.out.println("No solution."); } } This produces an answer of height= approx. 50, and weight=approx. 100. Any insight would be helpful. Michael Michael Prescott direct: 416.646.7062 main: 416.646.7000 fax: 416.646.7050 Exchange Solutions Inc. 250 Yonge Street, 18th Floor Toronto, ON M5B 2L7 www.exchangesolutions.com |