Skip to content

Commit

Permalink
Additional LP test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Dec 28, 2024
1 parent 42394ed commit e5d4111
Show file tree
Hide file tree
Showing 78 changed files with 75,404 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Added / Changed / Deprecated / Fixed / Removed / Security

> Corresponds to changes in the `develop` branch since the last release
### Changed

#### org.ojalgo.type

- The `ForgetfulMap` gained support for disposer-hooks – code that is called when objects are invalidated and removed from the cache. Also streamlined the code to create single `ForgetfulMap.ValueCache<T>` instances.

## [55.1.0] – 2024-12-22

### Added
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/ojalgo/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.ojalgo.netio.BasicLogger;
import org.ojalgo.optimisation.ExpressionsBasedModel;
import org.ojalgo.optimisation.Optimisation;
import org.ojalgo.optimisation.Optimisation.Result;
import org.ojalgo.optimisation.Optimisation.State;
import org.ojalgo.random.Uniform;
import org.ojalgo.scalar.ComplexNumber;
Expand Down Expand Up @@ -522,6 +523,10 @@ public static void assertStateAndSolution(final String message, final Optimisati
TestUtils.assertOptimisationResult(message, expected, actual, context, true, false, true, false);
}

public static void assertStateInfeasible(final Result actual) {
Assertions.assertEquals(Optimisation.State.INFEASIBLE, actual.getState(), actual.toString());
}

public static void assertStateLessThanFeasible(final Optimisation.Result actual) {
Assertions.assertFalse(actual.getState().isFeasible(), actual.toString());
}
Expand All @@ -534,6 +539,14 @@ public static void assertStateNotLessThanOptimal(final Optimisation.Result actua
Assertions.assertTrue(actual.getState().isOptimal(), actual.toString());
}

public static void assertStateUnbounded(final Result actual) {
Assertions.assertEquals(Optimisation.State.UNBOUNDED, actual.getState(), actual.toString());
}

public static void assertStateUnboundedOrLessThanFeasible(final Result actual) {
Assertions.assertTrue(!actual.getState().isFeasible() || Optimisation.State.UNBOUNDED.equals(actual.getState()), actual.toString());
}

public static void assertTensorEquals(final Tensor<?, ?> expected, final Tensor<?, ?> actual) {

TestUtils.assertEquals(expected.rank(), actual.rank());
Expand Down
67 changes: 55 additions & 12 deletions src/test/java/org/ojalgo/optimisation/ModelFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,76 @@
*/
public interface ModelFileTest {

/**
* expMinValString or expMaxValString can be null, empty string or a number-string.
* <ul>
* <li>null means that direction is not tested.
* <li>A number-string is the expected optimal solution value.
* <li>An empty string means unbounded in that direction.
* <li>If both are empty string the problem is infeasible (rather than unbounded in both directions).
* </ul>
*/
static void assertValues(final ExpressionsBasedModel model, final String expMinValString, final String expMaxValString, final NumberContext accuracy) {

BigDecimal expMinVal = expMinValString != null ? new BigDecimal(expMinValString) : null;
BigDecimal expMaxVal = expMaxValString != null ? new BigDecimal(expMaxValString) : null;
BigDecimal expMinVal = expMinValString != null && !expMinValString.isEmpty() ? new BigDecimal(expMinValString) : null;
BigDecimal expMaxVal = expMaxValString != null && !expMaxValString.isEmpty() ? new BigDecimal(expMaxValString) : null;

TestUtils.assertTrue(model.validate());

if (expMinVal != null) {
Result result = null;

Result result = model.minimise();
if (expMinValString != null) {

TestUtils.assertTrue("Minimisation solution not valid!", model.validate(result, accuracy, BasicLogger.DEBUG));
result = model.minimise();

TestUtils.assertEquals(expMinVal, result.getValue(), accuracy);
if (expMinValString.isEmpty()) {

TestUtils.assertStateNotLessThanOptimal(result);
if (expMaxValString != null && expMaxValString.isEmpty()) {
// Infeasible

TestUtils.assertStateLessThanFeasible(result);

} else {
// Unbounded

TestUtils.assertStateUnboundedOrLessThanFeasible(result);
}

} else {

TestUtils.assertStateNotLessThanOptimal(result);

TestUtils.assertEquals(expMinVal, result.getValue(), accuracy);

TestUtils.assertTrue("Minimisation solution not valid!", model.validate(result, accuracy, BasicLogger.DEBUG));
}
}

if (expMaxVal != null) {
if (expMaxValString != null) {

Result result = model.maximise();
result = model.maximise();

TestUtils.assertTrue("Maximisation solution not valid!", model.validate(result, accuracy, BasicLogger.DEBUG));
if (expMaxValString.isEmpty()) {

TestUtils.assertEquals(expMaxVal, result.getValue(), accuracy);
if (expMinValString != null && expMinValString.isEmpty()) {
// Infeasible

TestUtils.assertStateNotLessThanOptimal(result);
TestUtils.assertStateLessThanFeasible(result);

} else {
// Unbounded

TestUtils.assertStateUnboundedOrLessThanFeasible(result);
}

} else {

TestUtils.assertStateNotLessThanOptimal(result);

TestUtils.assertEquals(expMaxVal, result.getValue(), accuracy);

TestUtils.assertTrue("Maximisation solution not valid!", model.validate(result, accuracy, BasicLogger.DEBUG));
}
}
}

Expand Down
Loading

0 comments on commit e5d4111

Please sign in to comment.