Browse Source

GUI simulation path plot and can show vars and/or rewards.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@5400 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
6d502769be
  1. 1
      prism/src/simulator/GenerateSimulationPath.java
  2. 73
      prism/src/simulator/PathToGraph.java
  3. 43
      prism/src/userinterface/simulator/GUIPathPlotDialog.java

1
prism/src/simulator/GenerateSimulationPath.java

@ -302,6 +302,7 @@ public class GenerateSimulationPath
PathToGraph displayer; PathToGraph displayer;
displayer = new PathToGraph(graphModel, modulesFile); displayer = new PathToGraph(graphModel, modulesFile);
displayer.setVarsToShow(simVars);
displayer.setShowRewards(simPathShowRewards); displayer.setShowRewards(simPathShowRewards);
displayer.setShowChangesOnly(simPathShowChangesOnly); displayer.setShowChangesOnly(simPathShowChangesOnly);
if (simPathSnapshots) if (simPathSnapshots)

73
prism/src/simulator/PathToGraph.java

@ -26,6 +26,9 @@
package simulator; package simulator;
import java.util.ArrayList;
import java.util.List;
import org.jfree.data.xy.XYDataItem; import org.jfree.data.xy.XYDataItem;
import parser.State; import parser.State;
@ -42,7 +45,8 @@ public class PathToGraph extends PathDisplayer
{ {
/** Graph on which to plot path */ /** Graph on which to plot path */
private Graph graphModel = null; private Graph graphModel = null;
private SeriesKey seriesKeys[] = null;
private List<SeriesKey> varSeriesKeys = null;
private List<SeriesKey> rewardSeriesKeys = null;
// Model info // Model info
private ModulesFile modulesFile; private ModulesFile modulesFile;
@ -53,6 +57,7 @@ public class PathToGraph extends PathDisplayer
/** Step counter */ /** Step counter */
private double lastTime; private double lastTime;
private State lastState; private State lastState;
private double[] lastStateRewards;
/** /**
* Construct a {@link PathToGraph} object * Construct a {@link PathToGraph} object
@ -72,54 +77,100 @@ public class PathToGraph extends PathDisplayer
// Display methods // Display methods
@Override @Override
public void startDisplay(State initialState, double[] stateRewards)
public void startDisplay(State initialState, double[] initialStateRewards)
{ {
// Configure axes // Configure axes
graphModel.getXAxisSettings().setHeading("Time"); graphModel.getXAxisSettings().setHeading("Time");
graphModel.getYAxisSettings().setHeading("Value"); graphModel.getYAxisSettings().setHeading("Value");
// Create series // Create series
seriesKeys = new SeriesKey[numVars];
varSeriesKeys = new ArrayList<Graph.SeriesKey>();
if (varsToShow == null) {
for (int j = 0; j < numVars; j++) {
varSeriesKeys.add(graphModel.addSeries(modulesFile.getVarName(j)));
}
} else {
for (int j = 0; j < numVars; j++) { for (int j = 0; j < numVars; j++) {
seriesKeys[j] = graphModel.addSeries(modulesFile.getVarName(j));
if (varsToShow != null && varsToShow.contains(j))
varSeriesKeys.add(graphModel.addSeries(modulesFile.getVarName(j)));
else
varSeriesKeys.add(null);
}
}
if (showRewards) {
rewardSeriesKeys = new ArrayList<Graph.SeriesKey>();
for (int j = 0; j < numRewardStructs; j++) {
rewardSeriesKeys.add(graphModel.addSeries(modulesFile.getRewardStruct(j).getName()));
}
} }
// Display initial state // Display initial state
lastState = new State(initialState.varValues.length); lastState = new State(initialState.varValues.length);
displayState(0.0, initialState, true);
if (showRewards)
lastStateRewards = explicit.Utils.cloneDoubleArray(initialStateRewards);
displayState(0.0, initialState, initialStateRewards, true);
} }
@Override @Override
public void displayStep(double timeSpent, double timeCumul, Object action, double[] transitionRewards, State newState, double[] newStateRewards) public void displayStep(double timeSpent, double timeCumul, Object action, double[] transitionRewards, State newState, double[] newStateRewards)
{ {
displayState(timeCumul, newState, !showChangesOnly);
displayState(timeCumul, newState, newStateRewards, !showChangesOnly);
} }
@Override @Override
public void displaySnapshot(double timeCumul, State newState, double[] newStateRewards) public void displaySnapshot(double timeCumul, State newState, double[] newStateRewards)
{ {
displayState(timeCumul, newState, true);
displayState(timeCumul, newState, newStateRewards, true);
} }
private void displayState(double time, State state, boolean force)
private void displayState(double time, State state, double[] stateRewards, boolean force)
{ {
if (varsToShow == null) {
for (int j = 0; j < numVars; j++) { for (int j = 0; j < numVars; j++) {
Object val = state.varValues[j]; Object val = state.varValues[j];
double d = 0.0; double d = 0.0;
if (force || !val.equals(lastState.varValues[j])) { if (force || !val.equals(lastState.varValues[j])) {
try { try {
d = TypeDouble.getInstance().castValueTo(val).doubleValue(); d = TypeDouble.getInstance().castValueTo(val).doubleValue();
graphModel.addPointToSeries(seriesKeys[j], new XYDataItem(time, d));
graphModel.addPointToSeries(varSeriesKeys.get(j), new XYDataItem(time, d));
} catch (PrismException e) { } catch (PrismException e) {
if (val instanceof Boolean) { if (val instanceof Boolean) {
d = ((Boolean) val).booleanValue() ? 1.0 : 0.0; d = ((Boolean) val).booleanValue() ? 1.0 : 0.0;
graphModel.addPointToSeries(seriesKeys[j], new XYDataItem(time, d));
graphModel.addPointToSeries(varSeriesKeys.get(j), new XYDataItem(time, d));
} }
} }
} }
} }
} else {
for (int j : varsToShow) {
Object val = state.varValues[j];
double d = 0.0;
if (force || !val.equals(lastState.varValues[j])) {
try {
d = TypeDouble.getInstance().castValueTo(val).doubleValue();
graphModel.addPointToSeries(varSeriesKeys.get(j), new XYDataItem(time, d));
} catch (PrismException e) {
if (val instanceof Boolean) {
d = ((Boolean) val).booleanValue() ? 1.0 : 0.0;
graphModel.addPointToSeries(varSeriesKeys.get(j), new XYDataItem(time, d));
}
}
}
}
}
if (showRewards) {
for (int j = 0; j < numRewardStructs; j++) {
double d = stateRewards[j];
if (force || lastStateRewards[j] != stateRewards[j]) {
graphModel.addPointToSeries(rewardSeriesKeys.get(j), new XYDataItem(time, d));
}
}
}
lastTime = time; lastTime = time;
lastState.copy(state); lastState.copy(state);
if (showRewards) {
explicit.Utils.copyDoubleArray(stateRewards, lastStateRewards);
}
} }
@Override @Override
@ -127,6 +178,6 @@ public class PathToGraph extends PathDisplayer
{ {
// Always display last points to ensure complete plot lines // Always display last points to ensure complete plot lines
// (it's OK to overwrite points) // (it's OK to overwrite points)
displayState(lastTime, lastState, true);
displayState(lastTime, lastState, lastStateRewards, true);
} }
} }

43
prism/src/userinterface/simulator/GUIPathPlotDialog.java

@ -45,6 +45,7 @@ import javax.swing.border.EmptyBorder;
import parser.ast.ModulesFile; import parser.ast.ModulesFile;
import userinterface.GUIPrism; import userinterface.GUIPrism;
import javax.swing.JCheckBox;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class GUIPathPlotDialog extends JDialog public class GUIPathPlotDialog extends JDialog
@ -101,6 +102,9 @@ public class GUIPathPlotDialog extends JDialog
private JComboBox comboBoxSimulate; private JComboBox comboBoxSimulate;
private JButton okButton; private JButton okButton;
private JButton cancelButton; private JButton cancelButton;
private JLabel lblPlot;
private JCheckBox chckbxVariables;
private JCheckBox chckbxRewards;
/** /**
* Show "Path Plot Details" dialog, return settings as a simpath string. * Show "Path Plot Details" dialog, return settings as a simpath string.
@ -135,15 +139,15 @@ public class GUIPathPlotDialog extends JDialog
super(parent, "Path Plot Details", true); super(parent, "Path Plot Details", true);
this.gui = parent; this.gui = parent;
this.modulesFile = modulesFile; this.modulesFile = modulesFile;
setBounds(100, 100, 450, 154);
setBounds(100, 100, 450, 200);
getContentPane().setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER); getContentPane().add(contentPanel, BorderLayout.CENTER);
GridBagLayout gbl_contentPanel = new GridBagLayout(); GridBagLayout gbl_contentPanel = new GridBagLayout();
gbl_contentPanel.columnWidths = new int[] { 20, 0, 0, 0, 60, 0 }; gbl_contentPanel.columnWidths = new int[] { 20, 0, 0, 0, 60, 0 };
gbl_contentPanel.rowHeights = new int[] { 20, 0, 0, 0, 0 };
gbl_contentPanel.rowHeights = new int[] { 20, 0, 0, 0, 0, 0, 0 };
gbl_contentPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; gbl_contentPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
gbl_contentPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
contentPanel.setLayout(gbl_contentPanel); contentPanel.setLayout(gbl_contentPanel);
{ {
JLabel lblSimulate = new JLabel("Simulate:"); JLabel lblSimulate = new JLabel("Simulate:");
@ -248,6 +252,33 @@ public class GUIPathPlotDialog extends JDialog
buttonPane.add(cancelButton); buttonPane.add(cancelButton);
} }
} }
{
lblPlot = new JLabel("Plot:");
GridBagConstraints gbc_lblPlot = new GridBagConstraints();
gbc_lblPlot.anchor = GridBagConstraints.EAST;
gbc_lblPlot.insets = new Insets(0, 0, 5, 5);
gbc_lblPlot.gridx = 1;
gbc_lblPlot.gridy = 3;
contentPanel.add(lblPlot, gbc_lblPlot);
}
{
chckbxVariables = new JCheckBox("Variables");
GridBagConstraints gbc_chckbxVariables = new GridBagConstraints();
gbc_chckbxVariables.anchor = GridBagConstraints.WEST;
gbc_chckbxVariables.insets = new Insets(0, 0, 5, 5);
gbc_chckbxVariables.gridx = 2;
gbc_chckbxVariables.gridy = 3;
contentPanel.add(chckbxVariables, gbc_chckbxVariables);
}
{
chckbxRewards = new JCheckBox("Rewards");
GridBagConstraints gbc_chckbxRewards = new GridBagConstraints();
gbc_chckbxRewards.anchor = GridBagConstraints.WEST;
gbc_chckbxRewards.insets = new Insets(0, 0, 5, 5);
gbc_chckbxRewards.gridx = 2;
gbc_chckbxRewards.gridy = 4;
contentPanel.add(chckbxRewards, gbc_chckbxRewards);
}
// defaults for new creation // defaults for new creation
if (modulesFile.getModelType().continuousTime()) { if (modulesFile.getModelType().continuousTime()) {
@ -259,6 +290,8 @@ public class GUIPathPlotDialog extends JDialog
textFieldInterval.setText(""); textFieldInterval.setText("");
} }
comboBoxShow.setSelectedItem(ShowChoice.CHANGES); comboBoxShow.setSelectedItem(ShowChoice.CHANGES);
chckbxVariables.setSelected(true);
chckbxRewards.setSelected(false);
this.getRootPane().setDefaultButton(okButton); this.getRootPane().setDefaultButton(okButton);
setLocationRelativeTo(getParent()); // centre setLocationRelativeTo(getParent()); // centre
@ -334,6 +367,10 @@ public class GUIPathPlotDialog extends JDialog
if ((ShowChoice) comboBoxShow.getSelectedItem() == ShowChoice.CHANGES) { if ((ShowChoice) comboBoxShow.getSelectedItem() == ShowChoice.CHANGES) {
simPathString += ",changes=true"; simPathString += ",changes=true";
} }
if (!chckbxVariables.isSelected()) {
simPathString += ",vars=()";
}
simPathString += ",rewards=" + chckbxRewards.isSelected();
cancelled = false; cancelled = false;
dispose(); dispose();

Loading…
Cancel
Save