1 package net.sf.openrocket.optimization.general;
3 import java.util.ArrayList;
4 import java.util.Collection;
8 * An OptimizationController that delegates control actions to multiple other controllers.
9 * The optimization is stopped if any of the controllers stops it.
11 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13 public class OptimizationControllerDelegator implements OptimizationController {
15 private final List<OptimizationController> controllers = new ArrayList<OptimizationController>();
18 * Construct the controlled based on an array of controllers.
20 * @param controllers the controllers to use.
22 public OptimizationControllerDelegator(OptimizationController... controllers) {
23 for (OptimizationController c : controllers) {
24 this.controllers.add(c);
29 * Construct the controller based on a collection of controllers.
31 * @param controllers the controllers to use.
33 public OptimizationControllerDelegator(Collection<OptimizationController> controllers) {
34 this.controllers.addAll(controllers);
39 * Control whether to continue optimization. This method returns false if any of the
40 * used controllers returns false. However, all controllers will be called even if
41 * an earlier one stops the optimization.
44 public boolean stepTaken(Point oldPoint, double oldValue, Point newPoint, double newValue, double stepSize) {
47 for (OptimizationController c : controllers) {
48 if (!c.stepTaken(oldPoint, oldValue, newPoint, newValue, stepSize)) {