Search in sources :

Example 91 with ExpressionsBasedModel

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

the class LinearProblems method testP20180311_66.

/**
 * https://github.com/optimatika/ojAlgo/issues/66
 */
@Test
public void testP20180311_66() {
    final Variable x = Variable.make("x").lower(0).weight(2);
    final Variable y = Variable.make("y").lower(0).weight(-1);
    final Variable z = Variable.make("z").lower(0).weight(4);
    final ExpressionsBasedModel model = new ExpressionsBasedModel();
    model.addVariable(x);
    model.addVariable(y);
    model.addVariable(z);
    model.addExpression().set(x, 3).set(y, 2).set(z, 2).upper(0);
    model.addExpression().set(x, 0).set(y, 3).set(z, -2).lower(2);
    final Optimisation.Result result = model.maximise();
    TestUtils.assertEquals(Optimisation.State.INFEASIBLE, result.getState());
    TestUtils.assertFalse(model.validate(result));
}
Also used : Variable(org.ojalgo.optimisation.Variable) Result(org.ojalgo.optimisation.Optimisation.Result) Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 92 with ExpressionsBasedModel

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

the class LinearProblems method testP20180312_69.

/**
 * https://github.com/optimatika/ojAlgo/issues/69
 */
@Test
public void testP20180312_69() {
    final Variable x = Variable.make("x").lower(0).weight(3);
    final Variable y = Variable.make("y").lower(0).weight(2);
    final Variable z = Variable.make("z").lower(0).weight(-2);
    final ExpressionsBasedModel model = new ExpressionsBasedModel();
    model.addVariable(x);
    model.addVariable(y);
    model.addVariable(z);
    model.addExpression().set(x, 0).set(y, 1).set(z, -2).level(4);
    model.addExpression().set(x, 0).set(y, 4).set(z, -2).upper(1);
    // ExpressionsBasedModel.clearPresolvers();
    final Optimisation.Result result = model.maximise();
    TestUtils.assertFalse(model.validate(result));
    TestUtils.assertEquals(Optimisation.State.INFEASIBLE, result.getState());
}
Also used : Variable(org.ojalgo.optimisation.Variable) Result(org.ojalgo.optimisation.Optimisation.Result) Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 93 with ExpressionsBasedModel

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

the class LinearProblems method testP20111010.

/**
 * Depending on how the constraints were constructed the solver could fail to solve and report the problem
 * to be unbounded.
 */
@Test
public void testP20111010() {
    final Variable[] tmpVariables = new Variable[] { new Variable("X").lower(ZERO).weight(ONE), new Variable("Y").lower(ZERO).weight(ZERO), new Variable("Z").lower(ZERO).weight(ZERO) };
    final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
    final Expression tmpExprC1 = tmpModel.addExpression("C1");
    tmpExprC1.level(ZERO);
    tmpExprC1.set(0, ONE);
    final Expression tmpExprC2 = tmpModel.addExpression("C2");
    tmpExprC2.level(ZERO);
    tmpExprC2.set(0, ONE);
    tmpExprC2.set(1, NEG);
    final Expression tmpExprC3 = tmpModel.addExpression("C3");
    tmpExprC3.level(ZERO);
    tmpExprC3.set(0, ONE);
    tmpExprC3.set(2, NEG);
    final BasicMatrix tmpExpectedSolution = PrimitiveMatrix.FACTORY.makeZero(3, 1);
    final Optimisation.Result tmpResult11 = tmpModel.minimise();
    // TestUtils.assertEquals(tmpExpectedState, tmpResult11.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResult11);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResult11));
    tmpExprC2.set(0, NEG);
    tmpExprC2.set(1, ONE);
    tmpExprC3.set(0, ONE);
    tmpExprC3.set(2, NEG);
    final Optimisation.Result tmpResultN1 = tmpModel.minimise();
    // TestUtils.assertEquals(tmpExpectedState, tmpResultN1.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResultN1);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResultN1));
    tmpExprC2.set(0, ONE);
    tmpExprC2.set(1, NEG);
    tmpExprC3.set(0, NEG);
    tmpExprC3.set(2, ONE);
    final Optimisation.Result tmpResult1N = tmpModel.minimise();
    // TestUtils.assertEquals(tmpExpectedState, tmpResult1N.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResult1N);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResult1N));
    tmpExprC2.set(0, NEG);
    tmpExprC2.set(1, ONE);
    tmpExprC3.set(0, NEG);
    tmpExprC3.set(2, ONE);
    final Optimisation.Result tmpResultNN = tmpModel.minimise();
    // TestUtils.assertEquals(tmpExpectedState, tmpResultNN.getState());
    TestUtils.assertStateNotLessThanOptimal(tmpResultNN);
    TestUtils.assertEquals(tmpExpectedSolution, RationalMatrix.FACTORY.columns(tmpResultNN));
}
Also used : BasicMatrix(org.ojalgo.matrix.BasicMatrix) Variable(org.ojalgo.optimisation.Variable) Expression(org.ojalgo.optimisation.Expression) Result(org.ojalgo.optimisation.Optimisation.Result) Optimisation(org.ojalgo.optimisation.Optimisation) ExpressionsBasedModel(org.ojalgo.optimisation.ExpressionsBasedModel) Test(org.junit.jupiter.api.Test)

Example 94 with ExpressionsBasedModel

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

the class NetlibCase method testShare2b.

/**
 * OK! 2010-04-19 lp_solve => -415.73224074
 */
@Test
public void testShare2b() {
    final File tmpFile = new File(PATH + "share2b.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    this.assertMinMaxVal(tmpModel, new BigDecimal("-4.1573224074E+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 95 with ExpressionsBasedModel

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

the class NetlibCase method testKb2.

/**
 * OK! 2010-04-19 lp_solve => -1749.90012991
 */
@Test
public void testKb2() {
    final File tmpFile = new File(PATH + "kb2.mps");
    final MathProgSysModel tmpMPS = MathProgSysModel.make(tmpFile);
    final ExpressionsBasedModel tmpModel = tmpMPS.getExpressionsBasedModel();
    this.assertMinMaxVal(tmpModel, new BigDecimal("-1.74990012991E+03"), 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)

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