- public double computeValue(Simulation simulation) throws OptimizationException, InterruptedException {
- try {
- log.debug("Running simulation to evaluate apogee altitude");
- simulation.simulate(new ApogeeEndListener(), new InterruptListener());
- log.debug("Maximum altitude was " + simulation.getSimulatedData().getBranch(0).getMaximum(FlightDataType.TYPE_ALTITUDE));
- return simulation.getSimulatedData().getBranch(0).getMaximum(FlightDataType.TYPE_ALTITUDE);
- } catch (MotorIgnitionException e) {
- // A problem with motor ignition will cause optimization to fail
- throw new OptimizationException(e);
- } catch (SimulationLaunchException e) {
- // Other launch exceptions result in zero altitude
- return 0.0;
- } catch (SimulationCancelledException e) {
- throw (InterruptedException) new InterruptedException("Optimization was interrupted").initCause(e);
- } catch (SimulationException e) {
- // Other exceptions fail
- throw new OptimizationException(e);
- }
+ protected SimulationListener[] getSimulationListeners() {
+ return new SimulationListener[] { new ApogeeEndListener() };
+ }
+
+ @Override
+ protected double getResultValue(FlightData simulatedData) {
+ return simulatedData.getBranch(0).getMaximum(FlightDataType.TYPE_ALTITUDE);