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));
}
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());
}
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));
}
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);
}
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);
}
Aggregations