You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2014/01/22 23:12:43 UTC
svn commit: r1560541 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java
test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java
Author: tn
Date: Wed Jan 22 22:12:42 2014
New Revision: 1560541
URL: http://svn.apache.org/r1560541
Log:
[MATH-970] Add a method isSolutionOptimal to SolutionCallback.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java?rev=1560541&r1=1560540&r2=1560541&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/linear/SolutionCallback.java Wed Jan 22 22:12:42 2014
@@ -52,4 +52,12 @@ public class SolutionCallback implements
public PointValuePair getSolution() {
return tableau != null ? tableau.getSolution() : null;
}
+
+ /**
+ * Returns if the found solution is optimal.
+ * @return {@code true} if the solution is optimal, {@code false} otherwise
+ */
+ public boolean isSolutionOptimal() {
+ return tableau != null ? tableau.isOptimal() : false;
+ }
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java?rev=1560541&r1=1560540&r2=1560541&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optim/linear/SimplexSolverTest.java Wed Jan 22 22:12:42 2014
@@ -763,6 +763,9 @@ public class SimplexSolverTest {
final SimplexSolver solver = new SimplexSolver();
final SolutionCallback callback = new SolutionCallback();
+
+ Assert.assertNull(callback.getSolution());
+ Assert.assertFalse(callback.isSolutionOptimal());
try {
solver.optimize(new MaxIter(3), f, new LinearConstraintSet(constraints),
@@ -775,6 +778,7 @@ public class SimplexSolverTest {
final PointValuePair solution = callback.getSolution();
Assert.assertNotNull(solution);
Assert.assertTrue(validSolution(solution, constraints, 1e-4));
+ Assert.assertFalse(callback.isSolutionOptimal());
// the solution is clearly not optimal: optimal = 10.0
Assert.assertEquals(7.0, solution.getValue(), 1e-4);
}