Search in sources :

Example 1 with MathProgSysModel

use of org.ojalgo.optimisation.MathProgSysModel 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 2 with MathProgSysModel

use of org.ojalgo.optimisation.MathProgSysModel 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 3 with MathProgSysModel

use of org.ojalgo.optimisation.MathProgSysModel 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)

Example 4 with MathProgSysModel

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

the class NetlibCase method testBoeing2.

/**
 * OK! 2010-04-19 lp_solve => -315.01872802
 */
@Test
public void testBoeing2() {
    final File tmpFile = new File(PATH + "boeing2.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    this.assertMinMaxVal(tmpModel, new BigDecimal("-3.1501872802E+02"), null);
}
Also used : MathProgSysModel(org.ojalgo.optimisation.MathProgSysModel) File(java.io.File) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test)

Example 5 with MathProgSysModel

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

the class MipLibCase method assertMinMaxVal.

protected static void assertMinMaxVal(final String modelName, final BigDecimal expMinVal, final BigDecimal expMaxVal, final boolean relax, final Map<String, BigDecimal> solution) {
    if (DEBUG) {
        BasicLogger.DEBUG.println();
        BasicLogger.DEBUG.println();
        BasicLogger.DEBUG.println(modelName);
        BasicLogger.DEBUG.println();
    }
    final File tmpFile = new File(PATH + modelName);
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    if (relax) {
        tmpModel.relax(true);
    }
    if (solution != null) {
        for (final Variable tmpVariable : tmpModel.getVariables()) {
            final BigDecimal tmpValue = solution.get(tmpVariable.getName());
            if (tmpValue != null) {
                tmpVariable.setValue(tmpValue);
            } else {
                tmpVariable.setValue(BigMath.ZERO);
            }
        }
        if (!tmpModel.validate(PRECISION.newScale(4))) {
            TestUtils.fail(SOLUTION_NOT_VALID);
        }
    }
    tmpModel.options.mip_gap = 0.001;
    tmpModel.options.time_suffice = 5L * CalendarDateUnit.MINUTE.size();
    tmpModel.options.time_abort = 15L * CalendarDateUnit.MINUTE.size();
    tmpModel.options.progress(IntegerSolver.class);
    TestUtils.assertTrue(tmpModel.validate());
    if (expMinVal != null) {
        final double tmpMinimum = tmpModel.minimise().getValue();
        if (!tmpModel.validate(PRECISION)) {
            TestUtils.fail(SOLUTION_NOT_VALID);
        }
        final double tmpExpected = expMinVal.doubleValue();
        final double tmpError = expMinVal.ulp().doubleValue();
        TestUtils.assertEquals(tmpExpected, tmpMinimum, tmpError);
    }
    if (expMaxVal != null) {
        final double tmpMaximum = tmpModel.maximise().getValue();
        if (!tmpModel.validate(PRECISION)) {
            TestUtils.fail(SOLUTION_NOT_VALID);
        }
        final double tmpExpected = expMaxVal.doubleValue();
        final double tmpError = expMaxVal.ulp().doubleValue();
        TestUtils.assertEquals(tmpExpected, tmpMaximum, tmpError);
    }
}
Also used : Variable(org.ojalgo.optimisation.Variable) MathProgSysModel(org.ojalgo.optimisation.MathProgSysModel) File(java.io.File) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) BigDecimal(java.math.BigDecimal)

Aggregations

File (java.io.File)16 MathProgSysModel (org.ojalgo.optimisation.MathProgSysModel)16 ExpressionsBasedModel (org.ojalgo.optimisation.ExpressionsBasedModel)15 Test (org.junit.jupiter.api.Test)14 BigDecimal (java.math.BigDecimal)12 Disabled (org.junit.jupiter.api.Disabled)2 Variable (org.ojalgo.optimisation.Variable)2 Expression (org.ojalgo.optimisation.Expression)1 Optimisation (org.ojalgo.optimisation.Optimisation)1 Result (org.ojalgo.optimisation.Optimisation.Result)1 State (org.ojalgo.optimisation.Optimisation.State)1