Search in sources :

Example 16 with ExpressionsBasedModel

use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.

the class UCLAee236aCase method testRelaxedNodeP04.

/**
 * P4
 */
@Test
public void testRelaxedNodeP04() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).upper(TWO);
    tmpModel.getVariable(1).lower(THREE);
    // tmpModel.options.debug_stream = BasicLogger.DEBUG;
    // tmpModel.options.debug_solver = LinearSolver.class;
    // tmpModel.options.validate = true;
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertStateNotLessThanOptimal(tmpResult);
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.00 }, { 3.00 } });
    TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
    TestUtils.assertEquals(-9.00, tmpModel.minimise().getValue(), PRECISION);
}
Also used : Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 17 with ExpressionsBasedModel

use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.

the class UCLAee236aCase method testFullMIP.

/**
 * http://www.ee.ucla.edu/ee236a/lectures/intlp.pdf
 */
@Test
public void testFullMIP() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel();
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } });
    TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
}
Also used : Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 18 with ExpressionsBasedModel

use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.

the class UCLAee236aCase method testRelaxedNodeP02.

/**
 * P2
 */
@Test
public void testRelaxedNodeP02() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.00 }, { 1.33 } });
    TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
    TestUtils.assertEquals(-10.00, tmpModel.minimise().getValue(), PRECISION);
}
Also used : Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) PrimitiveDenseStore(org.ojalgo.matrix.store.PrimitiveDenseStore) Test(org.junit.jupiter.api.Test)

Example 19 with ExpressionsBasedModel

use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.

the class BurkardtDatasetsMps method testMPSempstest.

/**
 * A simple test file primarily useful for checking the compression and decompression programs. Don't
 * think this model was designed to be solved; so I don't try to.
 */
@Test
public void testMPSempstest() {
    final File tmpFile = new File(PATH + "empstest.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    this.assertMinMaxVal(tmpModel, null, null);
}
Also used : MathProgSysModel(org.ojalgo.optimisation.MathProgSysModel) File(java.io.File) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 20 with ExpressionsBasedModel

use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.

the class BurkardtDatasetsMps method testMPStestprob.

/**
 * A simple problem with 4 rows and 3 variables. I got my version from here (same numbers but different
 * names): <a href="http://en.wikipedia.org/wiki/MPS_(format)">testprob@wikipedia</a> and/or
 * <a href="http://lpsolve.sourceforge.net/5.5/mps-format.htm">testprob@lpsolve</a>
 */
@Test
public void testMPStestprob() {
    final Variable tmpXONE = new Variable("XONE").weight(ONE).lower(ZERO).upper(FOUR);
    final Variable tmpYTWO = new Variable("YTWO").weight(FOUR).lower(NEG).upper(ONE);
    final Variable tmpZTHREE = new Variable("ZTHREE").weight(NINE).lower(ZERO).upper(null);
    final Variable[] tmpVariables = new Variable[] { tmpXONE, tmpYTWO, tmpZTHREE };
    final ExpressionsBasedModel tmpExpModel = new ExpressionsBasedModel(tmpVariables);
    final Expression tmpLIM1 = tmpExpModel.addExpression("LIM1");
    for (int v = 0; v < tmpVariables.length; v++) {
        tmpLIM1.set(v, new BigDecimal[] { ONE, ONE, ZERO }[v]);
    }
    tmpLIM1.upper(FIVE);
    final Expression tmpLIM2 = tmpExpModel.addExpression("LIM2");
    for (int v = 0; v < tmpVariables.length; v++) {
        tmpLIM2.set(v, new BigDecimal[] { ONE, ZERO, ONE }[v]);
    }
    tmpLIM2.lower(TEN);
    final Expression tmpMYEQN = tmpExpModel.addExpression("MYEQN");
    for (int v = 0; v < tmpVariables.length; v++) {
        tmpMYEQN.set(v, new BigDecimal[] { ZERO, ONE.negate(), ONE }[v]);
    }
    tmpMYEQN.level(SEVEN);
    TestUtils.assertTrue(tmpExpModel.validate());
    final File tmpFile = new File(PATH + "testprob.mps");
    final MathProgSysModel tmpActModel = MathProgSysModel.make(tmpFile);
    TestUtils.assertTrue(tmpActModel.validate());
    final Result tmpExpMinRes = tmpExpModel.minimise();
    final Result tmpActMinRes = tmpActModel.minimise();
    TestUtils.assertEquals(tmpExpMinRes.getValue(), tmpActMinRes.getValue(), PRECISION);
    TestUtils.assertEquals(tmpVariables.length, tmpExpMinRes.count());
    TestUtils.assertEquals(tmpVariables.length, tmpActMinRes.count());
    TestUtils.assertEquals(tmpExpMinRes, tmpActMinRes, PRECISION);
    for (int i = 0; i < tmpVariables.length; i++) {
        TestUtils.assertEquals(tmpVariables[i].getName(), tmpExpMinRes.doubleValue(i), tmpActMinRes.doubleValue(i), PRECISION);
    }
    if (!tmpExpModel.validate(tmpExpMinRes, PRECISION)) {
        TestUtils.fail(SOLUTION_NOT_VALID);
    }
    if (!tmpActModel.validate(tmpActMinRes, PRECISION)) {
        TestUtils.fail(SOLUTION_NOT_VALID);
    }
    this.assertMinMaxVal(tmpActModel.getExpressionsBasedModel(), new BigDecimal("54"), new BigDecimal("80"));
}
Also used : Variable(org.ojalgo.optimisation.Variable) MathProgSysModel(org.ojalgo.optimisation.MathProgSysModel) Expression(org.ojalgo.optimisation.Expression) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) File(java.io.File) BigDecimal(java.math.BigDecimal) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test)

Aggregations

ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)109 Test (org.junit.jupiter.api.Test)78 Variable (org.ojalgo.optimisation.Variable)59 Optimisation (org.ojalgo.optimisation.Optimisation)50 Result (org.ojalgo.optimisation.Optimisation.Result)49 Expression (org.ojalgo.optimisation.Expression)45 BigDecimal (java.math.BigDecimal)33 File (java.io.File)15 MathProgSysModel (org.ojalgo.optimisation.MathProgSysModel)15 PrimitiveDenseStore (org.ojalgo.matrix.store.PrimitiveDenseStore)13 BasicMatrix (org.ojalgo.matrix.BasicMatrix)11 NumberContext (org.ojalgo.type.context.NumberContext)10 ArrayList (java.util.ArrayList)9 BigArray (org.ojalgo.array.BigArray)6 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Disabled (org.junit.jupiter.api.Disabled)4