Search in sources :

Example 36 with ExpressionsBasedModel

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

the class MarketShareCase method testMipButLinearConstrainedToOptimal.

@Test
@Disabled("Underscored before JUnit 5")
public void testMipButLinearConstrainedToOptimal() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        if (tmpName.startsWith("s")) {
            tmpVariable.level(SOLUTION.get(tmpName));
        }
    }
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 37 with ExpressionsBasedModel

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

the class MarketShareCase method testRelaxedButIntegerConstrainedToOptimal.

@Test
public void testRelaxedButIntegerConstrainedToOptimal() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    tmpModel.relax(true);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        if (tmpName.startsWith("x")) {
            tmpVariable.level(SOLUTION.get(tmpName));
        }
    }
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test)

Example 38 with ExpressionsBasedModel

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

the class MarketShareCase method testMipButSomeConstainedToOptimatl.

@Test
public void testMipButSomeConstainedToOptimatl() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    // tmpModel.options.debug(IntegerSolver.class);
    // 37, 20
    final int tmpConstrLimit = 20;
    int tmpConstrCount = 0;
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        if (tmpConstrCount < tmpConstrLimit) {
            tmpVariable.level(SOLUTION.get(tmpName));
            tmpConstrCount++;
        }
    }
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertStateNotLessThanOptimal(tmpResult);
    TestUtils.assertTrue(tmpModel.validate(tmpModel.options.feasibility));
    TestUtils.assertTrue(tmpModel.validate(tmpResult, tmpModel.options.feasibility));
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), tmpModel.options.feasibility);
    final NumberContext tmpContext = tmpModel.options.solution.newScale(13);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        final String tmpName = tmpVariable.getName();
        final double tmpExpected = SOLUTION.get(tmpName).doubleValue();
        final double tmpActual = tmpVariable.getValue().doubleValue();
        TestUtils.assertEquals(tmpName, tmpExpected, tmpActual, tmpContext);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) NumberContext(org.ojalgo.type.context.NumberContext) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test)

Example 39 with ExpressionsBasedModel

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

the class MarketShareCase method testRelaxedButAllConstrainedToOptimal.

@Test
public void testRelaxedButAllConstrainedToOptimal() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    tmpModel.relax(true);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        tmpVariable.level(SOLUTION.get(tmpVariable.getName()));
    }
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test)

Example 40 with ExpressionsBasedModel

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

the class MarketShareCase method testFullMIP.

@Test
@Disabled("Underscored before JUnit 5")
public void testFullMIP() {
    final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
    // tmpModel.options.debug_stream = BasicLogger.DEBUG;
    // tmpModel.options.debug_solver = IntegerSolver.class;
    // tmpModel.options.validate = true;
    final Result tmpResult = tmpModel.minimise();
    TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
    for (final Variable tmpVariable : tmpModel.getVariables()) {
        TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Result(org.ojalgo.optimisation.Optimisation.Result) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

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