2222import org .apache .commons .math3 .util .Incrementor ;
2323
2424/**
25- * Base class for implementing optimizers . It contains the boiler-plate code for counting
26- * the number of evaluations of the objective function and the number of iterations of the
27- * algorithm, and storing the convergence checker.
25+ * Base class for implementing optimization problems . It contains the boiler-plate code
26+ * for counting the number of evaluations of the objective function and the number of
27+ * iterations of the algorithm, and storing the convergence checker.
2828 *
29- * @param <PAIR> Type of the point/value pair returned by the optimization algorithm.
30- * @param <OPTIM> Type of a subclass of this class. This parameter allows to implement
31- * fluent API methods at upper levels of the class hierarchy (since the
32- * fluent API requires that the actual type of the subclass is returned).
29+ * @param <PAIR> Type of the point/value pair returned by the optimization algorithm.
3330 * @version $Id$
3431 * @since 3.3
3532 */
3633public abstract class AbstractOptimizationProblem <PAIR >
3734 implements OptimizationProblem <PAIR > {
3835
36+ /** Callback to use for the evaluation counter. */
37+ private static final MaxEvalCallback MAX_EVAL_CALLBACK = new MaxEvalCallback ();
38+ /** Callback to use for the iteration counter. */
39+ private static final MaxIterCallback MAX_ITER_CALLBACK = new MaxIterCallback ();
40+
3941 /** max evaluations */
4042 private final int maxEvaluations ;
4143 /** max iterations */
4244 private final int maxIterations ;
4345 /** Convergence checker. */
44- private ConvergenceChecker <PAIR > checker = null ;
46+ private final ConvergenceChecker <PAIR > checker ;
4547
48+ /**
49+ * Create an {@link AbstractOptimizationProblem} from the given data.
50+ *
51+ * @param maxEvaluations the number of allowed model function evaluations.
52+ * @param maxIterations the number of allowed iterations.
53+ * @param checker the convergence checker.
54+ */
55+ protected AbstractOptimizationProblem (final int maxEvaluations ,
56+ final int maxIterations ,
57+ final ConvergenceChecker <PAIR > checker ) {
58+ this .maxEvaluations = maxEvaluations ;
59+ this .maxIterations = maxIterations ;
60+ this .checker = checker ;
61+ }
4662
63+ /** {@inheritDoc} */
4764 public Incrementor getEvaluationCounter () {
4865 return new Incrementor (this .maxEvaluations , MAX_EVAL_CALLBACK );
4966 }
5067
68+ /** {@inheritDoc} */
5169 public Incrementor getIterationCounter () {
5270 return new Incrementor (this .maxIterations , MAX_ITER_CALLBACK );
5371 }
5472
55- protected AbstractOptimizationProblem (final int maxEvaluations ,
56- final int maxIterations ,
57- final ConvergenceChecker <PAIR > checker ) {
58- this .maxEvaluations = maxEvaluations ;
59- this .maxIterations = maxIterations ;
60- this .checker = checker ;
61- }
62-
73+ /** {@inheritDoc} */
6374 public ConvergenceChecker <PAIR > getConvergenceChecker () {
6475 return checker ;
6576 }
@@ -77,8 +88,6 @@ public void trigger(int max) {
7788 }
7889 }
7990
80- private static final MaxEvalCallback MAX_EVAL_CALLBACK = new MaxEvalCallback ();
81-
8291 /** Defines the action to perform when reaching the maximum number of evaluations. */
8392 private static class MaxIterCallback
8493 implements Incrementor .MaxCountExceededCallback {
@@ -92,5 +101,4 @@ public void trigger(int max) {
92101 }
93102 }
94103
95- private static final MaxIterCallback MAX_ITER_CALLBACK = new MaxIterCallback ();
96104}
0 commit comments