Re: [ojAlgo-user] QuadraticSolver returns different results for the exact same problem
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Anders P. <an...@op...> - 2014-07-28 09:59:58
|
There is now a new solver org.ojalgo.optimisation.convex.ConvexSolver intended to replace and extend the functionality of org.ojalgo.optimisation.quadratic.QuadraticSolver. The new solver currently/still has exactly the same api as the old one - it's easy to switch between them. If you're using ExpressionsBasedModel (or MarkowitzModel in the org.ojalgo.finance.portfolio package) you should make sure that the method getDefaultSolver() contains this: //return QuadraticSolver.make(this); return ConvexSolver.make(this); The intention is that the new solver should handle more problems/cases, get rid of some odd behavior and scale better. If you're currently using ojAlgo to solve quadratic optimisation problems please try this new solver and report problems to this mailing list. Get the latest source code either from http://sourceforge.net/p/ojalgo/code/ or https://github.com/optimatika/ojAlgo /Anders On 22 maj 2014, at 23:09, Anders Peterson <an...@op...> wrote: > The algorithm incorporates an element of randomness to break out of cyclic behavior that sometimes occurs. I guess some combination of inequality constraints produce a numerically difficult subproblem, and it appears repeatedly. > > I've added your test case to ojAlgo's, but haven't had time to study the problem in detail yet so I don't know what else to say. > > You may try to permutate the problem - change the order of the inequality constraints or even introduce som tiny error on some problem parameter. > > /Anders > > > On 22 maj 2014, at 15:24, Oddvar Grønning <od...@pr...> wrote: > >> Hi all, >> >> I’ve been using the QuadraticSolver for a while, and suddenly stumbled over an unexpected failure to solve a problem. The solution state was APPROXIMATE and the solution was not correct. I tested the same system with another QP-solver and got the result I expected. I then condensed the problem as much as I could and made a test out of it (see below). To my surprise the test sometimes fails and sometimes passes(!). I’ve been running this test (alone) in TestNG. I’m using Ojalgo v35 and Java 1.7.55. The Q matrix is positive definite. >> >> Does anyone understand what is going on? >> >> Br >> Oddvar >> >> @Test(singleThreaded=true) >> public void Ojalgo_QuadraticSolver_Test() { >> >> >> double[][] q = new double[][] {{49.0, 31.0, 17.0, 6.0}, >> {31.0, 25.0, 13.0, 5.0}, >> {17.0, 13.0, 11.0, 3.5}, >> {6.0, 5.0, 3.5, 4..0}}; >> >> JamaMatrix JamaQ = JamaMatrix.FACTORY.rows(q); >> >> double[] c = new double[] {195.0, 59.0, -1.8, -11.7}; >> >> JamaMatrix JamaC = JamaMatrix.FACTORY.columns(c); >> >> double[][] ai = new double[][] {{1.0, 0.0, 0.0, 0.0}, >> {-1.0, 0.0, 0..0, 0.0}, >> {1.0, 1.0, 0.0, 0.0}, >> {-1.0, -1.0, 0..0, 0.0}, >> {1.0, 1.0, 1.0, 0.0}, >> {-1.0, -1.0, -1.0, 0.0}, >> {0.1, 0.0, 0.0, 0.0}, >> {0.01, 0.0, 0..0, 0.0}, >> {0.18, 0.1, 0..0, 0.0}, >> {-0.01, 0.0, 0..0, 0.0}, >> {-0.183, -0.1, 0.0, 0..0}, >> {0.0283, 0.01, 0.0, 0..0}, >> {0.25, 0.183, 0.1, 0.0}}; >> >> JamaMatrix JamaAI = JamaMatrix.FACTORY.rows(ai); >> >> double[] bi = new double[] {0.13, 0.87, 0.18, 0.82, 0.23, 0..77, -0.04, 99.67, -0.06, 100.33, 1.06, 99.62, -0.08}; >> >> JamaMatrix JamaBI = JamaMatrix.FACTORY.columns(bi); >> >> org.ojalgo.optimisation.Optimisation.Result result = null; >> >> try { >> QuadraticSolver.Builder qsBuilder = new QuadraticSolver.Builder(JamaQ, JamaC); >> qsBuilder.inequalities(JamaAI, JamaBI); >> >> QuadraticSolver qSolver = qsBuilder.build(); >> result = qSolver.solve(); >> } >> catch(Exception e) { >> e.printStackTrace(); >> assert false; >> } >> >> State state = result.getState(); >> >> assert state == State.OPTIMAL; >> >> int numElm = (int) result.count(); >> double[] solution = new double[numElm]; >> >> for(int i = 0; i < numElm; i++) { >> solution[i] = result.doubleValue(i); >> } >> >> double[] expectedSolution = new double[]{ -0.4, 0.12, -0.0196, -2.45785}; >> >> for(int i = 0; i < numElm; i++) { >> assert Math.abs(solution[i] - expectedSolution[i]) < 1e-4; >> } >> >> } >> >> ------------------------------------------------------------------------------ >> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE >> Instantly run your Selenium tests across 300+ browser/OS combos. >> Get unparalleled scalability from the best Selenium testing platform available >> Simple to use. Nothing to install. Get started now for free." >> http://p.sf.net/sfu/SauceLabs_______________________________________________ >> ojAlgo-user mailing list >> ojA...@li... >> https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > > ------------------------------------------------------------------------------ > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE > Instantly run your Selenium tests across 300+ browser/OS combos. > Get unparalleled scalability from the best Selenium testing platform available > Simple to use. Nothing to install. Get started now for free." > http://p.sf.net/sfu/SauceLabs > _______________________________________________ > ojAlgo-user mailing list > ojA...@li... > https://lists.sourceforge.net/lists/listinfo/ojalgo-user > > |