Browse Source

Moved reachability/deadlocks/etc. into Model classes.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@746 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 18 years ago
parent
commit
701ad33350
  1. 216
      prism/src/prism/Explicit2MTBDD.java
  2. 5
      prism/src/prism/Model.java
  3. 173
      prism/src/prism/Modules2MTBDD.java
  4. 73
      prism/src/prism/NondetModel.java
  5. 3
      prism/src/prism/Prism.java
  6. 2
      prism/src/prism/PrismCL.java
  7. 125
      prism/src/prism/ProbModel.java
  8. 14
      prism/src/prism/StochModel.java

216
prism/src/prism/Explicit2MTBDD.java

@ -31,7 +31,6 @@ import java.util.Vector;
import java.util.HashMap; import java.util.HashMap;
import jdd.*; import jdd.*;
import mtbdd.*;
import parser.*; import parser.*;
import parser.ast.*; import parser.ast.*;
@ -39,13 +38,13 @@ import parser.ast.*;
public class Explicit2MTBDD public class Explicit2MTBDD
{ {
// prism
private Prism prism;
// logs // logs
private PrismLog mainLog; // main log private PrismLog mainLog; // main log
private PrismLog techLog; // tech log private PrismLog techLog; // tech log
// flags/settings
private boolean doReach = true; // by default, do reachability (sometimes might want to skip it though)
// files to read in from // files to read in from
private File statesFile; private File statesFile;
private File transFile; private File transFile;
@ -78,10 +77,7 @@ public class Explicit2MTBDD
// dds/dd vars - whole system // dds/dd vars - whole system
private JDDNode trans; // transition matrix dd private JDDNode trans; // transition matrix dd
private JDDNode range; // dd giving range for system private JDDNode range; // dd giving range for system
private JDDNode trans01; // 0-1 transition matrix dd
private JDDNode start; // dd for start state private JDDNode start; // dd for start state
private JDDNode reach; // dd of reachable states
private JDDNode deadlocks; // dd of deadlock states
private JDDNode stateRewards; // dd of state rewards private JDDNode stateRewards; // dd of state rewards
private JDDNode transRewards; // dd of transition rewards private JDDNode transRewards; // dd of transition rewards
private JDDVars allDDRowVars; // all dd vars (rows) private JDDVars allDDRowVars; // all dd vars (rows)
@ -112,10 +108,11 @@ public class Explicit2MTBDD
// constructor // constructor
public Explicit2MTBDD(PrismLog log1, PrismLog log2, File sf, File tf, int t, String is)
public Explicit2MTBDD(Prism prism, File sf, File tf, int t, String is)
{ {
mainLog = log1;
techLog = log2;
this.prism = prism;
mainLog = prism.getMainLog();
techLog = prism.getTechLog();
statesFile = sf; statesFile = sf;
transFile = tf; transFile = tf;
// set type at this point // set type at this point
@ -131,28 +128,6 @@ public class Explicit2MTBDD
initString = is; initString = is;
} }
// set options (generic)
public void setOption(String option, boolean b)
{
if (option.equals("doreach")) {
doReach = b;
}
else {
mainLog.println("\nWarning: option \""+option+"\" not supported by Explicit2MTBDD translator.");
}
}
public void setOption(String option, int i)
{
mainLog.println("\nWarning: option \""+option+"\" not supported by Explicit2MTBDD translator.");
}
public void setOption(String option, String s)
{
mainLog.println("\nWarning: option \""+option+"\" not supported by Explicit2MTBDD translator.");
}
// build state space // build state space
public ModulesFile buildStates() throws PrismException public ModulesFile buildStates() throws PrismException
@ -461,20 +436,16 @@ public class Explicit2MTBDD
// mainLog.println(); // mainLog.println();
// JDD.Deref(tmp); // JDD.Deref(tmp);
// calculate dd for initial state
start = JDD.Constant(1);
for (i = 0; i < numVars; i++) {
tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
start = JDD.And(start, tmp);
}
// compute state rewards // compute state rewards
computeStateRewards(); computeStateRewards();
// do reachability (or not!)
if (doReach) {
doReachability();
}
else {
skipReachability();
}
// find any deadlocks
findDeadlocks();
int numModules = 1; // just one module int numModules = 1; // just one module
String moduleNames[] = modulesFile.getModuleNames(); // whose name is stored here String moduleNames[] = modulesFile.getModuleNames(); // whose name is stored here
Values constantValues = new Values(); // no constants Values constantValues = new Values(); // no constants
@ -485,22 +456,42 @@ public class Explicit2MTBDD
// create new Model object to be returned // create new Model object to be returned
if (type == ModulesFile.PROBABILISTIC) { if (type == ModulesFile.PROBABILISTIC) {
model = new ProbModel(trans, trans01, start, reach, deadlocks, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
model = new ProbModel(trans, start, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
else if (type == ModulesFile.NONDETERMINISTIC) { else if (type == ModulesFile.NONDETERMINISTIC) {
model = new NondetModel(trans, trans01, start, reach, deadlocks, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars,
model = new NondetModel(trans, start, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars,
allDDSynchVars, allDDSchedVars, allDDChoiceVars, allDDNondetVars, ddVarNames, allDDSynchVars, allDDSchedVars, allDDChoiceVars, allDDNondetVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
else if (type == ModulesFile.STOCHASTIC) { else if (type == ModulesFile.STOCHASTIC) {
model = new StochModel(trans, trans01, start, reach, deadlocks, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
model = new StochModel(trans, start, stateRewardsArray, transRewardsArray, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
// do reachability (or not)
if (prism.getDoReach()) {
mainLog.print("\nComputing reachable states...\n");
model.doReachability(prism.getExtraReachInfo());
model.filterReachableStates();
}
else {
mainLog.print("\nSkipping reachable state computation.\n");
model.skipReachability();
model.filterReachableStates();
}
// Print some info (if extraddinfo flag on)
if (prism.getExtraDDInfo()) {
mainLog.print("Reach: " + JDD.GetNumNodes(model.getReach()) + " nodes\n");
}
// find any deadlocks
model.findDeadlocks();
// deref spare dds // deref spare dds
JDD.Deref(moduleIdentities[0]); JDD.Deref(moduleIdentities[0]);
JDD.Deref(moduleRangeDDs[0]); JDD.Deref(moduleRangeDDs[0]);
@ -893,139 +884,6 @@ public class Explicit2MTBDD
throw new PrismException("Error detected at line " + lineNum + " of states file \"" + statesFile + "\""); throw new PrismException("Error detected at line " + lineNum + " of states file \"" + statesFile + "\"");
} }
} }
// do reachability
private void doReachability()
{
int i;
JDDNode tmp;
// calculate dd for initial state
start = JDD.Constant(1);
for (i = 0; i < numVars; i++) {
tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
start = JDD.And(start, tmp);
}
// calculate 0-1 version of trans
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// remove any nondeterminism
if (type == ModulesFile.NONDETERMINISTIC) {
JDD.Ref(trans01);
tmp = JDD.MaxAbstract(trans01, allDDNondetVars);
}
else {
JDD.Ref(trans01);
tmp = trans01;
}
// compute reachable states
mainLog.print("\nComputing reachable states...\n");
reach = PrismMTBDD.Reachability(tmp, allDDRowVars, allDDColVars, start);
JDD.Deref(tmp);
// remove non-reachable states from transition matrix
JDD.Ref(reach);
trans = JDD.Apply(JDD.TIMES, reach, trans);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
trans = JDD.Apply(JDD.TIMES, tmp, trans);
// recalculate 0-1 version of trans
JDD.Deref(trans01);
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// remove non-reachable states from states rewards vector
JDD.Ref(reach);
stateRewards = JDD.Apply(JDD.TIMES, reach, stateRewards);
// remove non-reachable states from transition reward matrix
JDD.Ref(reach);
transRewards = JDD.Apply(JDD.TIMES, reach, transRewards);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
transRewards = JDD.Apply(JDD.TIMES, tmp, transRewards);
}
// this method allows you to skip the reachability phase
// there are two versions - one which actually does skip it
// and one which does it anyway but doesn't filter out the
// unreachable states from the transition matrix.
// these are only here for experimental purposes - not general use.
// (do reach but don't filter)
// private void skipReachability()
// {
// int i;
// JDDNode tmp;
//
// // calculate dd for initial state
// start = JDD.Constant(1);
// for (i = 0; i < numVars; i++) {
// tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
// start = JDD.And(start, tmp);
// }
//
// // calculate 0-1 version of trans
// JDD.Ref(trans);
// trans01 = JDD.GreaterThan(trans, 0);
//
// // remove any nondeterminism
// if (type == ModulesFile.NONDETERMINISTIC) {
// JDD.Ref(trans01);
// tmp = JDD.MaxAbstract(trans01, allDDNondetVars);
// }
// else {
// JDD.Ref(trans01);
// tmp = trans01;
// }
//
// // compute reachable states
// mainLog.print("\nComputing reachable states...\n");
// reach = PrismMTBDD.Reachability(tmp, allDDRowVars, allDDColVars, start);
// JDD.Deref(tmp);
// }
// (no reach and no filter)
private void skipReachability()
{
int i;
JDDNode tmp;
// calculate dd for initial state
start = JDD.Constant(1);
for (i = 0; i < numVars; i++) {
tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
start = JDD.And(start, tmp);
}
// calculate 0-1 version of trans
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// don't compute reachable states - assume all reachable
reach = JDD.Constant(1);
}
private void findDeadlocks()
{
// find states with at least one transition
JDD.Ref(trans01);
deadlocks = JDD.ThereExists(trans01, allDDColVars);
if (type == ModulesFile.NONDETERMINISTIC) {
deadlocks = JDD.ThereExists(deadlocks, allDDNondetVars);
}
// find reachable states with no transitions
JDD.Ref(reach);
deadlocks = JDD.And(reach, JDD.Not(deadlocks));
}
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

5
prism/src/prism/Model.java

@ -98,6 +98,11 @@ public interface Model
ODDNode getODD(); ODDNode getODD();
void doReachability();
void doReachability(boolean extraReachInfo);
void skipReachability();
void filterReachableStates();
void findDeadlocks();
void fixDeadlocks(); void fixDeadlocks();
void printTrans(); void printTrans();
void printTrans01(); void printTrans01();

173
prism/src/prism/Modules2MTBDD.java

@ -31,7 +31,6 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import jdd.*; import jdd.*;
import mtbdd.*;
import parser.*; import parser.*;
import parser.ast.*; import parser.ast.*;
@ -78,10 +77,7 @@ public class Modules2MTBDD
// dds/dd vars - whole system // dds/dd vars - whole system
private JDDNode trans; // transition matrix dd private JDDNode trans; // transition matrix dd
private JDDNode range; // dd giving range for system private JDDNode range; // dd giving range for system
private JDDNode trans01; // 0-1 transition matrix dd
private JDDNode start; // dd for start state private JDDNode start; // dd for start state
private JDDNode reach; // dd of reachable states
private JDDNode deadlocks; // dd of deadlock states
private JDDNode stateRewards[]; // dds for state rewards private JDDNode stateRewards[]; // dds for state rewards
private JDDNode transRewards[]; // dds for transition rewards private JDDNode transRewards[]; // dds for transition rewards
private JDDVars allDDRowVars; // all dd vars (rows) private JDDVars allDDRowVars; // all dd vars (rows)
@ -225,16 +221,8 @@ public class Modules2MTBDD
mainLog.print(JDD.GetNumTerminals(trans) + " terminal)\n"); mainLog.print(JDD.GetNumTerminals(trans) + " terminal)\n");
} }
// do reachability (or not!)
if (prism.getDoReach()) {
doReachability();
}
else {
skipReachability();
}
// find any deadlocks
findDeadlocks();
// build bdd for initial state(s)
buildInitialStates();
// store reward struct names // store reward struct names
rewardStructNames = new String[numRewardStructs]; rewardStructNames = new String[numRewardStructs];
@ -244,22 +232,42 @@ public class Modules2MTBDD
// create new Model object to be returned // create new Model object to be returned
if (type == ModulesFile.PROBABILISTIC) { if (type == ModulesFile.PROBABILISTIC) {
model = new ProbModel(trans, trans01, start, reach, deadlocks, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
model = new ProbModel(trans, start, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
else if (type == ModulesFile.NONDETERMINISTIC) { else if (type == ModulesFile.NONDETERMINISTIC) {
model = new NondetModel(trans, trans01, start, reach, deadlocks, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars,
model = new NondetModel(trans, start, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars,
allDDSynchVars, allDDSchedVars, allDDChoiceVars, allDDNondetVars, ddVarNames, allDDSynchVars, allDDSchedVars, allDDChoiceVars, allDDNondetVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
else if (type == ModulesFile.STOCHASTIC) { else if (type == ModulesFile.STOCHASTIC) {
model = new StochModel(trans, trans01, start, reach, deadlocks, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
model = new StochModel(trans, start, stateRewards, transRewards, rewardStructNames, allDDRowVars, allDDColVars, ddVarNames,
numModules, moduleNames, moduleDDRowVars, moduleDDColVars, numModules, moduleNames, moduleDDRowVars, moduleDDColVars,
numVars, varList, varDDRowVars, varDDColVars, constantValues); numVars, varList, varDDRowVars, varDDColVars, constantValues);
} }
// do reachability (or not)
if (prism.getDoReach()) {
mainLog.print("\nComputing reachable states...\n");
model.doReachability(prism.getExtraReachInfo());
model.filterReachableStates();
}
else {
mainLog.print("\nSkipping reachable state computation.\n");
model.skipReachability();
model.filterReachableStates();
}
// Print some info (if extraddinfo flag on)
if (prism.getExtraDDInfo()) {
mainLog.print("Reach: " + JDD.GetNumNodes(model.getReach()) + " nodes\n");
}
// find any deadlocks
model.findDeadlocks();
// deref spare dds // deref spare dds
globalDDRowVars.derefAll(); globalDDRowVars.derefAll();
globalDDColVars.derefAll(); globalDDColVars.derefAll();
@ -1929,15 +1937,14 @@ public class Modules2MTBDD
} }
} }
} }
// do reachability
private void doReachability() throws PrismException
// calculate dd for initial state(s)
private void buildInitialStates() throws PrismException
{ {
int i; int i;
JDDNode tmp; JDDNode tmp;
// calculate dd for initial state
// first, handle case where multiple initial states specified with init...endinit // first, handle case where multiple initial states specified with init...endinit
if (modulesFile.getInitialStates() != null) { if (modulesFile.getInitialStates() != null) {
start = translateExpression(modulesFile.getInitialStates()); start = translateExpression(modulesFile.getInitialStates());
@ -1953,130 +1960,6 @@ public class Modules2MTBDD
start = JDD.And(start, tmp); start = JDD.And(start, tmp);
} }
} }
// calculate 0-1 version of trans
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// remove any nondeterminism
if (type == ModulesFile.NONDETERMINISTIC) {
JDD.Ref(trans01);
tmp = JDD.MaxAbstract(trans01, allDDNondetVars);
}
else {
JDD.Ref(trans01);
tmp = trans01;
}
// compute reachable states
mainLog.print("\nComputing reachable states...\n");
reach = PrismMTBDD.Reachability(tmp, allDDRowVars, allDDColVars, start, prism.getExtraReachInfo()?1:0);
JDD.Deref(tmp);
// Print some info (if extraddinfo flag on)
if (prism.getExtraDDInfo()) {
mainLog.print("Reach: " + JDD.GetNumNodes(reach) + " nodes\n");
}
// remove non-reachable states from transition matrix
JDD.Ref(reach);
trans = JDD.Apply(JDD.TIMES, reach, trans);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
trans = JDD.Apply(JDD.TIMES, tmp, trans);
// recalculate 0-1 version of trans
JDD.Deref(trans01);
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// remove non-reachable states from state/transition rewards
for (i = 0; i < modulesFile.getNumRewardStructs(); i++) {
// state rewards vector
JDD.Ref(reach);
stateRewards[i] = JDD.Apply(JDD.TIMES, reach, stateRewards[i]);
// transition reward matrix
JDD.Ref(reach);
transRewards[i] = JDD.Apply(JDD.TIMES, reach, transRewards[i]);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
transRewards[i] = JDD.Apply(JDD.TIMES, tmp, transRewards[i]);
}
}
// this method allows you to skip the reachability phase
// there are two versions - one which actually does skip it
// and one which does it anyway but doesn't filter out the
// unreachable states from the transition matrix.
// these are only here for experimental purposes - not general use.
// (do reach but don't filter)
// private void skipReachability()
// {
// int i;
// JDDNode tmp;
//
// // calculate dd for initial state
// start = JDD.Constant(1);
// for (i = 0; i < numVars; i++) {
// tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
// start = JDD.And(start, tmp);
// }
//
// // calculate 0-1 version of trans
// JDD.Ref(trans);
// trans01 = JDD.GreaterThan(trans, 0);
//
// // remove any nondeterminism
// if (type == ModulesFile.NONDETERMINISTIC) {
// JDD.Ref(trans01);
// tmp = JDD.MaxAbstract(trans01, allDDNondetVars);
// }
// else {
// JDD.Ref(trans01);
// tmp = trans01;
// }
//
// // compute reachable states
// mainLog.print("\nComputing reachable states...\n");
// reach = PrismMTBDD.Reachability(tmp, allDDRowVars, allDDColVars, start);
// JDD.Deref(tmp);
// }
// (no reach and no filter)
private void skipReachability()
{
int i;
JDDNode tmp;
// calculate dd for initial state
start = JDD.Constant(1);
for (i = 0; i < numVars; i++) {
tmp = JDD.SetVectorElement(JDD.Constant(0), varDDRowVars[i], varList.getStart(i)-varList.getLow(i), 1);
start = JDD.And(start, tmp);
}
// calculate 0-1 version of trans
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// don't compute reachable states - assume all reachable
reach = JDD.Constant(1);
}
private void findDeadlocks()
{
// find states with at least one transition
JDD.Ref(trans01);
deadlocks = JDD.ThereExists(trans01, allDDColVars);
if (type == ModulesFile.NONDETERMINISTIC) {
deadlocks = JDD.ThereExists(deadlocks, allDDNondetVars);
}
// find reachable states with no transitions
JDD.Ref(reach);
deadlocks = JDD.And(reach, JDD.Not(deadlocks));
} }
} }

73
prism/src/prism/NondetModel.java

@ -112,28 +112,60 @@ public class NondetModel extends ProbModel
public String getTransName() public String getTransName()
{ {
return "Transition matrix";
return "Transition matrix";
} }
public String getTransSymbol() public String getTransSymbol()
{ {
return "S"; return "S";
} }
// constructor // constructor
public NondetModel(JDDNode tr, JDDNode tr01, JDDNode s, JDDNode r, JDDNode dl, JDDNode sr[], JDDNode trr[],
String rsn[], JDDVars arv, JDDVars acv, JDDVars asyv, JDDVars asv, JDDVars achv, JDDVars andv, Vector ddvn,
int nm, String[] mn, JDDVars[] mrv, JDDVars[] mcv, int nv, VarList vl, JDDVars[] vrv, JDDVars[] vcv,
Values cv)
public NondetModel(JDDNode tr, JDDNode s, JDDNode sr[], JDDNode trr[], String rsn[], JDDVars arv, JDDVars acv,
JDDVars asyv, JDDVars asv, JDDVars achv, JDDVars andv, Vector<String> ddvn, int nm, String[] mn,
JDDVars[] mrv, JDDVars[] mcv, int nv, VarList vl, JDDVars[] vrv, JDDVars[] vcv, Values cv)
{ {
super(tr, tr01, s, r, dl, sr, trr, rsn, arv, acv, ddvn, nm, mn, mrv, mcv, nv, vl, vrv, vcv, cv);
super(tr, s, sr, trr, rsn, arv, acv, ddvn, nm, mn, mrv, mcv, nv, vl, vrv, vcv, cv);
allDDSynchVars = asyv; allDDSynchVars = asyv;
allDDSchedVars = asv; allDDSchedVars = asv;
allDDChoiceVars = achv; allDDChoiceVars = achv;
allDDNondetVars = andv; allDDNondetVars = andv;
}
// do reachability
public void doReachability(boolean extraReachInfo)
{
JDDNode tmp;
// remove any nondeterminism
JDD.Ref(trans01);
tmp = JDD.MaxAbstract(trans01, allDDNondetVars);
// compute reachable states
reach = PrismMTBDD.Reachability(tmp, allDDRowVars, allDDColVars, start, extraReachInfo ? 1 : 0);
JDD.Deref(tmp);
// work out number of reachable states
numStates = JDD.GetNumMinterms(reach, allDDRowVars.n());
// build odd
odd = ODDUtils.BuildODD(reach, allDDRowVars);
// store reachable states in a StateList
reachStateList = new StateListMTBDD(reach, this);
}
// remove non-reachable states from various dds
// (and calculate num transitions, etc.)
// (and build mask)
public void filterReachableStates()
{
super.filterReachableStates();
// build mask for nondeterminstic choices // build mask for nondeterminstic choices
JDD.Ref(trans01); JDD.Ref(trans01);
JDD.Ref(reach); JDD.Ref(reach);
@ -144,6 +176,25 @@ public class NondetModel extends ProbModel
double d = JDD.GetNumMinterms(nondetMask, getNumDDRowVars() + getNumDDNondetVars()); double d = JDD.GetNumMinterms(nondetMask, getNumDDRowVars() + getNumDDNondetVars());
numChoices = ((Math.pow(2, getNumDDNondetVars())) * numStates) - d; numChoices = ((Math.pow(2, getNumDDNondetVars())) * numStates) - d;
} }
// identify any deadlock states
public void findDeadlocks()
{
// find states with at least one transition
JDD.Ref(trans01);
deadlocks = JDD.ThereExists(trans01, allDDColVars);
deadlocks = JDD.ThereExists(deadlocks, allDDNondetVars);
// find reachable states with no transitions
JDD.Ref(reach);
deadlocks = JDD.And(reach, JDD.Not(deadlocks));
// store deadlock states in a StateList
deadlockStateList = new StateListMTBDD(deadlocks, this);
}
// remove deadlocks by adding self-loops
public void fixDeadlocks() public void fixDeadlocks()
{ {
@ -248,8 +299,8 @@ public class NondetModel extends ProbModel
if (!explicit) { if (!explicit) {
// can only do explicit (sparse matrix based) export for mdps // can only do explicit (sparse matrix based) export for mdps
} else { } else {
PrismSparse.ExportMDP(trans, getTransSymbol(), allDDRowVars, allDDColVars, allDDNondetVars, odd, exportType,
(file != null) ? file.getPath() : null);
PrismSparse.ExportMDP(trans, getTransSymbol(), allDDRowVars, allDDColVars, allDDNondetVars, odd,
exportType, (file != null) ? file.getPath() : null);
} }
} }

3
prism/src/prism/Prism.java

@ -849,8 +849,7 @@ public class Prism implements PrismSettingsListener
public ModulesFile parseExplicitModel(File statesFile, File transFile, int typeOverride, String initString) throws PrismException public ModulesFile parseExplicitModel(File statesFile, File transFile, int typeOverride, String initString) throws PrismException
{ {
// create Explicit2MTBDD object // create Explicit2MTBDD object
exp2mtbdd = new Explicit2MTBDD(mainLog, techLog, statesFile, transFile, typeOverride, initString);
exp2mtbdd.setOption("doreach", getDoReach());
exp2mtbdd = new Explicit2MTBDD(this, statesFile, transFile, typeOverride, initString);
// build state space // build state space
return exp2mtbdd.buildStates(); return exp2mtbdd.buildStates();

2
prism/src/prism/PrismCL.java

@ -534,7 +534,7 @@ public class PrismCL
} }
// print model info // print model info
mainLog.println("\nType: " + model.getType());
mainLog.println("\nType: " + model.getTypeString());
mainLog.print("Modules: "); mainLog.print("Modules: ");
for (i = 0; i < model.getNumModules(); i++) { for (i = 0; i < model.getNumModules(); i++) {
mainLog.print(model.getModuleName(i) + " "); mainLog.print(model.getModuleName(i) + " ");

125
prism/src/prism/ProbModel.java

@ -364,30 +364,27 @@ public class ProbModel implements Model
{ {
return odd; return odd;
} }
public String getTransName() public String getTransName()
{ {
return "Transition matrix";
return "Transition matrix";
} }
public String getTransSymbol() public String getTransSymbol()
{ {
return "P"; return "P";
} }
// constructor // constructor
public ProbModel(JDDNode tr, JDDNode tr01, JDDNode s, JDDNode r, JDDNode dl, JDDNode sr[], JDDNode trr[],
String rsn[], JDDVars arv, JDDVars acv, Vector<String> ddvn, int nm, String[] mn, JDDVars[] mrv, JDDVars[] mcv,
int nv, VarList vl, JDDVars[] vrv, JDDVars[] vcv, Values cv)
public ProbModel(JDDNode tr, JDDNode s, JDDNode sr[], JDDNode trr[], String rsn[], JDDVars arv, JDDVars acv,
Vector<String> ddvn, int nm, String[] mn, JDDVars[] mrv, JDDVars[] mcv, int nv, VarList vl, JDDVars[] vrv,
JDDVars[] vcv, Values cv)
{ {
int i; int i;
trans = tr; trans = tr;
trans01 = tr01;
start = s; start = s;
reach = r;
deadlocks = dl;
fixdl = JDD.Constant(0); fixdl = JDD.Constant(0);
stateRewards = sr; stateRewards = sr;
transRewards = trr; transRewards = trr;
@ -415,26 +412,112 @@ public class ProbModel implements Model
gtol[i] = gtol[i] * gtol[i + 1]; gtol[i] = gtol[i] * gtol[i + 1];
} }
// work out number of states
numStates = JDD.GetNumMinterms(reach, allDDRowVars.n());
// calculate 0-1 version of trans
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// work out number of initial states
numStartStates = JDD.GetNumMinterms(start, allDDRowVars.n()); numStartStates = JDD.GetNumMinterms(start, allDDRowVars.n());
// work out number of transitions
numTransitions = JDD.GetNumMinterms(trans01, getNumDDVarsInTrans());
// store initial states in a StateList
startStateList = new StateListMTBDD(start, this);
}
// do reachability
public void doReachability()
{
doReachability(false);
}
public void doReachability(boolean extraReachInfo)
{
// compute reachable states
reach = PrismMTBDD.Reachability(trans01, allDDRowVars, allDDColVars, start, extraReachInfo ? 1 : 0);
// work out number of reachable states
numStates = JDD.GetNumMinterms(reach, allDDRowVars.n());
// build odd
odd = ODDUtils.BuildODD(reach, allDDRowVars);
// store reachable states in a StateList
reachStateList = new StateListMTBDD(reach, this);
}
// this method allows you to skip the reachability phase
// it is only here for experimental purposes - not general use.
public void skipReachability()
{
// don't compute reachable states - assume all reachable
reach = JDD.Constant(1);
// work out number of reachable states
numStates = Math.pow(2, allDDRowVars.n());
// build odd // build odd
odd = ODDUtils.BuildODD(reach, allDDRowVars); odd = ODDUtils.BuildODD(reach, allDDRowVars);
// store reachable states in a StateList // store reachable states in a StateList
reachStateList = new StateListMTBDD(reach, this); reachStateList = new StateListMTBDD(reach, this);
}
// remove non-reachable states from various dds
// (and calculate num transitions)
public void filterReachableStates()
{
int i;
JDDNode tmp;
// remove non-reachable states from transition matrix
JDD.Ref(reach);
trans = JDD.Apply(JDD.TIMES, reach, trans);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
trans = JDD.Apply(JDD.TIMES, tmp, trans);
// recalculate 0-1 version of trans
JDD.Deref(trans01);
JDD.Ref(trans);
trans01 = JDD.GreaterThan(trans, 0);
// remove non-reachable states from state/transition rewards
for (i = 0; i < stateRewards.length; i++) {
// state rewards vector
JDD.Ref(reach);
stateRewards[i] = JDD.Apply(JDD.TIMES, reach, stateRewards[i]);
// transition reward matrix
JDD.Ref(reach);
transRewards[i] = JDD.Apply(JDD.TIMES, reach, transRewards[i]);
JDD.Ref(reach);
tmp = JDD.PermuteVariables(reach, allDDRowVars, allDDColVars);
transRewards[i] = JDD.Apply(JDD.TIMES, tmp, transRewards[i]);
}
// work out number of transitions
numTransitions = JDD.GetNumMinterms(trans01, getNumDDVarsInTrans());
}
// identify any deadlock states
public void findDeadlocks()
{
// find states with at least one transition
JDD.Ref(trans01);
deadlocks = JDD.ThereExists(trans01, allDDColVars);
// find reachable states with no transitions
JDD.Ref(reach);
deadlocks = JDD.And(reach, JDD.Not(deadlocks));
// store deadlock states in a StateList // store deadlock states in a StateList
deadlockStateList = new StateListMTBDD(deadlocks, this); deadlockStateList = new StateListMTBDD(deadlocks, this);
// store initial states in a StateList
startStateList = new StateListMTBDD(start, this);
} }
// remove deadlocks by adding self-loops
public void fixDeadlocks() public void fixDeadlocks()
{ {
JDDNode tmp; JDDNode tmp;
@ -530,11 +613,11 @@ public class ProbModel implements Model
public void exportToFile(int exportType, boolean explicit, File file) throws FileNotFoundException public void exportToFile(int exportType, boolean explicit, File file) throws FileNotFoundException
{ {
if (!explicit) { if (!explicit) {
PrismMTBDD.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType, (file != null) ? file
.getPath() : null);
PrismMTBDD.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType,
(file != null) ? file.getPath() : null);
} else { } else {
PrismSparse.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType, (file != null) ? file
.getPath() : null);
PrismSparse.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType,
(file != null) ? file.getPath() : null);
} }
} }

14
prism/src/prism/StochModel.java

@ -51,20 +51,20 @@ public class StochModel extends ProbModel
public String getTransName() public String getTransName()
{ {
return "Rate matrix";
return "Rate matrix";
} }
public String getTransSymbol() public String getTransSymbol()
{ {
return "R"; return "R";
} }
// constructor // constructor
public StochModel(JDDNode tr, JDDNode tr01, JDDNode s, JDDNode r, JDDNode dl, JDDNode sr[], JDDNode trr[],
String rsn[], JDDVars arv, JDDVars acv, Vector ddvn, int nm, String[] mn, JDDVars[] mrv, JDDVars[] mcv,
int nv, VarList vl, JDDVars[] vrv, JDDVars[] vcv, Values cv)
public StochModel(JDDNode tr, JDDNode s, JDDNode sr[], JDDNode trr[], String rsn[], JDDVars arv, JDDVars acv,
Vector<String> ddvn, int nm, String[] mn, JDDVars[] mrv, JDDVars[] mcv, int nv, VarList vl, JDDVars[] vrv,
JDDVars[] vcv, Values cv)
{ {
super(tr, tr01, s, r, dl, sr, trr, rsn, arv, acv, ddvn, nm, mn, mrv, mcv, nv, vl, vrv, vcv, cv);
super(tr, s, sr, trr, rsn, arv, acv, ddvn, nm, mn, mrv, mcv, nv, vl, vrv, vcv, cv);
} }
} }
Loading…
Cancel
Save