Merge pull request #709 from teyrana/fix/optimizer
[fixes #701] Re-enables Rocket Optimizer
This commit is contained in:
commit
9ca6b0be1a
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
# The OpenRocket build version
|
# The OpenRocket build version
|
||||||
build.version=20-08-alpha-14
|
build.version=20-08-alpha-15
|
||||||
|
|
||||||
|
|
||||||
# The source of the package. When building a package for a specific
|
# The source of the package. When building a package for a specific
|
||||||
|
@ -164,7 +164,12 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FlightConfiguration getActiveConfiguration() {
|
||||||
|
mutex.verify();
|
||||||
|
return rocket.getFlightConfiguration(this.configId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the rocket associated with this simulation.
|
* Return the rocket associated with this simulation.
|
||||||
*
|
*
|
||||||
@ -185,7 +190,7 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Set the motor configuration ID. If this id does not yet exist, it will be created.
|
* Set the motor configuration ID. If this id does not yet exist, it will be created.
|
||||||
*
|
*
|
||||||
* @param id the configuration to set.
|
* @param fcid the configuration to set.
|
||||||
*/
|
*/
|
||||||
public void setFlightConfigurationId(FlightConfigurationId fcid) {
|
public void setFlightConfigurationId(FlightConfigurationId fcid) {
|
||||||
if ( null == fcid ){
|
if ( null == fcid ){
|
||||||
@ -487,25 +492,29 @@ public class Simulation implements ChangeSource, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Create a duplicate of this simulation with the specified rocket. The new
|
* Create a duplicate of this simulation with the specified rocket. The new
|
||||||
* simulation is in non-simulated state.
|
* simulation is in non-simulated state.
|
||||||
|
* This methods performs
|
||||||
|
* synchronization on the simulation for thread protection.
|
||||||
|
* <p>
|
||||||
|
* Note: This method is package-private for unit testing purposes.
|
||||||
*
|
*
|
||||||
* @param newRocket the rocket for the new simulation.
|
* @param newRocket the rocket for the new simulation.
|
||||||
* @return a new simulation with the same conditions and properties.
|
* @return a new deep copy of the simulation and rocket with the same conditions and properties.
|
||||||
*/
|
*/
|
||||||
public Simulation duplicateSimulation(Rocket newRocket) {
|
public Simulation duplicateSimulation(Rocket newRocket) {
|
||||||
mutex.lock("duplicateSimulation");
|
mutex.lock("duplicateSimulation");
|
||||||
try {
|
try {
|
||||||
Simulation copy = new Simulation(newRocket);
|
final Simulation newSim = new Simulation(newRocket);
|
||||||
|
newSim.name = this.name;
|
||||||
copy.name = this.name;
|
newSim.configId = this.configId;
|
||||||
copy.options.copyFrom(this.options);
|
newSim.options.copyFrom(this.options);
|
||||||
copy.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
|
newSim.simulatedConfigurationDescription = this.simulatedConfigurationDescription;
|
||||||
for (SimulationExtension c : this.simulationExtensions) {
|
for (SimulationExtension c : this.simulationExtensions) {
|
||||||
copy.simulationExtensions.add(c.clone());
|
newSim.simulationExtensions.add(c.clone());
|
||||||
}
|
}
|
||||||
copy.simulationStepperClass = this.simulationStepperClass;
|
newSim.simulationStepperClass = this.simulationStepperClass;
|
||||||
copy.aerodynamicCalculatorClass = this.aerodynamicCalculatorClass;
|
newSim.aerodynamicCalculatorClass = this.aerodynamicCalculatorClass;
|
||||||
|
|
||||||
return copy;
|
return newSim;
|
||||||
} finally {
|
} finally {
|
||||||
mutex.unlock("duplicateSimulation");
|
mutex.unlock("duplicateSimulation");
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class RocketOptimizationFunction implements Function {
|
|||||||
private final SimulationModifier[] modifiers;
|
private final SimulationModifier[] modifiers;
|
||||||
|
|
||||||
|
|
||||||
private final List<RocketOptimizationListener> listeners = new ArrayList<RocketOptimizationListener>();
|
private final List<RocketOptimizationListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,12 +83,12 @@ public class RocketOptimizationFunction implements Function {
|
|||||||
modifiers.length + " simulation modifiers");
|
modifiers.length + " simulation modifiers");
|
||||||
}
|
}
|
||||||
|
|
||||||
Simulation simulation = newSimulationInstance(baseSimulation);
|
final Simulation simulation = newSimulationInstance(baseSimulation);
|
||||||
|
|
||||||
for (int i = 0; i < modifiers.length; i++) {
|
for (int i = 0; i < modifiers.length; i++) {
|
||||||
modifiers[i].modify(simulation, p[i]);
|
modifiers[i].modify(simulation, p[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Check whether the point is within the simulation domain
|
// Check whether the point is within the simulation domain
|
||||||
Pair<Double, Value> d = domain.getDistanceToDomain(simulation);
|
Pair<Double, Value> d = domain.getDistanceToDomain(simulation);
|
||||||
double distance = d.getU();
|
double distance = d.getU();
|
||||||
@ -106,7 +106,6 @@ public class RocketOptimizationFunction implements Function {
|
|||||||
return goalValue;
|
return goalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Compute the optimization value
|
// Compute the optimization value
|
||||||
parameterValue = parameter.computeValue(simulation);
|
parameterValue = parameter.computeValue(simulation);
|
||||||
goalValue = goal.getMinimizationParameter(parameterValue);
|
goalValue = goal.getMinimizationParameter(parameterValue);
|
||||||
@ -118,35 +117,25 @@ public class RocketOptimizationFunction implements Function {
|
|||||||
goalValue = Double.MAX_VALUE;
|
goalValue = Double.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.trace("Parameter value at point " + point + " is " + parameterValue + ", goal function value=" + goalValue);
|
fireEvent( simulation, point, referenceValue,
|
||||||
|
new Value(parameterValue, parameter.getUnitGroup().getDefaultUnit()),
|
||||||
fireEvent(simulation, point, referenceValue, new Value(parameterValue, parameter.getUnitGroup().getDefaultUnit()),
|
goalValue);
|
||||||
goalValue);
|
|
||||||
|
|
||||||
return goalValue;
|
return goalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a new deep copy of the simulation and rocket. This methods performs
|
* Returns a new deep copy of the simulation and rocket.
|
||||||
* synchronization on the simulation for thread protection.
|
|
||||||
* <p>
|
* <p>
|
||||||
* Note: This method is package-private for unit testing purposes.
|
* Note: This method is package-private for unit testing purposes.
|
||||||
*
|
*
|
||||||
* @return a new deep copy of the simulation and rocket
|
* @return a new deep copy of the simulation and rocket
|
||||||
*/
|
*/
|
||||||
Simulation newSimulationInstance(Simulation simulation) {
|
Simulation newSimulationInstance(Simulation simulation) {
|
||||||
synchronized (baseSimulation) {
|
return simulation.duplicateSimulation(simulation.getRocket().copyWithOriginalID());
|
||||||
Rocket newRocket = simulation.getRocket().copyWithOriginalID();
|
|
||||||
Simulation newSimulation = simulation.duplicateSimulation(newRocket);
|
|
||||||
return newSimulation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a listener to this function. The listener will be notified each time the
|
* Add a listener to this function. The listener will be notified each time the
|
||||||
* function is successfully evaluated.
|
* function is successfully evaluated.
|
||||||
|
@ -63,7 +63,7 @@ public class StabilityDomain implements SimulationDomain {
|
|||||||
*/
|
*/
|
||||||
AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
||||||
|
|
||||||
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration();
|
FlightConfiguration configuration = simulation.getActiveConfiguration();
|
||||||
FlightConditions conditions = new FlightConditions(configuration);
|
FlightConditions conditions = new FlightConditions(configuration);
|
||||||
conditions.setMach(Application.getPreferences().getDefaultMach());
|
conditions.setMach(Application.getPreferences().getDefaultMach());
|
||||||
conditions.setAOA(0);
|
conditions.setAOA(0);
|
||||||
|
@ -70,8 +70,8 @@ public class FlightConfigurationModifier<E extends FlightConfigurableParameter<E
|
|||||||
+ " with correct ID");
|
+ " with correct ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
FlightConfigurableParameterSet<E> configs = (FlightConfigurableParameterSet<E>) configGetter.invoke(c);
|
FlightConfigurableParameterSet<E> configSet = (FlightConfigurableParameterSet<E>) configGetter.invoke(c);
|
||||||
return configs.get(simulation.getRocket().getSelectedConfiguration().getFlightConfigurationID());
|
return configSet.get(simulation.getFlightConfigurationId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ public class GenericComponentModifier extends GenericModifier<RocketComponent> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RocketComponent getModifiedObject(Simulation simulation) throws OptimizationException {
|
protected RocketComponent getModifiedObject(Simulation simulation) throws OptimizationException {
|
||||||
RocketComponent c = simulation.getRocket().findComponent(componentId);
|
final RocketComponent c = simulation.getRocket().findComponent(componentId);
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
throw new OptimizationException("Could not find component of type " + componentClass.getSimpleName()
|
throw new OptimizationException("Could not find component of type " + componentClass.getSimpleName()
|
||||||
+ " with correct ID");
|
+ " with correct ID");
|
||||||
|
@ -44,57 +44,47 @@ public class StabilityParameter implements OptimizableParameter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double computeValue(Simulation simulation) throws OptimizationException {
|
public double computeValue(Simulation simulation) throws OptimizationException {
|
||||||
Coordinate cp, cg;
|
|
||||||
double cpx, cgx;
|
|
||||||
double stability;
|
|
||||||
|
|
||||||
log.debug("Calculating stability of simulation, absolute=" + absolute);
|
log.debug("Calculating stability of simulation, absolute=" + absolute);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These are instantiated each time because this class must be thread-safe.
|
* These are instantiated each time because this class must be thread-safe.
|
||||||
* Caching would in any case be inefficient since the rocket changes all the time.
|
* Caching would in any case be inefficient since the rocket changes all the time.
|
||||||
*/
|
*/
|
||||||
AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
final AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();
|
||||||
|
final FlightConfiguration configuration = simulation.getActiveConfiguration();
|
||||||
FlightConfiguration configuration = simulation.getRocket().getSelectedConfiguration();
|
final FlightConditions conditions = new FlightConditions(configuration);
|
||||||
FlightConditions conditions = new FlightConditions(configuration);
|
|
||||||
conditions.setMach(Application.getPreferences().getDefaultMach());
|
conditions.setMach(Application.getPreferences().getDefaultMach());
|
||||||
conditions.setAOA(0);
|
conditions.setAOA(0);
|
||||||
conditions.setRollRate(0);
|
conditions.setRollRate(0);
|
||||||
|
|
||||||
cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null);
|
final Coordinate cp = aerodynamicCalculator.getWorstCP(configuration, conditions, null);
|
||||||
// worst case CM is also
|
// the launch CM is the worst case CM
|
||||||
cg = MassCalculator.calculateLaunch(configuration).getCM();
|
final Coordinate cg = MassCalculator.calculateLaunch(configuration).getCM();
|
||||||
|
|
||||||
|
double cpx = Double.NaN;
|
||||||
if (cp.weight > 0.000001)
|
if (cp.weight > 0.000001)
|
||||||
cpx = cp.x;
|
cpx = cp.x;
|
||||||
else
|
|
||||||
cpx = Double.NaN;
|
double cgx = Double.NaN;
|
||||||
|
|
||||||
if (cg.weight > 0.000001)
|
if (cg.weight > 0.000001)
|
||||||
cgx = cg.x;
|
cgx = cg.x;
|
||||||
else
|
|
||||||
cgx = Double.NaN;
|
|
||||||
|
|
||||||
|
|
||||||
// Calculate the reference (absolute or relative)
|
// Calculate the reference (absolute or relative)
|
||||||
stability = cpx - cgx;
|
final double stability_absolute = cpx - cgx;
|
||||||
|
|
||||||
if (!absolute) {
|
if (absolute) {
|
||||||
|
return stability_absolute;
|
||||||
|
} else {
|
||||||
double diameter = 0;
|
double diameter = 0;
|
||||||
for (RocketComponent c : configuration.getActiveComponents()) {
|
for (RocketComponent c : configuration.getActiveInstances().keySet()) {
|
||||||
if (c instanceof SymmetricComponent) {
|
if (c instanceof SymmetricComponent) {
|
||||||
double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
final double d1 = ((SymmetricComponent) c).getForeRadius() * 2;
|
||||||
double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
final double d2 = ((SymmetricComponent) c).getAftRadius() * 2;
|
||||||
diameter = MathUtil.max(diameter, d1, d2);
|
diameter = MathUtil.max(diameter, d1, d2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stability = stability / diameter;
|
return stability_absolute / diameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Resulting stability is " + stability + ", absolute=" + absolute);
|
|
||||||
|
|
||||||
return stability;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -215,7 +215,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
trans.get("optimization.modifier.internalcomponent.position"),
|
trans.get("optimization.modifier.internalcomponent.position"),
|
||||||
trans.get("optimization.modifier.internalcomponent.position.desc"),
|
trans.get("optimization.modifier.internalcomponent.position.desc"),
|
||||||
c, UnitGroup.UNITS_LENGTH,
|
c, UnitGroup.UNITS_LENGTH,
|
||||||
1.0, c.getClass(), c.getID(), "AxialMethod");
|
1.0, c.getClass(), c.getID(), "AxialOffset");
|
||||||
mod.setMinValue(0);
|
mod.setMinValue(0);
|
||||||
mod.setMaxValue(parent.getLength());
|
mod.setMaxValue(parent.getLength());
|
||||||
modifiers.add(mod);
|
modifiers.add(mod);
|
||||||
@ -229,7 +229,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
trans.get("optimization.modifier.finset.position"),
|
trans.get("optimization.modifier.finset.position"),
|
||||||
trans.get("optimization.modifier.finset.position.desc"),
|
trans.get("optimization.modifier.finset.position.desc"),
|
||||||
c, UnitGroup.UNITS_LENGTH,
|
c, UnitGroup.UNITS_LENGTH,
|
||||||
1.0, c.getClass(), c.getID(), "AxialMethod");
|
1.0, c.getClass(), c.getID(), "AxialOffset");
|
||||||
mod.setMinValue(0);
|
mod.setMinValue(0);
|
||||||
mod.setMaxValue(parent.getLength());
|
mod.setMaxValue(parent.getLength());
|
||||||
modifiers.add(mod);
|
modifiers.add(mod);
|
||||||
@ -243,7 +243,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
trans.get("optimization.modifier.launchlug.position"),
|
trans.get("optimization.modifier.launchlug.position"),
|
||||||
trans.get("optimization.modifier.launchlug.position.desc"),
|
trans.get("optimization.modifier.launchlug.position.desc"),
|
||||||
c, UnitGroup.UNITS_LENGTH,
|
c, UnitGroup.UNITS_LENGTH,
|
||||||
1.0, c.getClass(), c.getID(), "AxialMethod");
|
1.0, c.getClass(), c.getID(), "AxialOffset");
|
||||||
mod.setMinValue(0);
|
mod.setMinValue(0);
|
||||||
mod.setMaxValue(parent.getLength());
|
mod.setMaxValue(parent.getLength());
|
||||||
modifiers.add(mod);
|
modifiers.add(mod);
|
||||||
@ -260,7 +260,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
1.0,
|
1.0,
|
||||||
c.getClass(),
|
c.getClass(),
|
||||||
c.getID(),
|
c.getID(),
|
||||||
"DeploymentConfiguration",
|
"DeploymentConfigurations",
|
||||||
DeploymentConfiguration.class,
|
DeploymentConfiguration.class,
|
||||||
"DeployDelay");
|
"DeployDelay");
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ public class DefaultSimulationModifierService implements SimulationModifierServi
|
|||||||
1.0,
|
1.0,
|
||||||
c.getClass(),
|
c.getClass(),
|
||||||
c.getID(),
|
c.getID(),
|
||||||
"DeploymentConfiguration",
|
"DeploymentConfigurations",
|
||||||
DeploymentConfiguration.class,
|
DeploymentConfiguration.class,
|
||||||
"DeployAltitude") {
|
"DeployAltitude") {
|
||||||
|
|
||||||
|
@ -71,7 +71,16 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
private double cachedRefLength = -1;
|
private double cachedRefLength = -1;
|
||||||
|
|
||||||
private int modID = 0;
|
private int modID = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a Default configuration with the specified <code>Rocket</code>.
|
||||||
|
*
|
||||||
|
* @param rocket the rocket
|
||||||
|
*/
|
||||||
|
public FlightConfiguration(final Rocket rocket) {
|
||||||
|
this(rocket, FlightConfigurationId.DEFAULT_VALUE_FCID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new configuration with the specified <code>Rocket</code>.
|
* Create a new configuration with the specified <code>Rocket</code>.
|
||||||
*
|
*
|
||||||
|
@ -84,7 +84,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
|
|||||||
clearPreset();
|
clearPreset();
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FlightConfigurableParameterSet<DeploymentConfiguration> getDeploymentConfigurations() {
|
public FlightConfigurableParameterSet<DeploymentConfiguration> getDeploymentConfigurations() {
|
||||||
return deploymentConfigurations;
|
return deploymentConfigurations;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class Rocket extends ComponentAssembly {
|
|||||||
functionalModID = modID;
|
functionalModID = modID;
|
||||||
|
|
||||||
// must be after the hashmaps :P
|
// must be after the hashmaps :P
|
||||||
FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID);
|
final FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID);
|
||||||
configSet = new FlightConfigurableParameterSet<>( defaultConfig );
|
configSet = new FlightConfigurableParameterSet<>( defaultConfig );
|
||||||
this.selectedConfiguration = defaultConfig;
|
this.selectedConfiguration = defaultConfig;
|
||||||
}
|
}
|
||||||
@ -330,15 +330,26 @@ public class Rocket extends ComponentAssembly {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Rocket copyWithOriginalID() {
|
public Rocket copyWithOriginalID() {
|
||||||
Rocket copy = (Rocket) super.copyWithOriginalID();
|
final Rocket copyRocket = (Rocket) super.copyWithOriginalID();
|
||||||
|
|
||||||
// Rocket copy is cloned, so non-trivial members must be cloned as well:
|
// Rocket copy is cloned, so non-trivial members must be cloned as well:
|
||||||
copy.stageMap = new HashMap<Integer, AxialStage>();
|
copyRocket.stageMap = new HashMap<>();
|
||||||
copy.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( this.configSet );
|
for( Map.Entry<Integer,AxialStage> entry : this.stageMap.entrySet()){
|
||||||
copy.selectedConfiguration = copy.configSet.get( this.getSelectedConfiguration().getId());
|
final AxialStage stage = (AxialStage)copyRocket.findComponent(entry.getValue().getID());
|
||||||
copy.listenerList = new HashSet<EventListener>();
|
copyRocket.stageMap.put(entry.getKey(), stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// these flight configurations need to reference the _new_ Rocket copy
|
||||||
|
// the default value needs to be explicitly set, because it has different semantics
|
||||||
|
copyRocket.configSet = new FlightConfigurableParameterSet<>(new FlightConfiguration(copyRocket));
|
||||||
|
for (FlightConfigurationId key : this.configSet.getIds()) {
|
||||||
|
copyRocket.configSet.set(key, new FlightConfiguration(copyRocket, key));
|
||||||
|
}
|
||||||
|
|
||||||
|
copyRocket.selectedConfiguration = copyRocket.configSet.get( this.getSelectedConfiguration().getId());
|
||||||
|
copyRocket.listenerList = new HashSet<>();
|
||||||
|
|
||||||
return copy;
|
return copyRocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFlightConfigurationCount() {
|
public int getFlightConfigurationCount() {
|
||||||
@ -376,8 +387,13 @@ public class Rocket extends ComponentAssembly {
|
|||||||
this.functionalModID = r.functionalModID;
|
this.functionalModID = r.functionalModID;
|
||||||
this.refType = r.refType;
|
this.refType = r.refType;
|
||||||
this.customReferenceLength = r.customReferenceLength;
|
this.customReferenceLength = r.customReferenceLength;
|
||||||
this.configSet = new FlightConfigurableParameterSet<FlightConfiguration>( r.configSet );
|
|
||||||
|
// these flight configurations need to reference the _this_ Rocket:
|
||||||
|
this.configSet.setDefault(new FlightConfiguration(this));
|
||||||
|
for (FlightConfigurationId key : r.configSet.map.keySet()) {
|
||||||
|
this.configSet.set(key, new FlightConfiguration(this, key));
|
||||||
|
}
|
||||||
|
|
||||||
this.perfectFinish = r.perfectFinish;
|
this.perfectFinish = r.perfectFinish;
|
||||||
|
|
||||||
this.checkComponentStructure();
|
this.checkComponentStructure();
|
||||||
|
@ -1627,7 +1627,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
checkState();
|
checkState();
|
||||||
Iterator<RocketComponent> iter = this.iterator(true);
|
Iterator<RocketComponent> iter = this.iterator(true);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
RocketComponent c = iter.next();
|
final RocketComponent c = iter.next();
|
||||||
if (c.getID().equals(idToFind))
|
if (c.getID().equals(idToFind))
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,7 @@ import javax.swing.JToggleButton;
|
|||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.Timer;
|
import javax.swing.Timer;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
import javax.swing.event.ChangeEvent;
|
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
import javax.swing.event.ListSelectionEvent;
|
|
||||||
import javax.swing.event.ListSelectionListener;
|
|
||||||
import javax.swing.event.TreeSelectionEvent;
|
import javax.swing.event.TreeSelectionEvent;
|
||||||
import javax.swing.event.TreeSelectionListener;
|
import javax.swing.event.TreeSelectionListener;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
@ -51,6 +48,9 @@ import javax.swing.table.TableColumnModel;
|
|||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
|
import net.sf.openrocket.optimization.rocketoptimization.modifiers.GenericComponentModifier;
|
||||||
|
import net.sf.openrocket.rocketcomponent.FinSet;
|
||||||
|
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -118,12 +118,11 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private static final String START_TEXT = trans.get("btn.start");
|
private static final String START_TEXT = trans.get("btn.start");
|
||||||
private static final String STOP_TEXT = trans.get("btn.stop");
|
private static final String STOP_TEXT = trans.get("btn.stop");
|
||||||
|
|
||||||
private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
private final RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class);
|
||||||
|
|
||||||
|
|
||||||
private final List<OptimizableParameter> optimizationParameters = new ArrayList<OptimizableParameter>();
|
private final List<OptimizableParameter> optimizationParameters = new ArrayList<>();
|
||||||
private final Map<Object, List<SimulationModifier>> simulationModifiers =
|
private final Map<Object, List<SimulationModifier>> simulationModifiers = new HashMap<>();
|
||||||
new HashMap<Object, List<SimulationModifier>>();
|
|
||||||
|
|
||||||
|
|
||||||
private final OpenRocketDocument baseDocument;
|
private final OpenRocketDocument baseDocument;
|
||||||
@ -138,7 +137,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final DescriptionArea selectedModifierDescription;
|
private final DescriptionArea selectedModifierDescription;
|
||||||
private final SimulationModifierTree availableModifierTree;
|
private final SimulationModifierTree availableModifierTree;
|
||||||
|
|
||||||
private final JComboBox<String> simulationSelectionCombo;
|
private final JComboBox<Named<Simulation>> simulationSelectionCombo;
|
||||||
private final JComboBox<Named<OptimizableParameter>> optimizationParameterCombo;
|
private final JComboBox<Named<OptimizableParameter>> optimizationParameterCombo;
|
||||||
|
|
||||||
private final JComboBox<?> optimizationGoalCombo;
|
private final JComboBox<?> optimizationGoalCombo;
|
||||||
@ -146,8 +145,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final UnitSelector optimizationGoalUnitSelector;
|
private final UnitSelector optimizationGoalUnitSelector;
|
||||||
private final DoubleModel optimizationSeekValue;
|
private final DoubleModel optimizationSeekValue;
|
||||||
|
|
||||||
private DoubleModel minimumStability;
|
private final DoubleModel minimumStability;
|
||||||
private DoubleModel maximumStability;
|
private final DoubleModel maximumStability;
|
||||||
private final JCheckBox minimumStabilitySelected;
|
private final JCheckBox minimumStabilitySelected;
|
||||||
private final JSpinner minimumStabilitySpinner;
|
private final JSpinner minimumStabilitySpinner;
|
||||||
private final UnitSelector minimumStabilityUnitSelector;
|
private final UnitSelector minimumStabilityUnitSelector;
|
||||||
@ -165,14 +164,10 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final JButton plotButton;
|
private final JButton plotButton;
|
||||||
private final JButton saveButton;
|
private final JButton saveButton;
|
||||||
|
|
||||||
private final JButton applyButton;
|
private final List<SimulationModifier> selectedModifiers = new ArrayList<>();
|
||||||
private final JButton resetButton;
|
|
||||||
private final JButton closeButton;
|
|
||||||
|
|
||||||
private final List<SimulationModifier> selectedModifiers = new ArrayList<SimulationModifier>();
|
|
||||||
|
|
||||||
/** List of components to disable while optimization is running */
|
/** List of components to disable while optimization is running */
|
||||||
private final List<JComponent> disableComponents = new ArrayList<JComponent>();
|
private final List<JComponent> disableComponents = new ArrayList<>();
|
||||||
|
|
||||||
/** Whether optimization is currently running or not */
|
/** Whether optimization is currently running or not */
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
@ -185,8 +180,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private int evaluationCount = 0;
|
private int evaluationCount = 0;
|
||||||
private double stepSize = 0;
|
private double stepSize = 0;
|
||||||
|
|
||||||
private final Map<Point, FunctionEvaluationData> evaluationHistory = new LinkedHashMap<Point, FunctionEvaluationData>();
|
private final Map<Point, FunctionEvaluationData> evaluationHistory = new LinkedHashMap<>();
|
||||||
private final List<Point> optimizationPath = new LinkedList<Point>();
|
private final List<Point> optimizationPath = new LinkedList<>();
|
||||||
|
|
||||||
private boolean updating = false;
|
private boolean updating = false;
|
||||||
|
|
||||||
@ -212,21 +207,10 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
ChangeListener clearHistoryChangeListener = new ChangeListener() {
|
ChangeListener clearHistoryChangeListener = e -> clearHistory();
|
||||||
@Override
|
ActionListener clearHistoryActionListener = e -> clearHistory();
|
||||||
public void stateChanged(ChangeEvent e) {
|
|
||||||
clearHistory();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
ActionListener clearHistoryActionListener = new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
clearHistory();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// // Selected modifiers table
|
// // Selected modifiers table
|
||||||
|
|
||||||
selectedModifierTableModel = new ParameterSelectionTableModel();
|
selectedModifierTableModel = new ParameterSelectionTableModel();
|
||||||
selectedModifierTable = new JTable(selectedModifierTableModel);
|
selectedModifierTable = new JTable(selectedModifierTableModel);
|
||||||
selectedModifierTable.setDefaultRenderer(Double.class, new DoubleCellRenderer());
|
selectedModifierTable.setDefaultRenderer(Double.class, new DoubleCellRenderer());
|
||||||
@ -249,15 +233,11 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
return selectedModifiers.get(row).getUnitGroup();
|
return selectedModifiers.get(row).getUnitGroup();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
selectedModifierTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
||||||
|
|
||||||
disableComponents.add(selectedModifierTable);
|
disableComponents.add(selectedModifierTable);
|
||||||
|
|
||||||
selectedModifierTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
|
selectedModifierTable.getSelectionModel().addListSelectionListener(e -> updateComponents());
|
||||||
@Override
|
|
||||||
public void valueChanged(ListSelectionEvent e) {
|
|
||||||
updateComponents();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set column widths
|
// Set column widths
|
||||||
TableColumnModel columnModel = selectedModifierTable.getColumnModel();
|
TableColumnModel columnModel = selectedModifierTable.getColumnModel();
|
||||||
@ -281,16 +261,16 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
addButton = new JButton(Chars.LEFT_ARROW + " " + trans.get("btn.add") + " ");
|
addButton = new JButton(Chars.LEFT_ARROW + " " + trans.get("btn.add") + " ");
|
||||||
addButton.setToolTipText(trans.get("btn.add.ttip"));
|
addButton.setToolTipText(trans.get("btn.add.ttip"));
|
||||||
addButton.addActionListener(new ActionListener() {
|
addButton.addActionListener(e -> {
|
||||||
@Override
|
SimulationModifier mod = getSelectedAvailableModifier();
|
||||||
public void actionPerformed(ActionEvent e) {
|
if (mod != null) {
|
||||||
SimulationModifier mod = getSelectedAvailableModifier();
|
addModifier(mod);
|
||||||
if (mod != null) {
|
clearHistory();
|
||||||
addModifier(mod);
|
} else {
|
||||||
clearHistory();
|
log.error("Attempting to add simulation modifier when none is selected");
|
||||||
} else {
|
}
|
||||||
log.error("Attempting to add simulation modifier when none is selected");
|
if (selectedModifierTable.isEditing()) {
|
||||||
}
|
selectedModifierTable.getCellEditor().stopCellEditing();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
disableComponents.add(addButton);
|
disableComponents.add(addButton);
|
||||||
@ -298,17 +278,19 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
removeButton = new JButton(" " + trans.get("btn.remove") + " " + Chars.RIGHT_ARROW);
|
removeButton = new JButton(" " + trans.get("btn.remove") + " " + Chars.RIGHT_ARROW);
|
||||||
removeButton.setToolTipText(trans.get("btn.remove.ttip"));
|
removeButton.setToolTipText(trans.get("btn.remove.ttip"));
|
||||||
removeButton.addActionListener(new ActionListener() {
|
removeButton.addActionListener(e -> {
|
||||||
@Override
|
SimulationModifier mod = getSelectedModifier();
|
||||||
public void actionPerformed(ActionEvent e) {
|
if (mod == null) {
|
||||||
SimulationModifier mod = getSelectedModifier();
|
log.error("Attempting to remove simulation modifier when none is selected");
|
||||||
if (mod == null) {
|
return;
|
||||||
log.error("Attempting to remove simulation modifier when none is selected");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
removeModifier(mod);
|
|
||||||
clearHistory();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selectedModifierTable.isEditing()) {
|
||||||
|
selectedModifierTable.getCellEditor().stopCellEditing();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeModifier(mod);
|
||||||
|
clearHistory();
|
||||||
});
|
});
|
||||||
disableComponents.add(removeButton);
|
disableComponents.add(removeButton);
|
||||||
sub.add(removeButton, "wrap para*2, sg button");
|
sub.add(removeButton, "wrap para*2, sg button");
|
||||||
@ -378,7 +360,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
simulationSelectionCombo = new JComboBox<String>();
|
simulationSelectionCombo = new JComboBox<>();
|
||||||
simulationSelectionCombo.setToolTipText(tip);
|
simulationSelectionCombo.setToolTipText(tip);
|
||||||
populateSimulations();
|
populateSimulations();
|
||||||
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
||||||
@ -392,7 +374,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
optimizationParameterCombo = new JComboBox<Named<OptimizableParameter>>();
|
optimizationParameterCombo = new JComboBox<>();
|
||||||
optimizationParameterCombo.setToolTipText(tip);
|
optimizationParameterCombo.setToolTipText(tip);
|
||||||
populateParameters();
|
populateParameters();
|
||||||
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
||||||
@ -406,7 +388,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
optimizationGoalCombo = new JComboBox<String>(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK });
|
optimizationGoalCombo = new JComboBox<>(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK });
|
||||||
optimizationGoalCombo.setToolTipText(tip);
|
optimizationGoalCombo.setToolTipText(tip);
|
||||||
optimizationGoalCombo.setEditable(false);
|
optimizationGoalCombo.setEditable(false);
|
||||||
optimizationGoalCombo.addActionListener(clearHistoryActionListener);
|
optimizationGoalCombo.addActionListener(clearHistoryActionListener);
|
||||||
@ -450,12 +432,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
minimumStabilitySelected = new JCheckBox(trans.get("lbl.requireMinStability"));
|
minimumStabilitySelected = new JCheckBox(trans.get("lbl.requireMinStability"));
|
||||||
minimumStabilitySelected.setSelected(true);
|
minimumStabilitySelected.setSelected(true);
|
||||||
minimumStabilitySelected.setToolTipText(tip);
|
minimumStabilitySelected.setToolTipText(tip);
|
||||||
minimumStabilitySelected.addActionListener(new ActionListener() {
|
minimumStabilitySelected.addActionListener(e -> updateComponents());
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
updateComponents();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
disableComponents.add(minimumStabilitySelected);
|
disableComponents.add(minimumStabilitySelected);
|
||||||
sub.add(minimumStabilitySelected);
|
sub.add(minimumStabilitySelected);
|
||||||
|
|
||||||
@ -551,51 +528,42 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
// // Start/Stop button
|
// // Start/Stop button
|
||||||
|
|
||||||
startButton = new JToggleButton(START_TEXT);
|
startButton = new JToggleButton(START_TEXT);
|
||||||
startButton.addActionListener(new ActionListener() {
|
startButton.addActionListener(e -> {
|
||||||
@Override
|
if (updating) {
|
||||||
public void actionPerformed(ActionEvent e) {
|
log.debug("Updating, ignoring event");
|
||||||
if (updating) {
|
return;
|
||||||
log.debug("Updating, ignoring event");
|
}
|
||||||
return;
|
if (running) {
|
||||||
}
|
log.info(Markers.USER_MARKER, "Stopping optimization");
|
||||||
if (running) {
|
stopOptimization();
|
||||||
log.info(Markers.USER_MARKER, "Stopping optimization");
|
} else {
|
||||||
stopOptimization();
|
log.info(Markers.USER_MARKER, "Starting optimization");
|
||||||
} else {
|
startOptimization();
|
||||||
log.info(Markers.USER_MARKER, "Starting optimization");
|
|
||||||
startOptimization();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sub.add(startButton, "span, growx, wrap para*2");
|
sub.add(startButton, "span, growx, wrap para*2");
|
||||||
|
|
||||||
plotButton = new JButton(trans.get("btn.plotPath"));
|
plotButton = new JButton(trans.get("btn.plotPath"));
|
||||||
plotButton.setToolTipText(trans.get("btn.plotPath.ttip"));
|
plotButton.setToolTipText(trans.get("btn.plotPath.ttip"));
|
||||||
plotButton.addActionListener(new ActionListener() {
|
plotButton.addActionListener(e -> {
|
||||||
@Override
|
log.info(Markers.USER_MARKER, "Plotting optimization path, dimensionality=" + selectedModifiers.size());
|
||||||
public void actionPerformed(ActionEvent e) {
|
OptimizationPlotDialog dialog = new OptimizationPlotDialog(
|
||||||
log.info(Markers.USER_MARKER, "Plotting optimization path, dimensionality=" + selectedModifiers.size());
|
Collections.unmodifiableList(optimizationPath),
|
||||||
OptimizationPlotDialog dialog = new OptimizationPlotDialog(
|
Collections.unmodifiableMap(evaluationHistory),
|
||||||
Collections.unmodifiableList(optimizationPath),
|
Collections.unmodifiableList(selectedModifiers),
|
||||||
Collections.unmodifiableMap(evaluationHistory),
|
getSelectedParameter(),
|
||||||
Collections.unmodifiableList(selectedModifiers),
|
UnitGroup.stabilityUnits(getSelectedSimulation().getRocket()),
|
||||||
getSelectedParameter(),
|
GeneralOptimizationDialog.this);
|
||||||
UnitGroup.stabilityUnits(getSelectedSimulation().getRocket()),
|
dialog.setVisible(true);
|
||||||
GeneralOptimizationDialog.this);
|
|
||||||
dialog.setVisible(true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
disableComponents.add(plotButton);
|
disableComponents.add(plotButton);
|
||||||
sub.add(plotButton, "span, growx, wrap");
|
sub.add(plotButton, "span, growx, wrap");
|
||||||
|
|
||||||
saveButton = new JButton(trans.get("btn.save"));
|
saveButton = new JButton(trans.get("btn.save"));
|
||||||
saveButton.setToolTipText(trans.get("btn.save.ttip"));
|
saveButton.setToolTipText(trans.get("btn.save.ttip"));
|
||||||
saveButton.addActionListener(new ActionListener() {
|
saveButton.addActionListener(e -> {
|
||||||
@Override
|
log.info(Markers.USER_MARKER, "User selected save path");
|
||||||
public void actionPerformed(ActionEvent e) {
|
savePath();
|
||||||
log.info(Markers.USER_MARKER, "User selected save path");
|
|
||||||
savePath();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
disableComponents.add(saveButton);
|
disableComponents.add(saveButton);
|
||||||
sub.add(saveButton, "span, growx");
|
sub.add(saveButton, "span, growx");
|
||||||
@ -603,32 +571,25 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
panel.add(sub, "wrap para*2");
|
panel.add(sub, "wrap para*2");
|
||||||
|
|
||||||
// // Bottom buttons
|
// // Bottom buttons
|
||||||
|
final JButton applyButton = new JButton(trans.get("btn.apply"));
|
||||||
applyButton = new JButton(trans.get("btn.apply"));
|
|
||||||
applyButton.setToolTipText(trans.get("btn.apply.ttip"));
|
applyButton.setToolTipText(trans.get("btn.apply.ttip"));
|
||||||
applyButton.addActionListener(new ActionListener() {
|
applyButton.addActionListener(e -> {
|
||||||
@Override
|
log.info(Markers.USER_MARKER, "Applying optimization changes");
|
||||||
public void actionPerformed(ActionEvent e) {
|
applyDesign();
|
||||||
log.info(Markers.USER_MARKER, "Applying optimization changes");
|
|
||||||
applyDesign();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
disableComponents.add(applyButton);
|
disableComponents.add(applyButton);
|
||||||
panel.add(applyButton, "span, split, gapright para, right");
|
panel.add(applyButton, "span, split, gapright para, right");
|
||||||
|
|
||||||
resetButton = new JButton(trans.get("btn.reset"));
|
final JButton resetButton = new JButton(trans.get("btn.reset"));
|
||||||
resetButton.setToolTipText(trans.get("btn.reset.ttip"));
|
resetButton.setToolTipText(trans.get("btn.reset.ttip"));
|
||||||
resetButton.addActionListener(new ActionListener() {
|
resetButton.addActionListener(e -> {
|
||||||
@Override
|
log.info(Markers.USER_MARKER, "Resetting optimization design");
|
||||||
public void actionPerformed(ActionEvent e) {
|
resetDesign();
|
||||||
log.info(Markers.USER_MARKER, "Resetting optimization design");
|
|
||||||
resetDesign();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
disableComponents.add(resetButton);
|
disableComponents.add(resetButton);
|
||||||
panel.add(resetButton, "gapright para, right");
|
panel.add(resetButton, "gapright para, right");
|
||||||
|
|
||||||
closeButton = new JButton(trans.get("btn.close"));
|
final JButton closeButton = new JButton(trans.get("btn.close"));
|
||||||
closeButton.setToolTipText(trans.get("btn.close.ttip"));
|
closeButton.setToolTipText(trans.get("btn.close.ttip"));
|
||||||
closeButton.addActionListener(new ActionListener() {
|
closeButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -644,6 +605,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
clearHistory();
|
clearHistory();
|
||||||
updateComponents();
|
updateComponents();
|
||||||
GUIUtil.setDisposableDialogOptions(this, null);
|
GUIUtil.setDisposableDialogOptions(this, null);
|
||||||
|
|
||||||
|
// seem like a reasonable defaults
|
||||||
|
this.setSize(1200, 600);
|
||||||
|
// System.err.println("OptimizationDialog.size: " + this.getSize());
|
||||||
|
this.setLocation(100, 100);
|
||||||
|
// System.err.println("OptimizationDialog.location: " + this.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startOptimization() {
|
private void startOptimization() {
|
||||||
@ -671,13 +638,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
updating = false;
|
updating = false;
|
||||||
|
|
||||||
|
|
||||||
// Create a copy of the simulation (we're going to modify the original in the current thread)
|
// Create a copy of the simulation (we'll modify the copy here)
|
||||||
Simulation simulation = getSelectedSimulation();
|
final Simulation simulation = getSelectedSimulation();
|
||||||
Rocket rocketCopy = simulation.getRocket().copyWithOriginalID();
|
final OptimizableParameter parameter = getSelectedParameter();
|
||||||
simulation = simulation.duplicateSimulation(rocketCopy);
|
|
||||||
|
|
||||||
OptimizableParameter parameter = getSelectedParameter();
|
|
||||||
|
|
||||||
OptimizationGoal goal;
|
OptimizationGoal goal;
|
||||||
String value = (String) optimizationGoalCombo.getSelectedItem();
|
String value = (String) optimizationGoalCombo.getSelectedItem();
|
||||||
if (GOAL_MAXIMIZE.equals(value)) {
|
if (GOAL_MAXIMIZE.equals(value)) {
|
||||||
@ -735,11 +698,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SimulationModifier[] modifiers = selectedModifiers.toArray(new SimulationModifier[0]);
|
SimulationModifier[] modifiers = selectedModifiers.toArray(new SimulationModifier[0]);
|
||||||
|
|
||||||
// Check for DeploymentAltitude modifier, if it's there, we want to make certain the DeploymentEvent
|
|
||||||
// is ALTITUDE:
|
|
||||||
for (SimulationModifier mod : modifiers) {
|
for (SimulationModifier mod : modifiers) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mod.initialize(simulation);
|
mod.initialize(simulation);
|
||||||
} catch (OptimizationException ex) {
|
} catch (OptimizationException ex) {
|
||||||
@ -822,8 +782,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
try {
|
try {
|
||||||
selectedModifiers.get(i).modify(sim, newPoint.get(i));
|
selectedModifiers.get(i).modify(sim, newPoint.get(i));
|
||||||
} catch (OptimizationException e) {
|
} catch (OptimizationException e) {
|
||||||
throw new BugException("Simulation modifier failed to modify the base simulation " +
|
throw new BugException( "Simulation modifier failed to modify the base simulation " +
|
||||||
"modifier=" + selectedModifiers.get(i), e);
|
"modifier=" + selectedModifiers.get(i), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
figure.updateFigure();
|
figure.updateFigure();
|
||||||
@ -899,6 +859,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
src.removeChild(0);
|
src.removeChild(0);
|
||||||
dest.addChild(c);
|
dest.addChild(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
figure.repaint();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
dest.thaw();
|
dest.thaw();
|
||||||
@ -915,7 +877,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
loadSimulationModifiers();
|
loadSimulationModifiers();
|
||||||
|
|
||||||
// Replace selected modifiers with corresponding new modifiers
|
// Replace selected modifiers with corresponding new modifiers
|
||||||
List<SimulationModifier> newSelected = new ArrayList<SimulationModifier>();
|
List<SimulationModifier> newSelected = new ArrayList<>();
|
||||||
for (SimulationModifier original : selectedModifiers) {
|
for (SimulationModifier original : selectedModifiers) {
|
||||||
List<SimulationModifier> newModifiers = simulationModifiers.get(original.getRelatedObject());
|
List<SimulationModifier> newModifiers = simulationModifiers.get(original.getRelatedObject());
|
||||||
if (newModifiers != null) {
|
if (newModifiers != null) {
|
||||||
@ -951,34 +913,14 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
current = selection.toString();
|
current = selection.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Named<Simulation>> simulations = new ArrayList<Named<Simulation>>();
|
List<Named<Simulation>> simulations = new ArrayList<>();
|
||||||
Rocket rocket = documentCopy.getRocket();
|
for (Simulation s : documentCopy.getSimulations()){
|
||||||
|
final FlightConfiguration config = s.getActiveConfiguration();
|
||||||
for (Simulation s : documentCopy.getSimulations()) {
|
final String optionName = createSimulationName(s.getName(), config.getName() );
|
||||||
//FlightConfigurationID id = s.getConfiguration().getFlightConfigurationID();
|
simulations.add(new Named<>(s, optionName));
|
||||||
FlightConfigurationId id = new FlightConfigurationId( "stub id value - General Optimizer");
|
|
||||||
|
|
||||||
String name = createSimulationName(s.getName(), descriptor.format(rocket, id));
|
|
||||||
simulations.add(new Named<Simulation>(s, name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FlightConfigurationId curId: rocket.getIds() ){
|
simulationSelectionCombo.setModel(new DefaultComboBoxModel<>(new Vector<>(simulations)));
|
||||||
if ( curId== null) {
|
|
||||||
// this is now *extremely* unlikely
|
|
||||||
throw new NullPointerException(" flightconfiguration has a null id... bug.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Simulation sim = new Simulation(rocket);
|
|
||||||
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, curId));
|
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
Simulation sim = new Simulation(rocket);
|
|
||||||
String name = createSimulationName(trans.get("noSimulationName"), descriptor.format(rocket, null));
|
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
|
||||||
|
|
||||||
|
|
||||||
simulationSelectionCombo.setModel(new DefaultComboBoxModel<String>((String[])simulations.toArray()));
|
|
||||||
simulationSelectionCombo.setSelectedIndex(0);
|
simulationSelectionCombo.setSelectedIndex(0);
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
for (int i = 0; i < simulations.size(); i++) {
|
for (int i = 0; i < simulations.size(); i++) {
|
||||||
@ -1000,12 +942,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
current = trans.get("MaximumAltitudeParameter.name");
|
current = trans.get("MaximumAltitudeParameter.name");
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Named<OptimizableParameter>> parameters = new Vector<Named<OptimizableParameter>>();
|
Vector<Named<OptimizableParameter>> parameters = new Vector<>();
|
||||||
for (OptimizableParameter p : optimizationParameters) {
|
for (OptimizableParameter p : optimizationParameters) {
|
||||||
parameters.add(new Named<OptimizableParameter>(p, p.getName()));
|
parameters.add(new Named<>(p, p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
optimizationParameterCombo.setModel(new DefaultComboBoxModel<Named<OptimizableParameter>>( parameters ));
|
optimizationParameterCombo.setModel(new DefaultComboBoxModel<>( parameters ));
|
||||||
|
|
||||||
for (int i = 0; i < parameters.size(); i++) {
|
for (int i = 0; i < parameters.size(); i++) {
|
||||||
if (parameters.get(i).toString().equals(current)) {
|
if (parameters.get(i).toString().equals(current)) {
|
||||||
@ -1029,13 +971,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
if (optimizationParameters.isEmpty()) {
|
if (optimizationParameters.isEmpty()) {
|
||||||
throw new BugException("No rocket optimization parameters found, distribution built wrong.");
|
throw new BugException("No rocket optimization parameters found, distribution built wrong.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(optimizationParameters, new Comparator<OptimizableParameter>() {
|
optimizationParameters.sort(Comparator.comparing(OptimizableParameter::getName));
|
||||||
@Override
|
|
||||||
public int compare(OptimizableParameter o1, OptimizableParameter o2) {
|
|
||||||
return o1.getName().compareTo(o2.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSimulationModifiers() {
|
private void loadSimulationModifiers() {
|
||||||
@ -1045,7 +982,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
Object key = m.getRelatedObject();
|
Object key = m.getRelatedObject();
|
||||||
List<SimulationModifier> list = simulationModifiers.get(key);
|
List<SimulationModifier> list = simulationModifiers.get(key);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList<SimulationModifier>();
|
list = new ArrayList<>();
|
||||||
simulationModifiers.put(key, list);
|
simulationModifiers.put(key, list);
|
||||||
}
|
}
|
||||||
list.add(m);
|
list.add(m);
|
||||||
@ -1053,12 +990,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
for (Object key : simulationModifiers.keySet()) {
|
for (Object key : simulationModifiers.keySet()) {
|
||||||
List<SimulationModifier> list = simulationModifiers.get(key);
|
List<SimulationModifier> list = simulationModifiers.get(key);
|
||||||
Collections.sort(list, new Comparator<SimulationModifier>() {
|
list.sort((o1, o2) -> o1.getName().compareTo(o2.getName()));
|
||||||
@Override
|
|
||||||
public int compare(SimulationModifier o1, SimulationModifier o2) {
|
|
||||||
return o1.getName().compareTo(o2.getName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1228,9 +1160,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
for (FunctionEvaluationData data : evaluationHistory.values()) {
|
for (FunctionEvaluationData data : evaluationHistory.values()) {
|
||||||
Value[] state = data.getState();
|
Value[] state = data.getState();
|
||||||
|
|
||||||
for (int i = 0; i < state.length; i++) {
|
for (Value value : state) {
|
||||||
writer.write(TextUtil.doubleToString(state[i].getUnitValue()));
|
writer.write(TextUtil.doubleToString(value.getUnitValue()));
|
||||||
writer.write(fieldSeparator);
|
writer.write(fieldSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,16 +1209,18 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private Simulation getSelectedSimulation() {
|
private Simulation getSelectedSimulation() {
|
||||||
/* This is to debug a NPE where the returned selected item is null. */
|
|
||||||
Object item = simulationSelectionCombo.getSelectedItem();
|
Object item = simulationSelectionCombo.getSelectedItem();
|
||||||
|
|
||||||
|
/* This is to debug a NPE where the returned selected item is null. */
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
String s = "Selected simulation is null:";
|
StringBuilder s = new StringBuilder("Selected simulation is null:");
|
||||||
s = s + " item count=" + simulationSelectionCombo.getItemCount();
|
s.append(" item count=").append(simulationSelectionCombo.getItemCount());
|
||||||
for (int i = 0; i < simulationSelectionCombo.getItemCount(); i++) {
|
for (int i = 0; i < simulationSelectionCombo.getItemCount(); i++) {
|
||||||
s = s + " [" + i + "]=" + simulationSelectionCombo.getItemAt(i);
|
s.append(" [").append(i).append("]=").append(simulationSelectionCombo.getItemAt(i));
|
||||||
}
|
}
|
||||||
throw new BugException(s);
|
throw new BugException(s.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((Named<Simulation>) item).get();
|
return ((Named<Simulation>) item).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,9 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
private final SimulationModifier[] modifiers;
|
private final SimulationModifier[] modifiers;
|
||||||
|
|
||||||
private final ParallelFunctionCache cache;
|
private final ParallelFunctionCache cache;
|
||||||
|
|
||||||
|
|
||||||
private final LinkedBlockingQueue<FunctionEvaluationData> evaluationQueue =
|
private final LinkedBlockingQueue<FunctionEvaluationData> evaluationQueue = new LinkedBlockingQueue<>();
|
||||||
new LinkedBlockingQueue<FunctionEvaluationData>();
|
private final LinkedBlockingQueue<OptimizationStepData> stepQueue = new LinkedBlockingQueue<>();
|
||||||
private final LinkedBlockingQueue<OptimizationStepData> stepQueue =
|
|
||||||
new LinkedBlockingQueue<OptimizationStepData>();
|
|
||||||
private volatile long lastPurge = 0;
|
private volatile long lastPurge = 0;
|
||||||
|
|
||||||
private OptimizationException optimizationException = null;
|
private OptimizationException optimizationException = null;
|
||||||
@ -115,13 +112,10 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
} catch (OptimizationException e) {
|
} catch (OptimizationException e) {
|
||||||
this.optimizationException = e;
|
this.optimizationException = e;
|
||||||
} finally {
|
} finally {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(() -> {
|
||||||
@Override
|
lastPurge = System.currentTimeMillis() + 24L * 3600L * 1000L;
|
||||||
public void run() {
|
processQueue();
|
||||||
lastPurge = System.currentTimeMillis() + 24L * 3600L * 1000L;
|
done(optimizationException);
|
||||||
processQueue();
|
|
||||||
done(optimizationException);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +151,6 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
/**
|
/**
|
||||||
* Publishes data to the listeners. The queue is purged every PURGE_TIMEOUT milliseconds.
|
* Publishes data to the listeners. The queue is purged every PURGE_TIMEOUT milliseconds.
|
||||||
*
|
*
|
||||||
* @param data the data to publish to the listeners
|
|
||||||
*/
|
*/
|
||||||
private synchronized void publish(FunctionEvaluationData evaluation, OptimizationStepData step) {
|
private synchronized void publish(FunctionEvaluationData evaluation, OptimizationStepData step) {
|
||||||
|
|
||||||
@ -172,12 +165,7 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (lastPurge + PURGE_TIMEOUT <= now) {
|
if (lastPurge + PURGE_TIMEOUT <= now) {
|
||||||
lastPurge = now;
|
lastPurge = now;
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(this::processQueue);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
processQueue();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -193,14 +181,14 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<FunctionEvaluationData> evaluations = new ArrayList<FunctionEvaluationData>();
|
List<FunctionEvaluationData> evaluations = new ArrayList<>();
|
||||||
evaluationQueue.drainTo(evaluations);
|
evaluationQueue.drainTo(evaluations);
|
||||||
if (!evaluations.isEmpty()) {
|
if (!evaluations.isEmpty()) {
|
||||||
functionEvaluated(evaluations);
|
functionEvaluated(evaluations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<OptimizationStepData> steps = new ArrayList<OptimizationStepData>();
|
List<OptimizationStepData> steps = new ArrayList<>();
|
||||||
stepQueue.drainTo(steps);
|
stepQueue.drainTo(steps);
|
||||||
if (!steps.isEmpty()) {
|
if (!steps.isEmpty()) {
|
||||||
optimizationStepTaken(steps);
|
optimizationStepTaken(steps);
|
||||||
|
@ -708,18 +708,17 @@ public class BasicFrame extends JFrame {
|
|||||||
});
|
});
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
|
|
||||||
// TODO: reimplement this dialog
|
//// Optimize
|
||||||
// //// Optimize
|
item = new JMenuItem(trans.get("main.menu.analyze.optimization"), KeyEvent.VK_O);
|
||||||
// item = new JMenuItem(trans.get("main.menu.analyze.optimization"), KeyEvent.VK_O);
|
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.analyze.optimization.desc"));
|
||||||
// item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.analyze.optimization.desc"));
|
item.addActionListener(new ActionListener() {
|
||||||
// item.addActionListener(new ActionListener() {
|
@Override
|
||||||
// @Override
|
public void actionPerformed(ActionEvent e) {
|
||||||
// public void actionPerformed(ActionEvent e) {
|
log.info(Markers.USER_MARKER, "Rocket optimization selected");
|
||||||
// log.info(Markers.USER_MARKER, "Rocket optimization selected");
|
new GeneralOptimizationDialog(document, BasicFrame.this).setVisible(true);
|
||||||
// new GeneralOptimizationDialog(document, BasicFrame.this).setVisible(true);
|
}
|
||||||
// }
|
});
|
||||||
// });
|
menu.add(item);
|
||||||
// menu.add(item);
|
|
||||||
|
|
||||||
//// Custom expressions
|
//// Custom expressions
|
||||||
item = new JMenuItem(trans.get("main.menu.analyze.customExpressions"), KeyEvent.VK_E);
|
item = new JMenuItem(trans.get("main.menu.analyze.customExpressions"), KeyEvent.VK_E);
|
||||||
|
@ -148,7 +148,9 @@ public class SimulationEditDialog extends JDialog {
|
|||||||
panel.add(label, "growx 0, gapright para");
|
panel.add(label, "growx 0, gapright para");
|
||||||
|
|
||||||
final Rocket rkt = document.getRocket();
|
final Rocket rkt = document.getRocket();
|
||||||
|
final FlightConfiguration config = rkt.getFlightConfiguration(simulationList[0].getFlightConfigurationId());
|
||||||
final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt);
|
final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt);
|
||||||
|
configComboBox.setSelectedItem(config);
|
||||||
|
|
||||||
//// Select the motor configuration to use.
|
//// Select the motor configuration to use.
|
||||||
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg"));
|
||||||
|
@ -292,7 +292,7 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
double otherBurn = 0;
|
double otherBurn = 0;
|
||||||
|
|
||||||
|
|
||||||
FlightConfiguration config = simulation.getRocket().getSelectedConfiguration();
|
FlightConfiguration config = simulation.getActiveConfiguration();
|
||||||
Collection<MotorConfiguration> activeMotors = config.getActiveMotors();
|
Collection<MotorConfiguration> activeMotors = config.getActiveMotors();
|
||||||
|
|
||||||
for (MotorConfiguration curInstance : activeMotors) {
|
for (MotorConfiguration curInstance : activeMotors) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user