use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class UCLAee236aCase method testRelaxedNodeP04.
/**
* P4
*/
@Test
public void testRelaxedNodeP04() {
final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
tmpModel.getVariable(0).upper(TWO);
tmpModel.getVariable(1).lower(THREE);
// tmpModel.options.debug_stream = BasicLogger.DEBUG;
// tmpModel.options.debug_solver = LinearSolver.class;
// tmpModel.options.validate = true;
final Optimisation.Result tmpResult = tmpModel.minimise();
TestUtils.assertStateNotLessThanOptimal(tmpResult);
final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.00 }, { 3.00 } });
TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
TestUtils.assertEquals(-9.00, tmpModel.minimise().getValue(), PRECISION);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class UCLAee236aCase method testFullMIP.
/**
* http://www.ee.ucla.edu/ee236a/lectures/intlp.pdf
*/
@Test
public void testFullMIP() {
final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel();
final Optimisation.Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } });
TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class UCLAee236aCase method testRelaxedNodeP02.
/**
* P2
*/
@Test
public void testRelaxedNodeP02() {
final ExpressionsBasedModel tmpModel = UCLAee236aCase.makeOriginalRootModel().relax(true);
tmpModel.getVariable(0).lower(THREE);
final Optimisation.Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals(State.OPTIMAL, tmpResult.getState());
final PrimitiveDenseStore tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 3.00 }, { 1.33 } });
TestUtils.assertEquals(tmpExpX, tmpResult, PRECISION);
TestUtils.assertEquals(-10.00, tmpModel.minimise().getValue(), PRECISION);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel 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);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel 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"));
}
Aggregations