+
+ /**
+ * Add a listener to this function. The listener will be notified each time the
+ * function is successfully evaluated.
+ * <p>
+ * Note that the listener may be called from other threads and must be thread-safe!
+ *
+ * @param listener the listener to add.
+ */
+ public void addRocketOptimizationListener(RocketOptimizationListener listener) {
+ listeners.add(listener);
+ }
+
+ public void removeRocketOptimizationListener(RocketOptimizationListener listener) {
+ listeners.remove(listener);
+ }
+
+
+
+ private void fireEvent(Simulation simulation, Point p, double domainReference, double parameterValue, double goalValue)
+ throws OptimizationException {
+
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+
+ Value[] values = new Value[p.dim()];
+ for (int i = 0; i < values.length; i++) {
+ double value = modifiers[i].getCurrentSIValue(simulation);
+ UnitGroup unit = modifiers[i].getUnitGroup();
+ values[i] = new Value(value, unit.getDefaultUnit());
+ }
+
+ for (RocketOptimizationListener l : listeners) {
+ l.evaluated(p, values, domainReference, parameterValue, goalValue);
+ }
+ }