use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method test6LinearModelCase.
/**
* Simplest possible unbounded model
*/
@Test
public void test6LinearModelCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(ONE), new Variable("X2").lower(ZERO).weight(TWO), new Variable("X3").lower(ZERO).weight(THREE) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Optimisation.Result tmpResult = tmpModel.maximise();
TestUtils.assertEquals(State.UNBOUNDED, tmpResult.getState());
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method test2LinearModelCase.
/**
* http://www.stats.ox.ac.uk/~yu/4_Simplex_II.pdf
*/
@Test
public void test2LinearModelCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(THREE), new Variable("X2").lower(ZERO).weight(ZERO), new Variable("X3").lower(ZERO).weight(ONE) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression tmpExprC1 = tmpModel.addExpression("C1");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC1.set(i, new BigDecimal[] { ONE, TWO, ONE }[i]);
}
tmpExprC1.level(TEN);
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { ONE, TWO.negate(), TWO }[i]);
}
tmpExprC2.level(SIX);
final Optimisation.Result tmpResult = tmpModel.maximise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 8.0 }, { 1.0 }, { 0.0 } });
final PhysicalStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1, 2 }));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method test4LinearModelCase.
/**
* http://www.saintmarys.edu/~psmith/338act14.html
*/
@Test
public void test4LinearModelCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(ONE.negate()), new Variable("X2").lower(ZERO).weight(ONE), new Variable("X3").lower(ZERO).weight(ZERO) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression tmpExprC1 = tmpModel.addExpression("C1");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC1.set(i, new BigDecimal[] { SIX, ONE.negate(), ZERO }[i]);
}
tmpExprC1.upper(TEN);
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { ONE, FIVE, ZERO }[i]);
}
tmpExprC2.lower(FOUR);
final Expression tmpExprC3 = tmpModel.addExpression("C3");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC3.set(i, new BigDecimal[] { ONE, FIVE, ONE }[i]);
}
tmpExprC3.level(FIVE);
final Optimisation.Result tmpResult = tmpModel.minimise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 1.74 }, { 0.45 }, { 1.0 } });
final PhysicalStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1, 2 }));
tmpActX.modifyAll(new NumberContext(7, 2).getFunction(PrimitiveFunction.getSet()));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearProblems method testP20180310_62.
/**
* https://github.com/optimatika/ojAlgo/issues/62
*/
@Test
public void testP20180310_62() {
final Variable x = Variable.make("x").lower(0).weight(1);
final Variable y = Variable.make("y").lower(0).weight(0);
final ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);
model.addExpression("first").set(x, 0).set(y, 1).lower(1);
model.addExpression("second").set(x, 0).set(y, 1).upper(-1);
TestUtils.assertEquals(Optimisation.State.INFEASIBLE, model.maximise().getState());
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearProblems method testP20150127.
/**
* Problemet var att en av noderna som IntegerSolver genererade var infeasible, men det misslyckades
* LinearSolver med att identifiera och returnerade en felaktig lösning som OPTIMAL. Detta testfall
* motsvarar
*/
@Test
public void testP20150127() {
final ExpressionsBasedModel tmpModel = P20150127b.getModel(true, true);
// tmpModel.options.debug(LinearSolver.class);
// Kan få testfallet att gå igenom, men dåsmäller andra testfall
// tmpModel.options.objective = tmpModel.options.objective.newScale(8);
final Result tmpResult = tmpModel.minimise();
// Should be infeasible
TestUtils.assertStateLessThanFeasible(tmpResult);
TestUtils.assertFalse(tmpModel.validate(tmpResult));
}
Aggregations