Search in sources :

Example 11 with ExpressionsBasedModel

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

the class SpecificBranchCase method testVpm2FirstBranch.

@Test
public void testVpm2FirstBranch() {
    final File tmpFile = new File(MipLibCase.PATH + "vpm2.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    TestUtils.assertTrue(tmpModel.validate());
    final ExpressionsBasedModel tmpLowerBranchModel = tmpModel.relax(false);
    final ExpressionsBasedModel tmpUpperBranchModel = tmpModel.relax(false);
    tmpLowerBranchModel.getVariable(106).upper(BigMath.ZERO);
    tmpUpperBranchModel.getVariable(106).lower(BigMath.ONE);
    final Optimisation.Result tmpLowerResult = tmpLowerBranchModel.minimise();
    final Optimisation.Result tmpUpperResult = tmpUpperBranchModel.minimise();
    final State tmpLowerState = tmpLowerResult.getState();
    final State tmpUpperState = tmpUpperResult.getState();
    if (!tmpLowerState.isFeasible() && !tmpUpperState.isFeasible()) {
        TestUtils.fail("Both these branches cannot be infeasible!");
    }
    tmpLowerBranchModel.minimise();
    if (tmpLowerState.isFeasible() && !tmpLowerBranchModel.validate(MipLibCase.PRECISION)) {
        TestUtils.fail(MipLibCase.SOLUTION_NOT_VALID);
    }
    tmpUpperBranchModel.minimise();
    if (tmpUpperState.isFeasible() && !tmpUpperBranchModel.validate(MipLibCase.PRECISION)) {
        TestUtils.fail(MipLibCase.SOLUTION_NOT_VALID);
    }
}
Also used : MathProgSysModel(org.ojalgo.optimisation.MathProgSysModel) Optimisation(org.ojalgo.optimisation.Optimisation) State(org.ojalgo.optimisation.Optimisation.State) File(java.io.File) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 12 with ExpressionsBasedModel

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

the class UCLAee236aCase method testRelaxedNodeP06.

/**
 * P6
 */
@Test
public void testRelaxedNodeP06() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    tmpModel.getVariable(1).lower(TWO);
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.INFEASIBLE, tmpResult.getState());
}
Also used : Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 13 with ExpressionsBasedModel

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

the class UCLAee236aCase method testRelaxedNodeP01.

/**
 * P1
 */
@Test
public void testRelaxedNodeP01() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).upper(TWO);
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.00 }, { 2.14 } });
    TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
    TestUtils.assertEquals(-10.43, 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 14 with ExpressionsBasedModel

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

the class UCLAee236aCase method testRelaxedNodeP09.

/**
 * P9
 */
@Test
public void testRelaxedNodeP09() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    tmpModel.getVariable(1).upper(ONE);
    tmpModel.getVariable(0).lower(FOUR);
    tmpModel.getVariable(1).upper(ZERO);
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.50 }, { 0.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 15 with ExpressionsBasedModel

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

the class UCLAee236aCase method testRelaxedNodeP07.

/**
 * P7
 */
@Test
public void testRelaxedNodeP07() {
    final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
    tmpModel.getVariable(0).lower(THREE);
    tmpModel.getVariable(1).upper(ONE);
    tmpModel.getVariable(0).upper(THREE);
    final Optimisation.Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
    final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.00 }, { 1.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)

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