Browse Source

Added option to do experiments for PTAs in GUI.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@2193 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 15 years ago
parent
commit
dcfc7c59de
  1. 292
      prism/src/userinterface/properties/GUIExperiment.java

292
prism/src/userinterface/properties/GUIExperiment.java

@ -31,6 +31,7 @@ import parser.*;
import parser.ast.*; import parser.ast.*;
import parser.type.*; import parser.type.*;
import prism.*; import prism.*;
import javax.swing.*; import javax.swing.*;
import userinterface.*; import userinterface.*;
import java.util.*; import java.util.*;
@ -48,23 +49,24 @@ public class GUIExperiment
private prism.ResultsCollection results; private prism.ResultsCollection results;
private String modString; private String modString;
private boolean finished = false; private boolean finished = false;
private ModulesFile mod; private ModulesFile mod;
private UndefinedConstants cons; private UndefinedConstants cons;
private PropertiesFile prop; //contains 1 property only private PropertiesFile prop; //contains 1 property only
private boolean running = false; private boolean running = false;
private Thread theThread; private Thread theThread;
private boolean useSimulation; private boolean useSimulation;
private Values definedMFConstants; private Values definedMFConstants;
private Values definedPFConstants; private Values definedPFConstants;
private Result res; private Result res;
/** Creates a new instance of GUIExperiment */ /** Creates a new instance of GUIExperiment */
public GUIExperiment(GUIExperimentTable table, GUIMultiProperties guiProp, PropertiesFile prop, UndefinedConstants cons, ModulesFile mod, String modString, boolean useSimulation)
public GUIExperiment(GUIExperimentTable table, GUIMultiProperties guiProp, PropertiesFile prop, UndefinedConstants cons, ModulesFile mod, String modString,
boolean useSimulation)
{ {
this.table = table; this.table = table;
this.guiProp = guiProp; this.guiProp = guiProp;
@ -73,76 +75,76 @@ public class GUIExperiment
this.mod = mod; this.mod = mod;
this.modString = modString; this.modString = modString;
this.useSimulation = useSimulation; this.useSimulation = useSimulation;
results = new prism.ResultsCollection(cons, prop.getProperty(0).getResultName()); results = new prism.ResultsCollection(cons, prop.getProperty(0).getResultName());
} }
//ACCESS METHODS //ACCESS METHODS
public int getTotalIterations() public int getTotalIterations()
{ {
return cons.getNumIterations(); return cons.getNumIterations();
} }
public int getCurrentIterations() public int getCurrentIterations()
{ {
return results.getCurrentIteration(); return results.getCurrentIteration();
} }
public Vector getRangingConstants() public Vector getRangingConstants()
{ {
return cons.getRangingConstants(); return cons.getRangingConstants();
} }
public String getDefinedConstantsString() public String getDefinedConstantsString()
{ {
return cons.getDefinedConstantsString(); return cons.getDefinedConstantsString();
} }
public String getPFDefinedConstantsString() public String getPFDefinedConstantsString()
{ {
return cons.getPFDefinedConstantsString(); return cons.getPFDefinedConstantsString();
} }
public String getPropertyString() public String getPropertyString()
{ {
return prop.getProperty(0).toString(); return prop.getProperty(0).toString();
} }
public Type getPropertyType() public Type getPropertyType()
{ {
return prop.getProperty(0).getType(); return prop.getProperty(0).getType();
} }
public ResultsCollection getResults() public ResultsCollection getResults()
{ {
return results; return results;
} }
public boolean isFinished() public boolean isFinished()
{ {
return finished; return finished;
} }
public boolean isUseSimulation() public boolean isUseSimulation()
{ {
return useSimulation; return useSimulation;
} }
public GUIExperimentTable getTable() public GUIExperimentTable getTable()
{ {
return table; return table;
} }
//UPDATE METHODS //UPDATE METHODS
public void startExperiment() public void startExperiment()
{ {
theThread = new ExperimentThread(guiProp,this,cons,mod,prop);
theThread = new ExperimentThread(guiProp, this, cons, mod, prop);
running = true; running = true;
theThread.start(); theThread.start();
}
}
public synchronized void experimentDone() public synchronized void experimentDone()
{ {
running = false; running = false;
@ -150,7 +152,7 @@ public class GUIExperiment
finished = true; finished = true;
this.table.repaint(); this.table.repaint();
} }
// note: presently, this is never actually called // note: presently, this is never actually called
// (in case of errors, these are stored as the results of the experiment and things end normally) // (in case of errors, these are stored as the results of the experiment and things end normally)
public synchronized void experimentFailed() public synchronized void experimentFailed()
@ -160,7 +162,7 @@ public class GUIExperiment
finished = true; finished = true;
table.repaint(); table.repaint();
} }
public synchronized void experimentInterrupted() public synchronized void experimentInterrupted()
{ {
running = false; running = false;
@ -168,39 +170,40 @@ public class GUIExperiment
finished = true; finished = true;
table.repaint(); table.repaint();
} }
public synchronized void setResult(Values mfValues, Values pfValues, Result res) throws PrismException public synchronized void setResult(Values mfValues, Values pfValues, Result res) throws PrismException
{ {
results.setResult(mfValues, pfValues, res.getResult()); results.setResult(mfValues, pfValues, res.getResult());
} }
public synchronized void setMultipleErrors(Values mfValues, Values pfValues, Exception e) throws PrismException public synchronized void setMultipleErrors(Values mfValues, Values pfValues, Exception e) throws PrismException
{ {
results.setMultipleErrors(mfValues, pfValues, e); results.setMultipleErrors(mfValues, pfValues, e);
} }
public void stop() public void stop()
{ {
if(running && theThread != null)
{
if(useSimulation) guiProp.getPrism().getSimulator().stopSampling();
if (running && theThread != null) {
if (useSimulation)
guiProp.getPrism().getSimulator().stopSampling();
theThread.interrupt(); theThread.interrupt();
} }
} }
//tidy up ResultsCollection when it has been removed (to tidy up graphs) //tidy up ResultsCollection when it has been removed (to tidy up graphs)
public void clear() public void clear()
{ {
} }
class ExperimentThread extends GUIComputationThread class ExperimentThread extends GUIComputationThread
{ {
private UndefinedConstants undefinedConstants; private UndefinedConstants undefinedConstants;
private ModulesFile modulesFile; private ModulesFile modulesFile;
private PropertiesFile propertiesFile; private PropertiesFile propertiesFile;
private GUIExperiment exp; private GUIExperiment exp;
public ExperimentThread(GUIMultiProperties guiProp, GUIExperiment exp, UndefinedConstants undefinedConstants, ModulesFile modulesFile, PropertiesFile propertiesFile)
public ExperimentThread(GUIMultiProperties guiProp, GUIExperiment exp, UndefinedConstants undefinedConstants, ModulesFile modulesFile,
PropertiesFile propertiesFile)
{ {
super(guiProp); super(guiProp);
this.exp = exp; this.exp = exp;
@ -208,23 +211,22 @@ public class GUIExperiment
this.modulesFile = modulesFile; this.modulesFile = modulesFile;
this.propertiesFile = propertiesFile; this.propertiesFile = propertiesFile;
} }
public void run() public void run()
{ {
int i, k; int i, k;
boolean clear = true; boolean clear = true;
Model model = null; Model model = null;
Expression propertyToCheck = propertiesFile.getProperty(0); Expression propertyToCheck = propertiesFile.getProperty(0);
SimulationInformation info = null; SimulationInformation info = null;
boolean reuseInfo = false, reuseInfoAsked = false; boolean reuseInfo = false, reuseInfoAsked = false;
definedMFConstants = null; definedMFConstants = null;
definedPFConstants = null; definedPFConstants = null;
res = null; res = null;
try
{
try {
SwingUtilities.invokeAndWait(new Runnable() SwingUtilities.invokeAndWait(new Runnable()
{ {
public void run() public void run()
@ -235,185 +237,186 @@ public class GUIExperiment
guiProp.notifyEventListeners(new GUIPropertiesEvent(GUIPropertiesEvent.EXPERIMENT_START)); guiProp.notifyEventListeners(new GUIPropertiesEvent(GUIPropertiesEvent.EXPERIMENT_START));
} }
}); });
for (i = 0; i < undefinedConstants.getNumModelIterations(); i++)
{
for (i = 0; i < undefinedConstants.getNumModelIterations(); i++) {
definedMFConstants = undefinedConstants.getMFConstantValues(); definedMFConstants = undefinedConstants.getMFConstantValues();
if (definedMFConstants != null) if (definedMFConstants.getNumValues() > 0) logln("\nModel constants: " + definedMFConstants);
if (definedMFConstants != null)
if (definedMFConstants.getNumValues() > 0)
logln("\nModel constants: " + definedMFConstants);
// set values for ModulesFile constants // set values for ModulesFile constants
try { try {
modulesFile.setUndefinedConstants(definedMFConstants); modulesFile.setUndefinedConstants(definedMFConstants);
}
catch (PrismException e) {
} catch (PrismException e) {
// in case of error, report it (in log only), store as result, and go on to the next model // in case of error, report it (in log only), store as result, and go on to the next model
errorLog(e.getMessage()); errorLog(e.getMessage());
try { try {
setMultipleErrors(definedMFConstants, null, e); setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results"); error("Problem storing results");
} }
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
continue; continue;
} }
// only do explicit model construction if necessary // only do explicit model construction if necessary
if(!useSimulation)
{
if (!useSimulation && modulesFile.getModelType() != ModelType.PTA) {
// build model // build model
try { try {
logln("\n-------------------------------------------"); logln("\n-------------------------------------------");
model = prism.buildModel(modulesFile); model = prism.buildModel(modulesFile);
clear = false; clear = false;
}
catch (PrismException e) {
} catch (PrismException e) {
// in case of error, report it (in log only), store as result, and go on to the next model // in case of error, report it (in log only), store as result, and go on to the next model
errorLog(e.getMessage()); errorLog(e.getMessage());
try { try {
setMultipleErrors(definedMFConstants, null, e); setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results"); error("Problem storing results");
} }
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
continue; continue;
} }
// remove any deadlocks (don't prompt - probably should) // remove any deadlocks (don't prompt - probably should)
StateList states = model.getDeadlockStates(); StateList states = model.getDeadlockStates();
if (states != null)
{
if (states.size() > 0)
{
if (states != null) {
if (states.size() > 0) {
guiProp.log("\nWarning: " + states.size() + " deadlock states detected; adding self-loops in these states...\n"); guiProp.log("\nWarning: " + states.size() + " deadlock states detected; adding self-loops in these states...\n");
model.fixDeadlocks(); model.fixDeadlocks();
} }
} }
// print some model info // print some model info
guiProp.log("\n"); guiProp.log("\n");
model.printTransInfo(guiProp.getGUI().getLog()); model.printTransInfo(guiProp.getGUI().getLog());
} }
// collect information for simulation if required // collect information for simulation if required
if(useSimulation && !reuseInfo)
{
if (useSimulation && !reuseInfo) {
try { try {
info = null; info = null;
info = GUISimulationPicker.defineSimulationWithDialog(guiProp.getGUI(), modulesFile.getInitialValues(), modulesFile, "("+definedMFConstants+")");
}
catch (PrismException e) {
info = GUISimulationPicker.defineSimulationWithDialog(guiProp.getGUI(), modulesFile.getInitialValues(), modulesFile, "("
+ definedMFConstants + ")");
} catch (PrismException e) {
// in case of error, report it (in log only), store as result, and go on to the next model // in case of error, report it (in log only), store as result, and go on to the next model
errorLog(e.getMessage()); errorLog(e.getMessage());
try { try {
setMultipleErrors(definedMFConstants, null, e); setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results"); error("Problem storing results");
} }
if (!clear) model.clear();
if (!clear)
model.clear();
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
continue; continue;
} }
// if info is null, the user clicked cancel // if info is null, the user clicked cancel
if(info == null) break;
if (info == null)
break;
// if there are multiple models, offer the chance to reuse simulation info // if there are multiple models, offer the chance to reuse simulation info
if (undefinedConstants.getNumModelIterations() > 1 && !reuseInfoAsked) { if (undefinedConstants.getNumModelIterations() > 1 && !reuseInfoAsked) {
reuseInfoAsked = true; reuseInfoAsked = true;
int q = guiProp.questionYesNo("Do you want to reuse the same initial state and simulation\n" +
"parameters for the remaining models in this experiment?\n" +
"If not you will be prompted for new values for each one.");
if (q == 0) reuseInfo = true;
int q = guiProp.questionYesNo("Do you want to reuse the same initial state and simulation\n"
+ "parameters for the remaining models in this experiment?\n" + "If not you will be prompted for new values for each one.");
if (q == 0)
reuseInfo = true;
} }
} }
// for distributed simulation, pass control to the GUISimulatorDistributionDialog // for distributed simulation, pass control to the GUISimulatorDistributionDialog
if(useSimulation && info.isDistributed())
{
if (useSimulation && info.isDistributed()) {
try { try {
GUISimulatorDistributionDialog dist = new GUISimulatorDistributionDialog(guiProp.getGUI(), prism.getSimulator(), true); GUISimulatorDistributionDialog dist = new GUISimulatorDistributionDialog(guiProp.getGUI(), prism.getSimulator(), true);
dist.show(exp, this, modulesFile, propertiesFile, undefinedConstants, propertyToCheck, info); dist.show(exp, this, modulesFile, propertiesFile, undefinedConstants, propertyToCheck, info);
//new GUISimulatorDistributionDialog(guiProp.getGUI(), prism.getSimulator(), true).show(modulesFile, undefinedConstants, propertyToCheck, info); //new GUISimulatorDistributionDialog(guiProp.getGUI(), prism.getSimulator(), true).show(modulesFile, undefinedConstants, propertyToCheck, info);
}
catch (PrismException e) {
} catch (PrismException e) {
// in case of error, report it (in log only), store as result, and go on to the next model // in case of error, report it (in log only), store as result, and go on to the next model
errorLog(e.getMessage()); errorLog(e.getMessage());
try { try {
setMultipleErrors(definedMFConstants, null, e); setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results"); error("Problem storing results");
} }
if (!clear) model.clear();
if (!clear)
model.clear();
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
continue; continue;
} }
} }
// for simulation where "simultaneous property checking" is enabled... // for simulation where "simultaneous property checking" is enabled...
else if(useSimulation && prism.getSettings().getBoolean(PrismSettings.SIMULATOR_SIMULTANEOUS) && undefinedConstants.getNumPropertyIterations() > 1)
{
else if (useSimulation && prism.getSettings().getBoolean(PrismSettings.SIMULATOR_SIMULTANEOUS)
&& undefinedConstants.getNumPropertyIterations() > 1) {
try { try {
logln("\n-------------------------------------------"); logln("\n-------------------------------------------");
logln("\nSimulating: " + propertyToCheck); logln("\nSimulating: " + propertyToCheck);
if (definedMFConstants != null) if (definedMFConstants.getNumValues() > 0) logln("Model constants: " + definedMFConstants);
if (definedMFConstants != null)
if (definedMFConstants.getNumValues() > 0)
logln("Model constants: " + definedMFConstants);
logln("Property constants: " + undefinedConstants.getPFDefinedConstantsString()); logln("Property constants: " + undefinedConstants.getPFDefinedConstantsString());
log("Simulation parameters: approx = "+info.getApprox()+", conf = "+info.getConfidence()+", num samples = "+info.getNoIterations()+", max path len = "+info.getMaxPathLength()+")\n");
prism.modelCheckSimulatorExperiment(modulesFile, propertiesFile, undefinedConstants, results, propertyToCheck, info.getInitialState(), info.getNoIterations(), info.getMaxPathLength());
log("Simulation parameters: approx = " + info.getApprox() + ", conf = " + info.getConfidence() + ", num samples = "
+ info.getNoIterations() + ", max path len = " + info.getMaxPathLength() + ")\n");
prism.modelCheckSimulatorExperiment(modulesFile, propertiesFile, undefinedConstants, results, propertyToCheck, info
.getInitialState(), info.getNoIterations(), info.getMaxPathLength());
// update progress meter // update progress meter
// (all properties simulated simultaneously so can't get more accurate feedback at the moment anyway) // (all properties simulated simultaneously so can't get more accurate feedback at the moment anyway)
table.progressChanged(); table.progressChanged();
}
catch (PrismException e) {
} catch (PrismException e) {
// in case of error, report it (in log only), store as result, and go on to the next model // in case of error, report it (in log only), store as result, and go on to the next model
errorLog(e.getMessage()); errorLog(e.getMessage());
try { try {
setMultipleErrors(definedMFConstants, null, e); setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results"); error("Problem storing results");
} }
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
continue; continue;
} }
}
else
{
} else {
// iterate through as many properties as necessary // iterate through as many properties as necessary
for (k = 0; k < undefinedConstants.getNumPropertyIterations(); k++)
{
for (k = 0; k < undefinedConstants.getNumPropertyIterations(); k++) {
// interrupt if requested // interrupt if requested
if(interrupted()) throw new InterruptedException();
try
{
if (interrupted())
throw new InterruptedException();
try {
// set values for PropertiesFile constants // set values for PropertiesFile constants
if (propertiesFile != null)
{
if (propertiesFile != null) {
definedPFConstants = undefinedConstants.getPFConstantValues(); definedPFConstants = undefinedConstants.getPFConstantValues();
propertiesFile.setUndefinedConstants(definedPFConstants); propertiesFile.setUndefinedConstants(definedPFConstants);
} }
// do model checking // do model checking
logln("\n-------------------------------------------"); logln("\n-------------------------------------------");
logln("\n"+(useSimulation?"Simulating":"Model checking")+": " + propertyToCheck);
if (definedMFConstants != null) if (definedMFConstants.getNumValues() > 0) logln("Model constants: " + definedMFConstants);
if (definedPFConstants != null) if (definedPFConstants.getNumValues() > 0) logln("Property constants: " + definedPFConstants);
if (useSimulation) log("Simulation parameters: approx = "+info.getApprox()+", conf = "+info.getConfidence()+", num samples = "+info.getNoIterations()+", max path len = "+info.getMaxPathLength()+")\n");
if (!useSimulation)
{
res = prism.modelCheck(model, propertiesFile, propertyToCheck);
}
else {
res = prism.modelCheckSimulator(modulesFile, propertiesFile, propertyToCheck, info.getInitialState(), info.getNoIterations(), info.getMaxPathLength());
logln("\n" + (useSimulation ? "Simulating" : "Model checking") + ": " + propertyToCheck);
if (definedMFConstants != null)
if (definedMFConstants.getNumValues() > 0)
logln("Model constants: " + definedMFConstants);
if (definedPFConstants != null)
if (definedPFConstants.getNumValues() > 0)
logln("Property constants: " + definedPFConstants);
if (useSimulation)
log("Simulation parameters: approx = " + info.getApprox() + ", conf = " + info.getConfidence() + ", num samples = "
+ info.getNoIterations() + ", max path len = " + info.getMaxPathLength() + ")\n");
if (!useSimulation) {
// PTA model checking
if (modulesFile.getModelType() == ModelType.PTA) {
res = prism.modelCheckPTA(modulesFile, propertiesFile, propertyToCheck);
}
// Non-PTA model checking
else {
res = prism.modelCheck(model, propertiesFile, propertyToCheck);
}
} else {
res = prism.modelCheckSimulator(modulesFile, propertiesFile, propertyToCheck, info.getInitialState(), info
.getNoIterations(), info.getMaxPathLength());
} }
}
catch(PrismException e)
{
} catch (PrismException e) {
// in case of error, report it (in log only), store exception as the result and proceed // in case of error, report it (in log only), store exception as the result and proceed
errorLog(e.getMessage()); errorLog(e.getMessage());
res = new Result(e); res = new Result(e);
@ -425,26 +428,26 @@ public class GUIExperiment
{ {
try { try {
GUIExperiment.this.setResult(definedMFConstants, definedPFConstants, res); GUIExperiment.this.setResult(definedMFConstants, definedPFConstants, res);
}
catch (PrismException e) {
} catch (PrismException e) {
error("Problem storing results"); error("Problem storing results");
} }
} }
}); });
table.progressChanged(); table.progressChanged();
// iterate to next property // iterate to next property
undefinedConstants.iterateProperty(); undefinedConstants.iterateProperty();
yield(); yield();
} }
} }
if (!clear) model.clear();
if (!clear)
model.clear();
// iterate to next model // iterate to next model
undefinedConstants.iterateModel(); undefinedConstants.iterateModel();
yield(); yield();
} }
SwingUtilities.invokeAndWait(new Runnable() SwingUtilities.invokeAndWait(new Runnable()
{ {
public void run() public void run()
@ -456,34 +459,35 @@ public class GUIExperiment
} }
}); });
experimentDone(); experimentDone();
if (results.containsErrors()) errorDialog("One or more errors occured during this experiment.\nSelect \"View results\" or check the log for more information");
}
catch(InterruptedException e)
{
try
{
if (results.containsErrors())
errorDialog("One or more errors occured during this experiment.\nSelect \"View results\" or check the log for more information");
} catch (InterruptedException e) {
try {
SwingUtilities.invokeAndWait(new Runnable() SwingUtilities.invokeAndWait(new Runnable()
{ {
public void run() public void run()
{ {
guiProp.stopProgress(); guiProp.stopProgress();
guiProp.setTaskBarText("Running experiment... interrupted."); guiProp.setTaskBarText("Running experiment... interrupted.");
guiProp.notifyEventListeners(new GUIComputationEvent(GUIComputationEvent.COMPUTATION_DONE, guiProp)); guiProp.notifyEventListeners(new GUIComputationEvent(GUIComputationEvent.COMPUTATION_DONE, guiProp));
guiProp.notifyEventListeners(new GUIPropertiesEvent(GUIPropertiesEvent.EXPERIMENT_END)); guiProp.notifyEventListeners(new GUIPropertiesEvent(GUIPropertiesEvent.EXPERIMENT_END));
} }
}); });
} }
// catch and ignore possible exceptions from invokeAndWait call // catch and ignore possible exceptions from invokeAndWait call
catch (InterruptedException e2) {}
catch (java.lang.reflect.InvocationTargetException e2) {}
if (!clear) model.clear();
catch (InterruptedException e2) {
} catch (java.lang.reflect.InvocationTargetException e2) {
}
if (!clear)
model.clear();
experimentInterrupted(); experimentInterrupted();
} }
// catch and ignore possible exception from invokeAndWait calls // catch and ignore possible exception from invokeAndWait calls
catch (java.lang.reflect.InvocationTargetException e) {}
catch (java.lang.reflect.InvocationTargetException e) {
}
} }
} }
} }
Loading…
Cancel
Save