commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1397759 - in /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct: AbstractSimplex.java SimplexOptimizer.java
Date Sat, 13 Oct 2012 01:12:59 GMT
Author: erans
Date: Sat Oct 13 01:12:58 2012
New Revision: 1397759

URL: http://svn.apache.org/viewvc?rev=1397759&view=rev
Log:
MATH-874
New API allows to pass the simplex as an argument to "optimize".

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/AbstractSimplex.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/SimplexOptimizer.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/AbstractSimplex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/AbstractSimplex.java?rev=1397759&r1=1397758&r2=1397759&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/AbstractSimplex.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/AbstractSimplex.java
Sat Oct 13 01:12:58 2012
@@ -29,6 +29,7 @@ import org.apache.commons.math3.exceptio
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
 import org.apache.commons.math3.exception.util.LocalizedFormats;
 import org.apache.commons.math3.optimization.PointValuePair;
+import org.apache.commons.math3.optimization.OptimizationData;
 
 /**
  * This class implements the simplex concept.
@@ -47,7 +48,7 @@ import org.apache.commons.math3.optimiza
  * @version $Id$
  * @since 3.0
  */
-public abstract class AbstractSimplex {
+public abstract class AbstractSimplex implements OptimizationData {
     /** Simplex. */
     private PointValuePair[] simplex;
     /** Start simplex configuration. */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/SimplexOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/SimplexOptimizer.java?rev=1397759&r1=1397758&r2=1397759&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/SimplexOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/direct/SimplexOptimizer.java
Sat Oct 13 01:12:58 2012
@@ -26,6 +26,7 @@ import org.apache.commons.math3.optimiza
 import org.apache.commons.math3.optimization.PointValuePair;
 import org.apache.commons.math3.optimization.SimpleValueChecker;
 import org.apache.commons.math3.optimization.MultivariateOptimizer;
+import org.apache.commons.math3.optimization.OptimizationData;
 
 /**
  * This class implements simplex-based direct search optimization.
@@ -118,9 +119,59 @@ public class SimplexOptimizer
      * Set the simplex algorithm.
      *
      * @param simplex Simplex.
+     * @deprecated As of 3.1. The initial simplex can now be passed as an
+     * argument of the {@link #optimize(int,MultivariateFunction,GoalType,OptimizationData[])}
+     * method.
      */
+    @Deprecated
     public void setSimplex(AbstractSimplex simplex) {
-        this.simplex = simplex;
+        parseOptimizationData(simplex);
+    }
+
+    /**
+     * Optimize an objective function.
+     *
+     * @param maxEval Allowed number of evaluations of the objective function.
+     * @param f Objective function.
+     * @param goalType Optimization type.
+     * @param optData Optimization data. The following data will be looked for:
+     * <ul>
+     *  <li>{@link org.apache.commons.math3.optimization.InitialGuess InitialGuess}</li>
+     *  <li>{@link AbstractSimplex}</li>
+     * </ul>
+     * @return the point/value pair giving the optimal value for objective
+     * function.
+     */
+    @Override
+    protected PointValuePair optimizeInternal(int maxEval, MultivariateFunction f,
+                                              GoalType goalType,
+                                              OptimizationData... optData) {
+        // Scan "optData" for the input specific to this optimizer.
+        parseOptimizationData(optData);
+
+        // The parent's method will retrieve the common parameters from
+        // "optData" and call "doOptimize".
+        return super.optimizeInternal(maxEval, f, goalType, optData);
+    }
+
+    /**
+     * Scans the list of (required and optional) optimization data that
+     * characterize the problem.
+     *
+     * @param optData Optimization data. The following data will be looked for:
+     * <ul>
+     *  <li>{@link AbstractSimplex}</li>
+     * </ul>
+     */
+    private void parseOptimizationData(OptimizationData... optData) {
+        // The existing values (as set by the previous call) are reused if
+        // not provided in the argument list.
+        for (OptimizationData data : optData) {
+            if (data instanceof AbstractSimplex) {
+                simplex = (AbstractSimplex) data;
+                continue;
+            }
+        }
     }
 
     /** {@inheritDoc} */



Mime
View raw message