use of org.ojalgo.optimisation.Variable in project ojAlgo by optimatika.
the class UCLAee236aCase method makeOriginalRootModel.
private static ExpressionsBasedModel makeOriginalRootModel() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(TWO.negate()).integer(true), new Variable("X2").lower(ZERO).weight(THREE.negate()).integer(true) };
final ExpressionsBasedModel retVal = new ExpressionsBasedModel(tmpVariables);
retVal.setMinimisation();
final Expression tmpExprC1 = retVal.addExpression("C1");
for (int i = 0; i < retVal.countVariables(); i++) {
tmpExprC1.set(i, new BigDecimal[] { TWO.multiply(NINTH), QUARTER }[i]);
}
tmpExprC1.upper(ONE);
final Expression tmpExprC2 = retVal.addExpression("C2");
for (int i = 0; i < retVal.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { SEVENTH, THIRD }[i]);
}
tmpExprC2.upper(ONE);
return retVal;
}
use of org.ojalgo.optimisation.Variable in project ojAlgo by optimatika.
the class LinearDesignTestCases method testUnboundedCase.
@Test
public void testUnboundedCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").weight(ONE), new Variable("X2").weight(TWO), new Variable("X3").weight(THREE) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression tmpExprC1 = tmpModel.addExpression("C1");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC1.set(i, ONE);
}
tmpExprC1.level(ONE);
final Optimisation.Result tmpMinResult = tmpModel.maximise();
TestUtils.assertTrue(tmpMinResult.getState().isFeasible());
TestUtils.assertFalse(tmpMinResult.getState().isOptimal());
TestUtils.assertTrue(tmpMinResult.getState().isFailure());
TestUtils.assertTrue(tmpModel.validate(tmpMinResult));
TestUtils.assertEquals(Optimisation.State.UNBOUNDED, tmpMinResult.getState());
final Optimisation.Result tmpMaxResult = tmpModel.maximise();
TestUtils.assertTrue(tmpMaxResult.getState().isFeasible());
TestUtils.assertFalse(tmpMaxResult.getState().isOptimal());
TestUtils.assertTrue(tmpMaxResult.getState().isFailure());
TestUtils.assertTrue(tmpModel.validate(tmpMaxResult));
TestUtils.assertEquals(Optimisation.State.UNBOUNDED, tmpMaxResult.getState());
}
use of org.ojalgo.optimisation.Variable in project ojAlgo by optimatika.
the class LinearDesignTestCases method test1LinearModelCase.
/**
* http://math.uww.edu/~mcfarlat/s-prob.htm
*/
@Test
public void test1LinearModelCase() {
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(ONE.negate()) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression retExprC1 = tmpModel.addExpression("C1");
for (int i = 0; i < tmpModel.countVariables(); i++) {
retExprC1.set(i, new BigDecimal[] { TWO, ONE, ONE }[i]);
}
retExprC1.upper(new BigDecimal("14.0"));
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { FOUR, TWO, THREE }[i]);
}
tmpExprC2.upper(new BigDecimal("28.0"));
final Expression tmpExprC3 = tmpModel.addExpression("C3");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC3.set(i, new BigDecimal[] { TWO, FIVE, FIVE }[i]);
}
tmpExprC3.upper(new BigDecimal("30.0"));
final Optimisation.Result tmpResult = tmpModel.maximise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5.0 }, { 4.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 test7LinearModelCase.
/**
* http://math.uww.edu/~mcfarlat/ns-prob.htm
*/
@Test
public void test7LinearModelCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(TWO), new Variable("X2").lower(ZERO).weight(THREE) };
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, ONE }[i]);
}
tmpExprC1.upper(TEN);
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { ONE, TWO }[i]);
}
tmpExprC2.lower(TWELVE);
final Expression tmpExprC3 = tmpModel.addExpression("C3");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC3.set(i, new BigDecimal[] { TWO, ONE }[i]);
}
tmpExprC3.lower(TWELVE);
final Optimisation.Result tmpResult = tmpModel.minimise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 4.0 }, { 4.0 } });
final PhysicalStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1 }));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
use of org.ojalgo.optimisation.Variable in project ojAlgo by optimatika.
the class LinearDesignTestCases method testInfeasibleCase.
@Test
public void testInfeasibleCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ONE).weight(ONE), new Variable("X2").lower(ONE).weight(TWO), new Variable("X3").lower(ONE).weight(THREE) };
final ExpressionsBasedModel tmpModel = new ExpressionsBasedModel(tmpVariables);
final Expression tmpExprC1 = tmpModel.addExpression("C1");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC1.set(i, ONE);
}
tmpExprC1.upper(TWO);
final Optimisation.Result tmpResult = tmpModel.maximise();
TestUtils.assertFalse(tmpResult.getState().isFeasible());
}
Aggregations