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. 178
      prism/src/userinterface/properties/GUIExperiment.java

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

@ -31,6 +31,7 @@ import parser.*;
import parser.ast.*;
import parser.type.*;
import prism.*;
import javax.swing.*;
import userinterface.*;
import java.util.*;
@ -64,7 +65,8 @@ public class GUIExperiment
private Result res;
/** 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.guiProp = guiProp;
@ -181,9 +183,9 @@ public class GUIExperiment
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();
}
}
@ -200,7 +202,8 @@ public class GUIExperiment
private PropertiesFile propertiesFile;
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);
this.exp = exp;
@ -223,8 +226,7 @@ public class GUIExperiment
definedPFConstants = null;
res = null;
try
{
try {
SwingUtilities.invokeAndWait(new Runnable()
{
public void run()
@ -236,22 +238,21 @@ public class GUIExperiment
}
});
for (i = 0; i < undefinedConstants.getNumModelIterations(); i++)
{
for (i = 0; i < undefinedConstants.getNumModelIterations(); i++) {
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
try {
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
errorLog(e.getMessage());
try {
setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results");
}
undefinedConstants.iterateModel();
@ -259,21 +260,19 @@ public class GUIExperiment
}
// only do explicit model construction if necessary
if(!useSimulation)
{
if (!useSimulation && modulesFile.getModelType() != ModelType.PTA) {
// build model
try {
logln("\n-------------------------------------------");
model = prism.buildModel(modulesFile);
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
errorLog(e.getMessage());
try {
setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results");
}
undefinedConstants.iterateModel();
@ -282,10 +281,8 @@ public class GUIExperiment
// remove any deadlocks (don't prompt - probably should)
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");
model.fixDeadlocks();
}
@ -297,102 +294,98 @@ public class GUIExperiment
}
// collect information for simulation if required
if(useSimulation && !reuseInfo)
{
if (useSimulation && !reuseInfo) {
try {
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
errorLog(e.getMessage());
try {
setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results");
}
if (!clear) model.clear();
if (!clear)
model.clear();
undefinedConstants.iterateModel();
continue;
}
// 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 (undefinedConstants.getNumModelIterations() > 1 && !reuseInfoAsked) {
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
if(useSimulation && info.isDistributed())
{
if (useSimulation && info.isDistributed()) {
try {
GUISimulatorDistributionDialog dist = new GUISimulatorDistributionDialog(guiProp.getGUI(), prism.getSimulator(), true);
dist.show(exp, this, modulesFile, propertiesFile, 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
errorLog(e.getMessage());
try {
setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results");
}
if (!clear) model.clear();
if (!clear)
model.clear();
undefinedConstants.iterateModel();
continue;
}
}
// 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 {
logln("\n-------------------------------------------");
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());
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
// (all properties simulated simultaneously so can't get more accurate feedback at the moment anyway)
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
errorLog(e.getMessage());
try {
setMultipleErrors(definedMFConstants, null, e);
}
catch (PrismException e2) {
} catch (PrismException e2) {
error("Problem storing results");
}
undefinedConstants.iterateModel();
continue;
}
}
else
{
} else {
// iterate through as many properties as necessary
for (k = 0; k < undefinedConstants.getNumPropertyIterations(); k++)
{
for (k = 0; k < undefinedConstants.getNumPropertyIterations(); k++) {
// interrupt if requested
if(interrupted()) throw new InterruptedException();
if (interrupted())
throw new InterruptedException();
try
{
try {
// set values for PropertiesFile constants
if (propertiesFile != null)
{
if (propertiesFile != null) {
definedPFConstants = undefinedConstants.getPFConstantValues();
propertiesFile.setUndefinedConstants(definedPFConstants);
}
@ -400,20 +393,30 @@ public class GUIExperiment
// do model checking
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);
}
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.modelCheckSimulator(modulesFile, propertiesFile, propertyToCheck, info.getInitialState(), info.getNoIterations(), info.getMaxPathLength());
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
errorLog(e.getMessage());
res = new Result(e);
@ -425,8 +428,7 @@ public class GUIExperiment
{
try {
GUIExperiment.this.setResult(definedMFConstants, definedPFConstants, res);
}
catch (PrismException e) {
} catch (PrismException e) {
error("Problem storing results");
}
}
@ -439,7 +441,8 @@ public class GUIExperiment
yield();
}
}
if (!clear) model.clear();
if (!clear)
model.clear();
// iterate to next model
undefinedConstants.iterateModel();
yield();
@ -457,12 +460,10 @@ public class GUIExperiment
});
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()
{
public void run()
@ -477,13 +478,16 @@ public class GUIExperiment
});
}
// 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();
}
// catch and ignore possible exception from invokeAndWait calls
catch (java.lang.reflect.InvocationTargetException e) {}
catch (java.lang.reflect.InvocationTargetException e) {
}
}
}
}
Loading…
Cancel
Save