use of org.ojalgo.optimisation.Variable 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.Variable 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.Variable 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.Variable 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.Variable in project ojAlgo by optimatika.
the class LinearProblems method testP20180314_70.
/**
* https://github.com/optimatika/ojAlgo/issues/70
*/
@Test
public void testP20180314_70() {
Variable x = Variable.make("x").lower(0).weight(-2);
Variable y = Variable.make("y").lower(0).weight(-2);
ExpressionsBasedModel model = new ExpressionsBasedModel();
model.addVariable(x);
model.addVariable(y);
model.addExpression().set(x, 3).set(y, 0).lower(2);
model.addExpression().set(x, 1).set(y, 2).lower(-5);
model.addExpression().set(x, 3).set(y, 1).upper(2);
final BigArray expected = BigArray.wrap(BigMath.TWO.multiply(BigMath.THIRD), BigMath.ZERO);
TestUtils.assertTrue(model.validate(expected));
Optimisation.Result solution = model.maximise();
TestUtils.assertTrue(model.validate(solution));
TestUtils.assertStateNotLessThanOptimal(solution);
}
Aggregations