Browse Source

New SimulatorEngine/Prism method prism.isPropertyOKForSimulation().

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@4741 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
ead22700e8
  1. 9
      prism/src/prism/Prism.java
  2. 42
      prism/src/simulator/SimulatorEngine.java
  3. 5
      prism/src/userinterface/properties/GUIMultiProperties.java
  4. 9
      prism/src/userinterface/properties/GUIProperty.java

9
prism/src/prism/Prism.java

@ -2372,6 +2372,15 @@ public class Prism implements PrismSettingsListener
}
}
/**
* Check whether a property is suitable for approximate model checking using the simulator.
* @param expr The property to check.
*/
public boolean isPropertyOKForSimulation(Expression expr)
{
return getSimulator().isPropertyOKForSimulation(expr);
}
/**
* Check if a property is suitable for analysis with the simulator.
* If not, an explanatory exception is thrown.

42
prism/src/simulator/SimulatorEngine.java

@ -67,6 +67,7 @@ import prism.*;
*
* For sampling-based approximate model checking, use:
* <UL>
* <LI> {@link #isPropertyOKForSimulation}
* <LI> {@link #checkPropertyForSimulation}
* <LI> {@link #modelCheckSingleProperty}
* <LI> {@link #modelCheckMultipleProperties}
@ -1196,24 +1197,49 @@ public class SimulatorEngine
// Model checking (approximate)
// ------------------------------------------------------------------------------
/**
* Check whether a property is suitable for approximate model checking using the simulator.
*/
public boolean isPropertyOKForSimulation(Expression expr)
{
return isPropertyOKForSimulationString(expr) == null;
}
/**
* Check whether a property is suitable for approximate model checking using the simulator.
* If not, an explanatory error message is thrown as an exception.
*/
public void checkPropertyForSimulation(Expression prop) throws PrismException
public void checkPropertyForSimulation(Expression expr) throws PrismException
{
String errMsg = isPropertyOKForSimulationString(expr);
if (errMsg != null)
throw new PrismException(errMsg);
}
/**
* Check whether a property is suitable for approximate model checking using the simulator.
* If yes, return null; if not, return an explanatory error message.
*/
private String isPropertyOKForSimulationString(Expression expr)
{
// Simulator can only be applied to P or R properties (without filters)
if (!(prop instanceof ExpressionProb || prop instanceof ExpressionReward)) {
if (prop instanceof ExpressionFilter) {
if (((ExpressionFilter) prop).getOperand() instanceof ExpressionProb || ((ExpressionFilter) prop).getOperand() instanceof ExpressionReward)
throw new PrismException("Simulator cannot handle P or R properties with filters");
if (!(expr instanceof ExpressionProb || expr instanceof ExpressionReward)) {
if (expr instanceof ExpressionFilter) {
if (((ExpressionFilter) expr).getOperand() instanceof ExpressionProb || ((ExpressionFilter) expr).getOperand() instanceof ExpressionReward)
return "Simulator cannot handle P or R properties with filters";
}
throw new PrismException("Simulator can only handle P or R properties");
return "Simulator can only handle P or R properties";
}
// Check that there are no nested probabilistic operators
if (prop.computeProbNesting() > 1) {
throw new PrismException("Simulator cannot handle nested P, R or S operators");
try {
if (expr.computeProbNesting() > 1) {
return "Simulator cannot handle nested P, R or S operators";
}
} catch (PrismException e) {
return "Simulator cannot handle this property: " + e.getMessage();
}
// No errors
return null;
}
/**

5
prism/src/userinterface/properties/GUIMultiProperties.java

@ -309,13 +309,10 @@ public class GUIMultiProperties extends GUIPlugin implements MouseListener, List
simulatableExprs = new ArrayList<Expression>();
for (int i = 0; i < validGUIProperties.size(); i++) {
GUIProperty guiP = validGUIProperties.get(i);
try {
getPrism().checkPropertyForSimulation(guiP.getProperty());
if (getPrism().isPropertyOKForSimulation(guiP.getProperty())) {
simulatableGUIProperties.add(guiP);
simulatableProperties.add(parsedProperties.getPropertyObject(i));
simulatableExprs.add(guiP.getProperty());
} catch (PrismException e) {
// do nothing
}
}
if (simulatableGUIProperties.size() == 0) {

9
prism/src/userinterface/properties/GUIProperty.java

@ -220,14 +220,7 @@ public class GUIProperty
*/
public boolean isValidForSimulation()
{
if (!isValid())
return false;
try {
prism.checkPropertyForSimulation(expr);
} catch (PrismException e) {
return false;
}
return true;
return isValid() && prism.isPropertyOKForSimulation(expr);
}
public Result getResult()

Loading…
Cancel
Save