[cleanup] Applies a bunch of changes suggested by the linter in the Optimization Code
This commit is contained in:
parent
aa90feb61b
commit
70cbc54daf
@ -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<>();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,8 +141,7 @@ public class RocketOptimizationFunction implements Function {
|
|||||||
Simulation newSimulationInstance(Simulation simulation) {
|
Simulation newSimulationInstance(Simulation simulation) {
|
||||||
synchronized (baseSimulation) {
|
synchronized (baseSimulation) {
|
||||||
Rocket newRocket = simulation.getRocket().copyWithOriginalID();
|
Rocket newRocket = simulation.getRocket().copyWithOriginalID();
|
||||||
Simulation newSimulation = simulation.duplicateSimulation(newRocket);
|
return simulation.duplicateSimulation(newRocket);
|
||||||
return newSimulation;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
@ -118,12 +115,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;
|
||||||
@ -146,8 +142,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 +161,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 +177,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 +204,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());
|
||||||
@ -253,12 +234,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
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();
|
||||||
@ -282,19 +258,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();
|
||||||
if (selectedModifierTable.isEditing()) {
|
|
||||||
selectedModifierTable.getCellEditor().stopCellEditing();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
disableComponents.add(addButton);
|
disableComponents.add(addButton);
|
||||||
@ -302,22 +275,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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedModifierTable.isEditing()) {
|
|
||||||
selectedModifierTable.getCellEditor().stopCellEditing();
|
|
||||||
}
|
|
||||||
|
|
||||||
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");
|
||||||
@ -387,7 +357,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
simulationSelectionCombo = new JComboBox<Named<Simulation>>();
|
simulationSelectionCombo = new JComboBox<>();
|
||||||
simulationSelectionCombo.setToolTipText(tip);
|
simulationSelectionCombo.setToolTipText(tip);
|
||||||
populateSimulations();
|
populateSimulations();
|
||||||
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
||||||
@ -401,7 +371,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);
|
||||||
@ -415,7 +385,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);
|
||||||
@ -459,12 +429,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);
|
||||||
|
|
||||||
@ -560,51 +525,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");
|
||||||
@ -612,32 +568,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
|
||||||
@ -745,8 +694,6 @@ 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 {
|
||||||
@ -926,7 +873,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) {
|
||||||
@ -962,15 +909,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();
|
Rocket rocket = documentCopy.getRocket();
|
||||||
|
|
||||||
for (Simulation s : documentCopy.getSimulations()) {
|
for (Simulation s : documentCopy.getSimulations()) {
|
||||||
//FlightConfigurationID id = s.getConfiguration().getFlightConfigurationID();
|
|
||||||
FlightConfigurationId id = new FlightConfigurationId( "stub id value - General Optimizer");
|
FlightConfigurationId id = new FlightConfigurationId( "stub id value - General Optimizer");
|
||||||
|
|
||||||
String name = createSimulationName(s.getName(), descriptor.format(rocket, id));
|
String name = createSimulationName(s.getName(), descriptor.format(rocket, id));
|
||||||
simulations.add(new Named<Simulation>(s, name));
|
simulations.add(new Named<>(s, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (FlightConfigurationId curId: rocket.getIds() ){
|
for (FlightConfigurationId curId: rocket.getIds() ){
|
||||||
@ -981,14 +927,14 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
Simulation sim = new Simulation(rocket);
|
Simulation sim = new Simulation(rocket);
|
||||||
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, curId));
|
String name = createSimulationName(trans.get("basicSimulationName"), descriptor.format(rocket, curId));
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<>(sim, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
Simulation sim = new Simulation(rocket);
|
Simulation sim = new Simulation(rocket);
|
||||||
String name = createSimulationName(trans.get("noSimulationName"), descriptor.format(rocket, null));
|
String name = createSimulationName(trans.get("noSimulationName"), descriptor.format(rocket, null));
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<>(sim, name));
|
||||||
|
|
||||||
simulationSelectionCombo.setModel(new DefaultComboBoxModel<Named<Simulation>>(new Vector<>(simulations)));
|
simulationSelectionCombo.setModel(new DefaultComboBoxModel<>(new Vector<>(simulations)));
|
||||||
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++) {
|
||||||
@ -1010,12 +956,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)) {
|
||||||
@ -1040,12 +986,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
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() {
|
||||||
@ -1055,7 +996,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);
|
||||||
@ -1063,12 +1004,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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1239,8 +1175,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1290,12 +1226,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
/* This is to debug a NPE where the returned selected item is null. */
|
/* This is to debug a NPE where the returned selected item is null. */
|
||||||
Object item = simulationSelectionCombo.getSelectedItem();
|
Object item = simulationSelectionCombo.getSelectedItem();
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
@ -62,11 +62,8 @@ public abstract class OptimizationWorker extends Thread implements OptimizationC
|
|||||||
|
|
||||||
private final ParallelFunctionCache cache;
|
private final ParallelFunctionCache cache;
|
||||||
|
|
||||||
|
private final LinkedBlockingQueue<FunctionEvaluationData> evaluationQueue = new LinkedBlockingQueue<>();
|
||||||
private final LinkedBlockingQueue<FunctionEvaluationData> evaluationQueue =
|
private final LinkedBlockingQueue<OptimizationStepData> stepQueue = new LinkedBlockingQueue<>();
|
||||||
new LinkedBlockingQueue<FunctionEvaluationData>();
|
|
||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user