[#1746] Fix units in rocket optimizer "seek value of"
This commit is contained in:
parent
1b813ed4b4
commit
a2f8e25360
@ -580,7 +580,7 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
|||||||
|
|
||||||
private final ArrayList<EventListener> listeners = new ArrayList<EventListener>();
|
private final ArrayList<EventListener> listeners = new ArrayList<EventListener>();
|
||||||
|
|
||||||
private final UnitGroup units;
|
private UnitGroup units;
|
||||||
private Unit currentUnit;
|
private Unit currentUnit;
|
||||||
|
|
||||||
private final double minValue;
|
private final double minValue;
|
||||||
@ -877,6 +877,13 @@ public class DoubleModel implements StateChangeListener, ChangeSource, Invalidat
|
|||||||
currentUnit = u;
|
currentUnit = u;
|
||||||
fireStateChanged();
|
fireStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUnitGroup(UnitGroup unitGroup) {
|
||||||
|
this.units = unitGroup;
|
||||||
|
this.currentUnit = units.getDefaultUnit();
|
||||||
|
this.lastValue = this.currentUnit.toUnit(this.lastValue);
|
||||||
|
fireStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -380,6 +380,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
optimizationParameterCombo.setToolTipText(tip);
|
optimizationParameterCombo.setToolTipText(tip);
|
||||||
populateParameters();
|
populateParameters();
|
||||||
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
||||||
|
optimizationParameterCombo.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
updateSeekValueUnits();
|
||||||
|
}
|
||||||
|
});
|
||||||
disableComponents.add(optimizationParameterCombo);
|
disableComponents.add(optimizationParameterCombo);
|
||||||
sub.add(optimizationParameterCombo, "growx, wrap unrel");
|
sub.add(optimizationParameterCombo, "growx, wrap unrel");
|
||||||
|
|
||||||
@ -554,6 +560,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
Collections.unmodifiableMap(evaluationHistory),
|
Collections.unmodifiableMap(evaluationHistory),
|
||||||
Collections.unmodifiableList(selectedModifiers),
|
Collections.unmodifiableList(selectedModifiers),
|
||||||
getSelectedParameter(),
|
getSelectedParameter(),
|
||||||
|
optimizationGoalUnitSelector.getSelectedUnit(),
|
||||||
UnitGroup.stabilityUnits(getSelectedSimulation().getRocket()),
|
UnitGroup.stabilityUnits(getSelectedSimulation().getRocket()),
|
||||||
GeneralOptimizationDialog.this);
|
GeneralOptimizationDialog.this);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
@ -606,6 +613,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
this.add(new JScrollPane(panel));
|
this.add(new JScrollPane(panel));
|
||||||
clearHistory();
|
clearHistory();
|
||||||
updateComponents();
|
updateComponents();
|
||||||
|
updateSeekValueUnits();
|
||||||
GUIUtil.setDisposableDialogOptions(this, null);
|
GUIUtil.setDisposableDialogOptions(this, null);
|
||||||
|
|
||||||
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
|
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
|
||||||
@ -650,7 +658,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
} else if (GOAL_MINIMIZE.equals(value)) {
|
} else if (GOAL_MINIMIZE.equals(value)) {
|
||||||
goal = new MinimizationGoal();
|
goal = new MinimizationGoal();
|
||||||
} else if (GOAL_SEEK.equals(value)) {
|
} else if (GOAL_SEEK.equals(value)) {
|
||||||
goal = new ValueSeekGoal(optimizationSeekValue.getValue());
|
Unit u = parameter.getUnitGroup().getDefaultUnit();
|
||||||
|
goal = new ValueSeekGoal(u.toUnit(optimizationSeekValue.getValue()));
|
||||||
} else {
|
} else {
|
||||||
throw new BugException("optimizationGoalCombo had invalid value: " + value);
|
throw new BugException("optimizationGoalCombo had invalid value: " + value);
|
||||||
}
|
}
|
||||||
@ -834,13 +843,22 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
evaluationHistory.clear();
|
evaluationHistory.clear();
|
||||||
optimizationPath.clear();
|
optimizationPath.clear();
|
||||||
bestValue = Double.NaN;
|
bestValue = Double.NaN;
|
||||||
bestValueUnit = getSelectedParameter().getUnitGroup().getDefaultUnit();
|
bestValueUnit = optimizationGoalUnitSelector.getSelectedUnit();
|
||||||
stepCount = 0;
|
stepCount = 0;
|
||||||
evaluationCount = 0;
|
evaluationCount = 0;
|
||||||
stepSize = 0.5;
|
stepSize = 0.5;
|
||||||
updateCounters();
|
updateCounters();
|
||||||
updateComponents();
|
updateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSeekValueUnits() {
|
||||||
|
if (optimizationSeekValue != null && optimizationGoalUnitSelector != null) {
|
||||||
|
optimizationSeekValue.setUnitGroup(getSelectedParameter().getUnitGroup());
|
||||||
|
optimizationSeekValue.setValue(0);
|
||||||
|
optimizationGoalUnitSelector.setModel(optimizationSeekValue);
|
||||||
|
optimizationGoalUnitSelector.revalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void applyDesign() {
|
private void applyDesign() {
|
||||||
// TODO: MEDIUM: Apply also potential changes to simulations
|
// TODO: MEDIUM: Apply also potential changes to simulations
|
||||||
@ -1168,7 +1186,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
writer.write(fieldSeparator);
|
writer.write(fieldSeparator);
|
||||||
}
|
}
|
||||||
writer.write(getSelectedParameter().getName() + " / " +
|
writer.write(getSelectedParameter().getName() + " / " +
|
||||||
getSelectedParameter().getUnitGroup().getDefaultUnit().getUnit());
|
optimizationGoalUnitSelector.getSelectedUnit().getUnit());
|
||||||
|
|
||||||
writer.write("\n");
|
writer.write("\n");
|
||||||
}
|
}
|
||||||
@ -1187,7 +1205,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.getParameterValue() != null) {
|
if (data.getParameterValue() != null) {
|
||||||
writer.write(TextUtil.doubleToString(data.getParameterValue().getUnitValue()));
|
writer.write(TextUtil.doubleToString(optimizationGoalUnitSelector.getSelectedUnit().toUnit(data.getParameterValue().getValue())));
|
||||||
} else {
|
} else {
|
||||||
writer.write("N/A");
|
writer.write("N/A");
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public class OptimizationPlotDialog extends JDialog {
|
|||||||
|
|
||||||
|
|
||||||
public OptimizationPlotDialog(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
public OptimizationPlotDialog(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
||||||
List<SimulationModifier> modifiers, OptimizableParameter parameter, UnitGroup stabilityUnit, Window parent) {
|
List<SimulationModifier> modifiers, OptimizableParameter parameter, Unit parameterUnit, UnitGroup stabilityUnit, Window parent) {
|
||||||
super(parent, trans.get("title"), ModalityType.APPLICATION_MODAL);
|
super(parent, trans.get("title"), ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
|
||||||
@ -88,9 +88,9 @@ public class OptimizationPlotDialog extends JDialog {
|
|||||||
|
|
||||||
ChartPanel chart;
|
ChartPanel chart;
|
||||||
if (modifiers.size() == 1) {
|
if (modifiers.size() == 1) {
|
||||||
chart = create1DPlot(path, evaluations, modifiers, parameter, stabilityUnit);
|
chart = create1DPlot(path, evaluations, modifiers, parameter, parameterUnit, stabilityUnit);
|
||||||
} else if (modifiers.size() == 2) {
|
} else if (modifiers.size() == 2) {
|
||||||
chart = create2DPlot(path, evaluations, modifiers, parameter, stabilityUnit);
|
chart = create2DPlot(path, evaluations, modifiers, parameter, parameterUnit, stabilityUnit);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid dimensionality, dim=" + modifiers.size());
|
throw new IllegalArgumentException("Invalid dimensionality, dim=" + modifiers.size());
|
||||||
}
|
}
|
||||||
@ -126,11 +126,11 @@ public class OptimizationPlotDialog extends JDialog {
|
|||||||
* Create a 1D plot of the optimization path.
|
* Create a 1D plot of the optimization path.
|
||||||
*/
|
*/
|
||||||
private ChartPanel create1DPlot(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
private ChartPanel create1DPlot(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
||||||
List<SimulationModifier> modifiers, OptimizableParameter parameter, UnitGroup stabilityUnit) {
|
List<SimulationModifier> modifiers, OptimizableParameter parameter, Unit parameterUnit, UnitGroup stabilityUnit) {
|
||||||
|
|
||||||
SimulationModifier modX = modifiers.get(0);
|
SimulationModifier modX = modifiers.get(0);
|
||||||
Unit xUnit = modX.getUnitGroup().getDefaultUnit();
|
Unit xUnit = modX.getUnitGroup().getDefaultUnit();
|
||||||
Unit yUnit = parameter.getUnitGroup().getDefaultUnit();
|
Unit yUnit = parameterUnit;
|
||||||
|
|
||||||
// Create the optimization path (with autosort)
|
// Create the optimization path (with autosort)
|
||||||
XYSeries series = new XYSeries(trans.get("plot1d.series"), true, true);
|
XYSeries series = new XYSeries(trans.get("plot1d.series"), true, true);
|
||||||
@ -224,10 +224,7 @@ public class OptimizationPlotDialog extends JDialog {
|
|||||||
* Create a 2D plot of the optimization path.
|
* Create a 2D plot of the optimization path.
|
||||||
*/
|
*/
|
||||||
private ChartPanel create2DPlot(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
private ChartPanel create2DPlot(List<Point> path, Map<Point, FunctionEvaluationData> evaluations,
|
||||||
List<SimulationModifier> modifiers, OptimizableParameter parameter, UnitGroup stabilityUnit) {
|
List<SimulationModifier> modifiers, OptimizableParameter parameter, Unit parameterUnit, UnitGroup stabilityUnit) {
|
||||||
|
|
||||||
Unit parameterUnit = parameter.getUnitGroup().getDefaultUnit();
|
|
||||||
|
|
||||||
SimulationModifier modX = modifiers.get(0);
|
SimulationModifier modX = modifiers.get(0);
|
||||||
SimulationModifier modY = modifiers.get(1);
|
SimulationModifier modY = modifiers.get(1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user