use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class MarketShareCase method testMipButLinearConstrainedToOptimal.
@Test
@Disabled("Underscored before JUnit 5")
public void testMipButLinearConstrainedToOptimal() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
for (final Variable tmpVariable : tmpModel.getVariables()) {
final String tmpName = tmpVariable.getName();
if (tmpName.startsWith("s")) {
tmpVariable.level(SOLUTION.get(tmpName));
}
}
final Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
for (final Variable tmpVariable : tmpModel.getVariables()) {
TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
}
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class MarketShareCase method testRelaxedButIntegerConstrainedToOptimal.
@Test
public void testRelaxedButIntegerConstrainedToOptimal() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
tmpModel.relax(true);
for (final Variable tmpVariable : tmpModel.getVariables()) {
final String tmpName = tmpVariable.getName();
if (tmpName.startsWith("x")) {
tmpVariable.level(SOLUTION.get(tmpName));
}
}
final Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
for (final Variable tmpVariable : tmpModel.getVariables()) {
TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
}
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class MarketShareCase method testMipButSomeConstainedToOptimatl.
@Test
public void testMipButSomeConstainedToOptimatl() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
// tmpModel.options.debug(IntegerSolver.class);
// 37, 20
final int tmpConstrLimit = 20;
int tmpConstrCount = 0;
for (final Variable tmpVariable : tmpModel.getVariables()) {
final String tmpName = tmpVariable.getName();
if (tmpConstrCount < tmpConstrLimit) {
tmpVariable.level(SOLUTION.get(tmpName));
tmpConstrCount++;
}
}
final Result tmpResult = tmpModel.minimise();
TestUtils.assertStateNotLessThanOptimal(tmpResult);
TestUtils.assertTrue(tmpModel.validate(tmpModel.options.feasibility));
TestUtils.assertTrue(tmpModel.validate(tmpResult, tmpModel.options.feasibility));
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), tmpModel.options.feasibility);
final NumberContext tmpContext = tmpModel.options.solution.newScale(13);
for (final Variable tmpVariable : tmpModel.getVariables()) {
final String tmpName = tmpVariable.getName();
final double tmpExpected = SOLUTION.get(tmpName).doubleValue();
final double tmpActual = tmpVariable.getValue().doubleValue();
TestUtils.assertEquals(tmpName, tmpExpected, tmpActual, tmpContext);
}
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class MarketShareCase method testRelaxedButAllConstrainedToOptimal.
@Test
public void testRelaxedButAllConstrainedToOptimal() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
tmpModel.relax(true);
for (final Variable tmpVariable : tmpModel.getVariables()) {
tmpVariable.level(SOLUTION.get(tmpVariable.getName()));
}
final Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
for (final Variable tmpVariable : tmpModel.getVariables()) {
TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
}
}
use of org.ojalgo.optimisation.ExpressionsBasedModel in project ojAlgo by optimatika.
the class MarketShareCase method testFullMIP.
@Test
@Disabled("Underscored before JUnit 5")
public void testFullMIP() {
final ExpressionsBasedModel tmpModel = MarketShareCase.makeModel();
// tmpModel.options.debug_stream = BasicLogger.DEBUG;
// tmpModel.options.debug_solver = IntegerSolver.class;
// tmpModel.options.validate = true;
final Result tmpResult = tmpModel.minimise();
TestUtils.assertEquals("OBJECTIVE_MIP", OBJECTIVE_MIP.doubleValue(), tmpResult.getValue(), 1E-14 / PrimitiveMath.THREE);
for (final Variable tmpVariable : tmpModel.getVariables()) {
TestUtils.assertEquals(tmpVariable.getName(), SOLUTION.get(tmpVariable.getName()).doubleValue(), tmpVariable.getValue().doubleValue(), 1E-14 / PrimitiveMath.THREE);
}
}
Aggregations