[ojAlgo-user] Problem with mixed integer linear programming
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Julien.Cojan <Jul...@op...> - 2011-10-10 10:18:39
|
Hello, I am using OjAlgo to solve mixed linear programming problems. However I often get a NullPointerException when running on my examples. I tried version 30.0 and 30.6, I get the same error. This is the smallest example I could find where I get this exception : import static org.ojalgo.constant.BigMath.ONE; import static org.ojalgo.constant.BigMath.ZERO; import java.math.BigDecimal; import org.ojalgo.optimisation.Expression; import org.ojalgo.optimisation.Variable; import org.ojalgo.optimisation.linear.LinearExpressionsModel; public class TestOjAlgo { public static void testBug1(){ Variable[] objective = new Variable[] { new Variable("X").weight(ONE), new Variable("Y").weight(ZERO), new Variable("Z").weight(ZERO)}; objective[1].setInteger(true); LinearExpressionsModel model = new LinearExpressionsModel(objective); // c1: X =0 Expression c1 = model.addEmptyLinearExpression("c1"); c1.level(ZERO); c1.setLinearFactor(0, ONE); // c2: -X +5Y =0 Expression c2 = model.addEmptyLinearExpression("c2"); c2.level(ZERO); c2.setLinearFactor(0, new BigDecimal(-1)); c2.setLinearFactor(1, ONE); // c3: X -Z =0 Expression c3 = model.addEmptyLinearExpression("c3"); c3.level(ZERO); // bugs with this constraint c3.setLinearFactor(0, ONE); c3.setLinearFactor(2, new BigDecimal(-1)); // but not with this one ??? // c3.setLinearFactor(0, new BigDecimal(-1)); // c3.setLinearFactor(2, ONE); model.minimise(); } public static void main(String[] args){ testBug1(); } } I get the following message Exception in thread "main" java.lang.NullPointerException at org.ojalgo.optimisation.OptimisationSolver$Result.<init>(OptimisationSolver.java:99) at org.ojalgo.optimisation.integer.IntegerSolver.solve(IntegerSolver.java:318) at org.ojalgo.optimisation.ExpressionsBasedModel.solve(ExpressionsBasedModel.java:741) at org.ojalgo.optimisation.ExpressionsBasedModel.minimise(ExpressionsBasedModel.java:458) at TestOjAlgo.testBug1(TestOjAlgo.java:57) at TestOjAlgo.main(TestOjAlgo.java:61) Is it a bug or am I not using ojAlgo properly ? -- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). |