use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class ComPictetPamBamTest method setupModel.
void setupModel() {
//
// variables
//
vars = new Variable[numberOfVars];
vars[0] = new Variable("x0").lower(BigMath.ZERO).upper(BigMath.HUNDRED);
vars[1] = new Variable("x1").lower(BigMath.ZERO).upper(BigMath.HUNDRED);
//
// model
//
linearModel = new ExpressionsBasedModel(vars);
{
//
// x0 = 2*x1, i.e. x0 - 2*x1 = 0
//
final Expression e = linearModel.addExpression("x0 = 2*x1");
e.set(0, BigMath.ONE);
e.set(1, BigMath.TWO.negate());
e.level(BigMath.ZERO);
}
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method buildOldKnapsackTestModel.
private ExpressionsBasedModel buildOldKnapsackTestModel() {
Variable tmpVar;
final Variable[] tmpVariables = new Variable[8];
tmpVar = new Variable("QRHEDGE");
tmpVar.weight(BigMath.ZERO);
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ZERO);
tmpVariables[0] = tmpVar;
tmpVar = new Variable("QKORT");
tmpVar.weight(new BigDecimal("0.0345"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ONE);
tmpVariables[1] = tmpVar;
tmpVar = new Variable("QHEDGE");
tmpVar.weight(new BigDecimal("0.04"));
tmpVar.lower(new BigDecimal("0.1846"));
tmpVar.upper(new BigDecimal("0.1846"));
tmpVariables[2] = tmpVar;
tmpVar = new Variable("QLÅNG");
tmpVar.weight(new BigDecimal("0.0412"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ONE);
tmpVariables[3] = tmpVar;
tmpVar = new Variable("QFF");
tmpVar.weight(new BigDecimal("0.069575"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ZERO);
tmpVariables[4] = tmpVar;
tmpVar = new Variable("QGLOBAL");
tmpVar.weight(new BigDecimal("0.0738"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ONE);
tmpVariables[5] = tmpVar;
tmpVar = new Variable("QSVERIGE");
tmpVar.weight(new BigDecimal("0.1288"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ONE);
tmpVariables[6] = tmpVar;
tmpVar = new Variable("QFF2");
tmpVar.weight(new BigDecimal("2.3"));
tmpVar.lower(BigMath.ZERO);
tmpVar.upper(BigMath.ZERO);
tmpVariables[7] = tmpVar;
final ExpressionsBasedModel retVal = new ExpressionsBasedModel(tmpVariables);
final int tmpLength = retVal.countVariables();
final Expression retVal2 = retVal.addExpression("100%");
for (int i = 0; i < tmpLength; i++) {
retVal2.set(i, ONE);
}
final Expression retVal1 = retVal2;
retVal1.lower(BigMath.ONE);
retVal1.upper(BigMath.ONE);
return retVal;
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method test3LinearModelCase.
/**
* http://optlab-server.sce.carleton.ca/POAnimations/TwoPhase.aspx
*/
@Test
public void test3LinearModelCase() {
final Variable[] tmpVariables = new Variable[] { new Variable("X1").lower(ZERO).weight(TEN.add(FIVE)), new Variable("X2").lower(ZERO).weight(TEN) };
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, ZERO }[i]);
}
tmpExprC1.upper(TWO);
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { ZERO, ONE }[i]);
}
tmpExprC2.upper(THREE);
final Expression tmpExprC3 = tmpModel.addExpression("C3");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC3.set(i, new BigDecimal[] { ONE, ONE }[i]);
}
tmpExprC3.level(FOUR);
final Optimisation.Result tmpResult = tmpModel.maximise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 2.0 }, { 2.0 } });
final PhysicalStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1 }));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method testMaxOldKnapsackTestModel.
@Test
public void testMaxOldKnapsackTestModel() {
final ExpressionsBasedModel tmpModel = this.buildOldKnapsackTestModel();
final Optimisation.Result tmpResult = tmpModel.maximise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final MatrixStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 0.0 }, { 0.0 }, { 0.1846 }, { 0.0 }, { 0.0 }, { 0.0 }, { 0.8154 }, { 0.0 } });
final MatrixStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1, 2, 3, 4, 5, 6, 7 }));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class LinearDesignTestCases method test5LinearModelCase.
/**
* http://www.maths.bris.ac.uk/~maxmr/opt/sm2.pdf
*/
@Test
public void test5LinearModelCase() {
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[] { HALF, QUARTER }[i]);
}
tmpExprC1.upper(FOUR);
final Expression tmpExprC2 = tmpModel.addExpression("C2");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC2.set(i, new BigDecimal[] { ONE, THREE }[i]);
}
tmpExprC2.lower(TEN.add(TEN));
final Expression tmpExprC3 = tmpModel.addExpression("C3");
for (int i = 0; i < tmpModel.countVariables(); i++) {
tmpExprC3.set(i, new BigDecimal[] { ONE, ONE }[i]);
}
tmpExprC3.level(TEN);
final Optimisation.Result tmpResult = tmpModel.minimise();
final BasicMatrix tmpSolution = RationalMatrix.FACTORY.columns(tmpResult);
final PhysicalStore<Double> tmpExpX = PrimitiveDenseStore.FACTORY.rows(new double[][] { { 5.0 }, { 5.0 } });
final PhysicalStore<Double> tmpActX = PrimitiveDenseStore.FACTORY.copy(tmpSolution.selectRows(new int[] { 0, 1 }));
TestUtils.assertEquals(tmpExpX, tmpActX);
}
Aggregations