[ojAlgo-user] QuadraticSolver returns different results for the exact same problem
Mathematics, linear algebra and optimisation
Brought to you by:
apete
From: Oddvar G. <od...@pr...> - 2014-05-22 13:40:34
|
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; } } |