Re: [ojAlgo-user] Simple quadratic program throws a division by zero error
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Leaman, R. (NIH/NLM/N. [E] <rob...@ni...> - 2015-09-09 13:06:30
|
Thank you very much Anders. I appreciate both the bug fix and the explanation: knowing exactly what was needed made it much easier to implement the workaround. -Robert -----Original Message----- From: Anders Peterson [mailto:an...@op...] Sent: Tuesday, September 08, 2015 4:23 PM To: oja...@li... Subject: Re: [ojAlgo-user] Simple quadratic program throws a division by zero error Thanks for reporting this. You’re not doing anything wrong. ojAlgo failed to handle the case where all inequality constraints where “active” (zero slack). If you get the latest source code from SourceForge or GitHub the bug is fixed, and it will be in the next release. As you noted there was a simple workaround. Just add one simple obviously redundant inequality constraint. /Anders > On 8 sep 2015, at 16:35, Leaman, Robert (NIH/NLM/NCBI) [E] <rob...@ni...> wrote: > > Hi, > > I am relatively new to ojAlgo and to quadratic programming. I’ve had quite a bit of success as I try it out, but found one QP that throws an error but looks fine to me. I removed extraneous variables and reduced it to a small program that throws the same error. > > This is the program: > PrimitiveDenseStore tmpQ = PrimitiveDenseStore.FACTORY.rows(new > double[][] { { 2, 0 }, { 0, 2 } }); PrimitiveDenseStore tmpC = > PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0, 0 } }); > PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new > double[][] { { -1, -1 } }); PrimitiveDenseStore tmpBI = > PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1 } }); > ConvexSolver tmpSolver = new ConvexSolver.Builder(tmpQ, > tmpC.transpose()).inequalities(tmpAI, tmpBI).build(); > Optimisation.Result tmpResult = tmpSolver.solve(); > > The result is a division by zero error: > java.lang.ArithmeticException: / by zero at > org.ojalgo.matrix.store.PrimitiveDenseStore.fillByMultiplying(Primitiv > eDenseStore.java:1199) at > org.ojalgo.matrix.store.MatrixStore.multiply(MatrixStore.java:438) > at org.ojalgo.matrix.store.MatrixStore.multiply(MatrixStore.java:432) > at > org.ojalgo.optimisation.convex.ActiveSetSolver.performIteration(Active > SetSolver.java:412) at > org.ojalgo.optimisation.convex.ConvexSolver.solve(ConvexSolver.java:31 > 0) at > org.ojalgo.optimisation.Optimisation$Solver.solve(Optimisation.java:38 > 3) > > I calculate that the program should have a single minimum of 0.5 at the point (0.5, 0.5). In fact, ojAlgo does find this solution I get if I add at least one additional constraint; either x1>=0 or x2>=0, like this: > PrimitiveDenseStore tmpAI = PrimitiveDenseStore.FACTORY.rows(new > double[][] { { -1, -1 }, { 0, -1 } }); PrimitiveDenseStore tmpBI = > PrimitiveDenseStore.FACTORY.rows(new double[][] { { -1 }, { 0 } }); > > I’m wondering if someone could point out what (if anything) I’m doing wrong. > > Thank you, > Robert > ---------------------------------------------------------------------- > -------- _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user ------------------------------------------------------------------------------ _______________________________________________ ojAlgo-user mailing list ojA...@li... https://lists.sourceforge.net/lists/listinfo/ojalgo-user |