|
|
@ -35,136 +35,354 @@ import mtbdd.*; |
|
|
import parser.*; |
|
|
import parser.*; |
|
|
import sparse.*; |
|
|
import sparse.*; |
|
|
|
|
|
|
|
|
// class to store an instance of a fully probabilistic model (mtbdds) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Class to store a PRISM model which is a DTMC |
|
|
|
|
|
*/ |
|
|
public class ProbModel implements Model |
|
|
public class ProbModel implements Model |
|
|
{ |
|
|
{ |
|
|
// model info |
|
|
// model info |
|
|
|
|
|
|
|
|
// type |
|
|
|
|
|
private static final String type = "Probabilistic (DTMC)"; |
|
|
|
|
|
|
|
|
|
|
|
// modules |
|
|
// modules |
|
|
private int numModules; // number of modules |
|
|
|
|
|
private String[] moduleNames; // module names |
|
|
|
|
|
|
|
|
protected int numModules; // number of modules |
|
|
|
|
|
protected String[] moduleNames; // module names |
|
|
// vars/consts |
|
|
// vars/consts |
|
|
private int numVars; // total number of module variables |
|
|
|
|
|
private VarList varList; // list of module variables |
|
|
|
|
|
private long[] gtol; // numbers for use by globalToLocal |
|
|
|
|
|
private Values constantValues; // values of constants |
|
|
|
|
|
|
|
|
protected int numVars; // total number of module variables |
|
|
|
|
|
protected VarList varList; // list of module variables |
|
|
|
|
|
protected long[] gtol; // numbers for use by globalToLocal |
|
|
|
|
|
protected Values constantValues; // values of constants |
|
|
// rewards |
|
|
// rewards |
|
|
private int numRewardStructs; // number of reward structs |
|
|
|
|
|
private String[] rewardStructNames; // reward struct names |
|
|
|
|
|
|
|
|
protected int numRewardStructs; // number of reward structs |
|
|
|
|
|
protected String[] rewardStructNames; // reward struct names |
|
|
// stats |
|
|
// stats |
|
|
private double numStates; // number of states |
|
|
|
|
|
private double numTransitions; // number of transitions |
|
|
|
|
|
private double numStartStates; // number of initial states |
|
|
|
|
|
|
|
|
protected double numStates; // number of states |
|
|
|
|
|
protected double numTransitions; // number of transitions |
|
|
|
|
|
protected double numStartStates; // number of initial states |
|
|
// reachable state list |
|
|
// reachable state list |
|
|
private StateListMTBDD reachStateList = null; |
|
|
|
|
|
|
|
|
protected StateListMTBDD reachStateList = null; |
|
|
// deadlock state list |
|
|
// deadlock state list |
|
|
private StateListMTBDD deadlockStateList = null; |
|
|
|
|
|
|
|
|
protected StateListMTBDD deadlockStateList = null; |
|
|
// initial state list |
|
|
// initial state list |
|
|
private StateListMTBDD startStateList = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected StateListMTBDD startStateList = null; |
|
|
|
|
|
|
|
|
// mtbdd stuff |
|
|
// mtbdd stuff |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dds |
|
|
// dds |
|
|
|
|
|
|
|
|
private JDDNode trans; // transition matrix dd |
|
|
|
|
|
private JDDNode trans01; // 0-1 transition matrix dd |
|
|
|
|
|
private JDDNode start; // start state dd |
|
|
|
|
|
private JDDNode reach; // reachable states dd |
|
|
|
|
|
private JDDNode deadlocks; // deadlock states dd |
|
|
|
|
|
private JDDNode fixdl; // fixed deadlock states dd |
|
|
|
|
|
private JDDNode stateRewards[]; // state rewards dds |
|
|
|
|
|
private JDDNode transRewards[]; // transition rewards dds |
|
|
|
|
|
|
|
|
protected JDDNode trans; // transition matrix dd |
|
|
|
|
|
protected JDDNode trans01; // 0-1 transition matrix dd |
|
|
|
|
|
protected JDDNode start; // start state dd |
|
|
|
|
|
protected JDDNode reach; // reachable states dd |
|
|
|
|
|
protected JDDNode deadlocks; // deadlock states dd |
|
|
|
|
|
protected JDDNode fixdl; // fixed deadlock states dd |
|
|
|
|
|
protected JDDNode stateRewards[]; // state rewards dds |
|
|
|
|
|
protected JDDNode transRewards[]; // transition rewards dds |
|
|
// dd vars |
|
|
// dd vars |
|
|
private JDDVars[] varDDRowVars; // dd vars for each module variable (rows) |
|
|
|
|
|
private JDDVars[] varDDColVars; // dd vars for each module variable (cols) |
|
|
|
|
|
private JDDVars[] moduleDDRowVars; // dd vars for each module (rows) |
|
|
|
|
|
private JDDVars[] moduleDDColVars; // dd vars for each module (cols) |
|
|
|
|
|
private JDDVars allDDRowVars; // all dd vars (rows) |
|
|
|
|
|
private JDDVars allDDColVars; // all dd vars (cols) |
|
|
|
|
|
|
|
|
protected JDDVars[] varDDRowVars; // dd vars for each module variable (rows) |
|
|
|
|
|
protected JDDVars[] varDDColVars; // dd vars for each module variable (cols) |
|
|
|
|
|
protected JDDVars[] moduleDDRowVars; // dd vars for each module (rows) |
|
|
|
|
|
protected JDDVars[] moduleDDColVars; // dd vars for each module (cols) |
|
|
|
|
|
protected JDDVars allDDRowVars; // all dd vars (rows) |
|
|
|
|
|
protected JDDVars allDDColVars; // all dd vars (cols) |
|
|
// names for all dd vars used |
|
|
// names for all dd vars used |
|
|
private Vector ddVarNames; |
|
|
|
|
|
|
|
|
protected Vector ddVarNames; |
|
|
|
|
|
|
|
|
private ODDNode odd; // odd |
|
|
|
|
|
|
|
|
protected ODDNode odd; // odd |
|
|
|
|
|
|
|
|
// accessor methods |
|
|
// accessor methods |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// model info |
|
|
// model info |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// type |
|
|
// type |
|
|
public String getType() { return type; } |
|
|
|
|
|
|
|
|
public int getType() |
|
|
|
|
|
{ |
|
|
|
|
|
return Model.DTMC; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getTypeString() |
|
|
|
|
|
{ |
|
|
|
|
|
return "Probabilistic (DTMC)"; // TODO: Change this after regression testing |
|
|
|
|
|
//return "DTMC"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// modules |
|
|
// modules |
|
|
public int getNumModules() { return numModules; } |
|
|
|
|
|
public String[] getModuleNames() { return moduleNames; } |
|
|
|
|
|
public String getModuleName(int i) { return moduleNames[i]; } |
|
|
|
|
|
|
|
|
public int getNumModules() |
|
|
|
|
|
{ |
|
|
|
|
|
return numModules; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String[] getModuleNames() |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleNames; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getModuleName(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleNames[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// vars |
|
|
// vars |
|
|
public int getNumVars() { return numVars; } |
|
|
|
|
|
public VarList getVarList() { return varList; } |
|
|
|
|
|
public String getVarName(int i) { return varList.getName(i); } |
|
|
|
|
|
public int getVarIndex(String n) { return varList.getIndex(n); } |
|
|
|
|
|
public int getVarModule(int i) { return varList.getModule(i); } |
|
|
|
|
|
public int getVarLow(int i) { return varList.getLow(i); } |
|
|
|
|
|
public int getVarHigh(int i) { return varList.getHigh(i); } |
|
|
|
|
|
public int getVarRange(int i) { return varList.getRange(i); } |
|
|
|
|
|
public Values getConstantValues() { return constantValues; } |
|
|
|
|
|
|
|
|
public int getNumVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return numVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public VarList getVarList() |
|
|
|
|
|
{ |
|
|
|
|
|
return varList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getVarName(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getName(i); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getVarIndex(String n) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getIndex(n); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getVarModule(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getModule(i); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getVarLow(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getLow(i); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getVarHigh(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getHigh(i); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getVarRange(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varList.getRange(i); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Values getConstantValues() |
|
|
|
|
|
{ |
|
|
|
|
|
return constantValues; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// rewards |
|
|
// rewards |
|
|
public int getNumRewardStructs() { return numRewardStructs; } |
|
|
|
|
|
|
|
|
public int getNumRewardStructs() |
|
|
|
|
|
{ |
|
|
|
|
|
return numRewardStructs; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// stats |
|
|
// stats |
|
|
public long getNumStates() { return (numStates>Long.MAX_VALUE) ? -1 : Math.round(numStates); } |
|
|
|
|
|
public long getNumTransitions() { return (numTransitions>Long.MAX_VALUE) ? -1 : Math.round(numTransitions); } |
|
|
|
|
|
public long getNumStartStates() { return (numStartStates>Long.MAX_VALUE) ? -1 : Math.round(numStartStates); } |
|
|
|
|
|
|
|
|
public long getNumStates() |
|
|
|
|
|
{ |
|
|
|
|
|
return (numStates > Long.MAX_VALUE) ? -1 : Math.round(numStates); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getNumTransitions() |
|
|
|
|
|
{ |
|
|
|
|
|
return (numTransitions > Long.MAX_VALUE) ? -1 : Math.round(numTransitions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public long getNumStartStates() |
|
|
|
|
|
{ |
|
|
|
|
|
return (numStartStates > Long.MAX_VALUE) ? -1 : Math.round(numStartStates); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// additional methods to get stats as strings |
|
|
// additional methods to get stats as strings |
|
|
public String getNumStatesString() { return PrismUtils.bigIntToString(numStates); } |
|
|
|
|
|
public String getNumTransitionsString() { return PrismUtils.bigIntToString(numTransitions); } |
|
|
|
|
|
public String getNumStartStatesString() { return PrismUtils.bigIntToString(numStartStates); } |
|
|
|
|
|
|
|
|
public String getNumStatesString() |
|
|
|
|
|
{ |
|
|
|
|
|
return PrismUtils.bigIntToString(numStates); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getNumTransitionsString() |
|
|
|
|
|
{ |
|
|
|
|
|
return PrismUtils.bigIntToString(numTransitions); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getNumStartStatesString() |
|
|
|
|
|
{ |
|
|
|
|
|
return PrismUtils.bigIntToString(numStartStates); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// lists of states |
|
|
// lists of states |
|
|
public StateList getReachableStates() { return reachStateList; } |
|
|
|
|
|
public StateList getDeadlockStates() { return deadlockStateList; } |
|
|
|
|
|
public StateList getStartStates() { return startStateList; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StateList getReachableStates() |
|
|
|
|
|
{ |
|
|
|
|
|
return reachStateList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public StateList getDeadlockStates() |
|
|
|
|
|
{ |
|
|
|
|
|
return deadlockStateList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public StateList getStartStates() |
|
|
|
|
|
{ |
|
|
|
|
|
return startStateList; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// mtbdd stuff |
|
|
// mtbdd stuff |
|
|
|
|
|
|
|
|
public JDDNode getTrans() { return trans; } |
|
|
|
|
|
public JDDNode getTrans01() { return trans01; } |
|
|
|
|
|
public JDDNode getStart() { return start; } |
|
|
|
|
|
public JDDNode getReach() { return reach; } |
|
|
|
|
|
public JDDNode getDeadlocks() { return deadlocks; } |
|
|
|
|
|
public JDDNode getFixedDeadlocks() { return fixdl; } |
|
|
|
|
|
public JDDNode getStateRewards() { return getStateRewards(0); } |
|
|
|
|
|
public JDDNode getStateRewards(int i) { return (i>=0&&i<numRewardStructs) ? stateRewards[i] : null; } |
|
|
|
|
|
public JDDNode getStateRewards(String s) { for (int i=0;i<numRewardStructs;i++) if (rewardStructNames[i].equals(s)) return stateRewards[i]; return null; } |
|
|
|
|
|
public JDDNode getTransRewards() { return getTransRewards(0); } |
|
|
|
|
|
public JDDNode getTransRewards(int i) { return (i>=0&&i<numRewardStructs) ? transRewards[i] : null; } |
|
|
|
|
|
public JDDNode getTransRewards(String s) { for (int i=0;i<numRewardStructs;i++) if (rewardStructNames[i].equals(s)) return transRewards[i]; return null; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getTrans() |
|
|
|
|
|
{ |
|
|
|
|
|
return trans; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getTrans01() |
|
|
|
|
|
{ |
|
|
|
|
|
return trans01; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getStart() |
|
|
|
|
|
{ |
|
|
|
|
|
return start; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getReach() |
|
|
|
|
|
{ |
|
|
|
|
|
return reach; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getDeadlocks() |
|
|
|
|
|
{ |
|
|
|
|
|
return deadlocks; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getFixedDeadlocks() |
|
|
|
|
|
{ |
|
|
|
|
|
return fixdl; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getStateRewards() |
|
|
|
|
|
{ |
|
|
|
|
|
return getStateRewards(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getStateRewards(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return (i >= 0 && i < numRewardStructs) ? stateRewards[i] : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getStateRewards(String s) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < numRewardStructs; i++) |
|
|
|
|
|
if (rewardStructNames[i].equals(s)) |
|
|
|
|
|
return stateRewards[i]; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getTransRewards() |
|
|
|
|
|
{ |
|
|
|
|
|
return getTransRewards(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getTransRewards(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return (i >= 0 && i < numRewardStructs) ? transRewards[i] : null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDNode getTransRewards(String s) |
|
|
|
|
|
{ |
|
|
|
|
|
for (int i = 0; i < numRewardStructs; i++) |
|
|
|
|
|
if (rewardStructNames[i].equals(s)) |
|
|
|
|
|
return transRewards[i]; |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// dd vars |
|
|
// dd vars |
|
|
public JDDVars[] getVarDDRowVars() { return varDDRowVars; } |
|
|
|
|
|
public JDDVars[] getVarDDColVars() { return varDDColVars; } |
|
|
|
|
|
public JDDVars getVarDDRowVars(int i) { return varDDRowVars[i]; } |
|
|
|
|
|
public JDDVars getVarDDColVars(int i) { return varDDColVars[i]; } |
|
|
|
|
|
public JDDVars[] getModuleDDRowVars() { return moduleDDRowVars; } |
|
|
|
|
|
public JDDVars[] getModuleDDColVars() { return moduleDDColVars; } |
|
|
|
|
|
public JDDVars getModuleDDRowVars(int i) { return moduleDDRowVars[i]; } |
|
|
|
|
|
public JDDVars getModuleDDColVars(int i) { return moduleDDColVars[i]; } |
|
|
|
|
|
public JDDVars getAllDDRowVars() { return allDDRowVars; } |
|
|
|
|
|
public JDDVars getAllDDColVars() { return allDDColVars; } |
|
|
|
|
|
|
|
|
public JDDVars[] getVarDDRowVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return varDDRowVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars[] getVarDDColVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return varDDColVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getVarDDRowVars(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varDDRowVars[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getVarDDColVars(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return varDDColVars[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars[] getModuleDDRowVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleDDRowVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars[] getModuleDDColVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleDDColVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getModuleDDRowVars(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleDDRowVars[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getModuleDDColVars(int i) |
|
|
|
|
|
{ |
|
|
|
|
|
return moduleDDColVars[i]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getAllDDRowVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return allDDRowVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JDDVars getAllDDColVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return allDDColVars; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// additional useful methods to do with dd vars |
|
|
// additional useful methods to do with dd vars |
|
|
public int getNumDDRowVars() { return allDDRowVars.n(); } |
|
|
|
|
|
public int getNumDDColVars() { return allDDColVars.n(); } |
|
|
|
|
|
public int getNumDDVarsInTrans() { return allDDRowVars.n()*2; } |
|
|
|
|
|
public Vector getDDVarNames() { return ddVarNames; } |
|
|
|
|
|
|
|
|
public int getNumDDRowVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return allDDRowVars.n(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getNumDDColVars() |
|
|
|
|
|
{ |
|
|
|
|
|
return allDDColVars.n(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getNumDDVarsInTrans() |
|
|
|
|
|
{ |
|
|
|
|
|
return allDDRowVars.n() * 2; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Vector getDDVarNames() |
|
|
|
|
|
{ |
|
|
|
|
|
return ddVarNames; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ODDNode getODD() |
|
|
|
|
|
{ |
|
|
|
|
|
return odd; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ODDNode getODD() { return odd; } |
|
|
|
|
|
|
|
|
public String getTransName() |
|
|
|
|
|
{ |
|
|
|
|
|
return "Transition matrix"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// constructor |
|
|
|
|
|
|
|
|
public String getTransSymbol() |
|
|
|
|
|
{ |
|
|
|
|
|
return "P"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ProbModel(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) |
|
|
|
|
|
|
|
|
// constructor |
|
|
|
|
|
|
|
|
|
|
|
public ProbModel(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) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trans = tr; |
|
|
trans = tr; |
|
|
trans01 = tr01; |
|
|
trans01 = tr01; |
|
|
start = s; |
|
|
start = s; |
|
|
@ -187,40 +405,40 @@ public class ProbModel implements Model |
|
|
varDDRowVars = vrv; |
|
|
varDDRowVars = vrv; |
|
|
varDDColVars = vcv; |
|
|
varDDColVars = vcv; |
|
|
constantValues = cv; |
|
|
constantValues = cv; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// compute numbers for globalToLocal converter |
|
|
// compute numbers for globalToLocal converter |
|
|
gtol = new long[numVars]; |
|
|
gtol = new long[numVars]; |
|
|
for (i = 0; i < numVars; i++) { |
|
|
for (i = 0; i < numVars; i++) { |
|
|
gtol[i] = 1l << (varDDRowVars[i].getNumVars()); |
|
|
gtol[i] = 1l << (varDDRowVars[i].getNumVars()); |
|
|
} |
|
|
} |
|
|
for (i = numVars-2; i >= 0; i--) { |
|
|
|
|
|
gtol[i] = gtol[i] * gtol[i+1]; |
|
|
|
|
|
|
|
|
for (i = numVars - 2; i >= 0; i--) { |
|
|
|
|
|
gtol[i] = gtol[i] * gtol[i + 1]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// work out number of states |
|
|
// work out number of states |
|
|
numStates = JDD.GetNumMinterms(reach, allDDRowVars.n()); |
|
|
numStates = JDD.GetNumMinterms(reach, allDDRowVars.n()); |
|
|
numStartStates = JDD.GetNumMinterms(start, allDDRowVars.n()); |
|
|
numStartStates = JDD.GetNumMinterms(start, allDDRowVars.n()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// work out number of transitions |
|
|
// work out number of transitions |
|
|
numTransitions = JDD.GetNumMinterms(trans01, allDDRowVars.n()*2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
numTransitions = JDD.GetNumMinterms(trans01, getNumDDVarsInTrans()); |
|
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 |
|
|
// store initial states in a StateList |
|
|
startStateList = new StateListMTBDD(start, this); |
|
|
startStateList = new StateListMTBDD(start, this); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void fixDeadlocks() |
|
|
public void fixDeadlocks() |
|
|
{ |
|
|
{ |
|
|
JDDNode tmp; |
|
|
JDDNode tmp; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!deadlocks.equals(JDD.ZERO)) { |
|
|
if (!deadlocks.equals(JDD.ZERO)) { |
|
|
// remove deadlocks by adding self-loops |
|
|
// remove deadlocks by adding self-loops |
|
|
JDD.Ref(deadlocks); |
|
|
JDD.Ref(deadlocks); |
|
|
@ -234,165 +452,175 @@ public class ProbModel implements Model |
|
|
deadlocks = JDD.Constant(0); |
|
|
deadlocks = JDD.Constant(0); |
|
|
deadlockStateList = new StateListMTBDD(deadlocks, this); |
|
|
deadlockStateList = new StateListMTBDD(deadlocks, this); |
|
|
// update model stats |
|
|
// update model stats |
|
|
numTransitions = JDD.GetNumMinterms(trans01, getNumDDVarsInTrans()); |
|
|
|
|
|
|
|
|
numTransitions = JDD.GetNumMinterms(trans01, getNumDDVarsInTrans()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void printTrans() |
|
|
public void printTrans() |
|
|
{ |
|
|
{ |
|
|
// JDD.PrintMatrix(trans, allDDRowVars, allDDColVars); |
|
|
|
|
|
|
|
|
// JDD.PrintMatrix(trans, allDDRowVars, allDDColVars); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void printTrans01() |
|
|
public void printTrans01() |
|
|
{ |
|
|
{ |
|
|
// JDD.PrintMatrix(trans01, allDDRowVars, allDDColVars, JDD.ZERO_ONE); |
|
|
|
|
|
|
|
|
// JDD.PrintMatrix(trans01, allDDRowVars, allDDColVars, JDD.ZERO_ONE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void printTransInfo(PrismLog log) { printTransInfo(log, false); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void printTransInfo(PrismLog log) |
|
|
|
|
|
{ |
|
|
|
|
|
printTransInfo(log, false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public void printTransInfo(PrismLog log, boolean extra) |
|
|
public void printTransInfo(PrismLog log, boolean extra) |
|
|
{ |
|
|
{ |
|
|
int i, j, n; |
|
|
int i, j, n; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.print("States: " + getNumStatesString() + " (" + getNumStartStatesString() + " initial)" + "\n"); |
|
|
log.print("States: " + getNumStatesString() + " (" + getNumStartStatesString() + " initial)" + "\n"); |
|
|
log.print("Transitions: " + getNumTransitionsString() + "\n"); |
|
|
log.print("Transitions: " + getNumTransitionsString() + "\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.println(); |
|
|
log.println(); |
|
|
|
|
|
|
|
|
log.print("Transition matrix: "); |
|
|
|
|
|
log.print(JDD.GetNumNodes(trans) + " nodes ("); |
|
|
|
|
|
log.print(JDD.GetNumTerminals(trans) + " terminal), "); |
|
|
|
|
|
log.print(JDD.GetNumMintermsString(trans, getNumDDVarsInTrans()) + " minterms, "); |
|
|
|
|
|
log.print("vars: " + getNumDDRowVars() + "r/" + getNumDDColVars() + "c\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.print(getTransName() + ": " + JDD.GetInfoString(trans, getNumDDVarsInTrans())); |
|
|
|
|
|
log.print(", vars: " + getNumDDRowVars() + "r/" + getNumDDColVars() + "c\n"); |
|
|
if (extra) { |
|
|
if (extra) { |
|
|
log.print("DD vars (r/c):"); |
|
|
log.print("DD vars (r/c):"); |
|
|
n = allDDRowVars.getNumVars(); |
|
|
n = allDDRowVars.getNumVars(); |
|
|
for (i = 0; i < n; i++) { |
|
|
for (i = 0; i < n; i++) { |
|
|
j = allDDRowVars.getVarIndex(i); |
|
|
j = allDDRowVars.getVarIndex(i); |
|
|
log.print(" "+j+":"+ddVarNames.get(j)); |
|
|
|
|
|
|
|
|
log.print(" " + j + ":" + ddVarNames.get(j)); |
|
|
j = allDDColVars.getVarIndex(i); |
|
|
j = allDDColVars.getVarIndex(i); |
|
|
log.print(" "+j+":"+ddVarNames.get(j)); |
|
|
|
|
|
|
|
|
log.print(" " + j + ":" + ddVarNames.get(j)); |
|
|
} |
|
|
} |
|
|
log.println(); |
|
|
log.println(); |
|
|
log.print("Transition matrix terminals: " + JDD.GetTerminalsAndNumbersString(trans, getNumDDVarsInTrans())+"\n"); |
|
|
|
|
|
|
|
|
log.print(getTransName() + " terminals: " + JDD.GetTerminalsAndNumbersString(trans, getNumDDVarsInTrans()) |
|
|
|
|
|
+ "\n"); |
|
|
log.print("Reach: " + JDD.GetNumNodes(reach) + " nodes\n"); |
|
|
log.print("Reach: " + JDD.GetNumNodes(reach) + " nodes\n"); |
|
|
log.print("ODD: " + ODDUtils.GetNumODDNodes() + " nodes\n"); |
|
|
log.print("ODD: " + ODDUtils.GetNumODDNodes() + " nodes\n"); |
|
|
} |
|
|
} |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
if (stateRewards[i] != null && !stateRewards[i].equals(JDD.ZERO)) { |
|
|
if (stateRewards[i] != null && !stateRewards[i].equals(JDD.ZERO)) { |
|
|
log.print("State rewards ("+(i+1)+(("".equals(rewardStructNames[i]))?"":(":\""+rewardStructNames[i]+"\""))+"): "); |
|
|
|
|
|
|
|
|
log.print("State rewards (" + (i + 1) |
|
|
|
|
|
+ (("".equals(rewardStructNames[i])) ? "" : (":\"" + rewardStructNames[i] + "\"")) + "): "); |
|
|
log.print(JDD.GetNumNodes(stateRewards[i]) + " nodes ("); |
|
|
log.print(JDD.GetNumNodes(stateRewards[i]) + " nodes ("); |
|
|
log.print(JDD.GetNumTerminals(stateRewards[i]) + " terminal), "); |
|
|
log.print(JDD.GetNumTerminals(stateRewards[i]) + " terminal), "); |
|
|
log.print(JDD.GetNumMintermsString(stateRewards[i], getNumDDRowVars()) + " minterms\n"); |
|
|
log.print(JDD.GetNumMintermsString(stateRewards[i], getNumDDRowVars()) + " minterms\n"); |
|
|
if (extra) { |
|
|
if (extra) { |
|
|
log.print("State rewards terminals ("+(i+1)+(("".equals(rewardStructNames[i]))?"":(":\""+rewardStructNames[i]+"\""))+"): "); |
|
|
|
|
|
log.print(JDD.GetTerminalsAndNumbersString(stateRewards[i], getNumDDRowVars())+"\n"); |
|
|
|
|
|
|
|
|
log.print("State rewards terminals (" + (i + 1) |
|
|
|
|
|
+ (("".equals(rewardStructNames[i])) ? "" : (":\"" + rewardStructNames[i] + "\"")) + "): "); |
|
|
|
|
|
log.print(JDD.GetTerminalsAndNumbersString(stateRewards[i], getNumDDRowVars()) + "\n"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (transRewards[i] != null && !transRewards[i].equals(JDD.ZERO)) { |
|
|
if (transRewards[i] != null && !transRewards[i].equals(JDD.ZERO)) { |
|
|
log.print("Transition rewards ("+(i+1)+(("".equals(rewardStructNames[i]))?"":(":\""+rewardStructNames[i]+"\""))+"): "); |
|
|
|
|
|
|
|
|
log.print("Transition rewards (" + (i + 1) |
|
|
|
|
|
+ (("".equals(rewardStructNames[i])) ? "" : (":\"" + rewardStructNames[i] + "\"")) + "): "); |
|
|
log.print(JDD.GetNumNodes(transRewards[i]) + " nodes ("); |
|
|
log.print(JDD.GetNumNodes(transRewards[i]) + " nodes ("); |
|
|
log.print(JDD.GetNumTerminals(transRewards[i]) + " terminal), "); |
|
|
log.print(JDD.GetNumTerminals(transRewards[i]) + " terminal), "); |
|
|
log.print(JDD.GetNumMintermsString(transRewards[i], getNumDDVarsInTrans()) + " minterms\n"); |
|
|
log.print(JDD.GetNumMintermsString(transRewards[i], getNumDDVarsInTrans()) + " minterms\n"); |
|
|
if (extra) { |
|
|
if (extra) { |
|
|
log.print("Transition rewards terminals ("+(i+1)+(("".equals(rewardStructNames[i]))?"":(":\""+rewardStructNames[i]+"\""))+"): "); |
|
|
|
|
|
log.print(JDD.GetTerminalsAndNumbersString(transRewards[i], getNumDDVarsInTrans())+"\n"); |
|
|
|
|
|
|
|
|
log.print("Transition rewards terminals (" + (i + 1) |
|
|
|
|
|
+ (("".equals(rewardStructNames[i])) ? "" : (":\"" + rewardStructNames[i] + "\"")) + "): "); |
|
|
|
|
|
log.print(JDD.GetTerminalsAndNumbersString(transRewards[i], getNumDDVarsInTrans()) + "\n"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// export transition matrix to a file |
|
|
// export transition matrix to a file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, "P", allDDRowVars, allDDColVars, odd, exportType, (file != null)?file.getPath():null); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
PrismSparse.ExportMatrix(trans, "P", allDDRowVars, allDDColVars, odd, exportType, (file != null)?file.getPath():null); |
|
|
|
|
|
|
|
|
PrismMTBDD.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType, (file != null) ? file |
|
|
|
|
|
.getPath() : null); |
|
|
|
|
|
} else { |
|
|
|
|
|
PrismSparse.ExportMatrix(trans, getTransSymbol(), allDDRowVars, allDDColVars, odd, exportType, (file != null) ? file |
|
|
|
|
|
.getPath() : null); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// export state rewards vector to a file |
|
|
// export state rewards vector to a file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns string containing files used if there were more than 1, null otherwise |
|
|
// returns string containing files used if there were more than 1, null otherwise |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String exportStateRewardsToFile(int exportType, File file) throws FileNotFoundException, PrismException |
|
|
public String exportStateRewardsToFile(int exportType, File file) throws FileNotFoundException, PrismException |
|
|
{ |
|
|
{ |
|
|
if (numRewardStructs == 0) throw new PrismException("There are no state rewards to export"); |
|
|
|
|
|
|
|
|
if (numRewardStructs == 0) |
|
|
|
|
|
throw new PrismException("There are no state rewards to export"); |
|
|
int i; |
|
|
int i; |
|
|
String filename, allFilenames = ""; |
|
|
String filename, allFilenames = ""; |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
filename = (file != null) ? file.getPath() : null; |
|
|
filename = (file != null) ? file.getPath() : null; |
|
|
if (filename != null && numRewardStructs > 1) { |
|
|
if (filename != null && numRewardStructs > 1) { |
|
|
filename = PrismUtils.addCounterSuffixToFilename(filename, i); |
|
|
filename = PrismUtils.addCounterSuffixToFilename(filename, i); |
|
|
allFilenames += ((i>0)?", ":"") + filename; |
|
|
|
|
|
|
|
|
allFilenames += ((i > 0) ? ", " : "") + filename; |
|
|
} |
|
|
} |
|
|
PrismMTBDD.ExportVector(stateRewards[i], "c"+i, allDDRowVars, odd, exportType, filename); |
|
|
|
|
|
|
|
|
PrismMTBDD.ExportVector(stateRewards[i], "c" + i, allDDRowVars, odd, exportType, filename); |
|
|
} |
|
|
} |
|
|
return (allFilenames.length()>0) ? allFilenames : null; |
|
|
|
|
|
|
|
|
return (allFilenames.length() > 0) ? allFilenames : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// export transition rewards matrix to a file |
|
|
// export transition rewards matrix to a file |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// returns string containing files used if there were more than 1, null otherwise |
|
|
// returns string containing files used if there were more than 1, null otherwise |
|
|
|
|
|
|
|
|
public String exportTransRewardsToFile(int exportType, boolean explicit, File file) throws FileNotFoundException, PrismException |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String exportTransRewardsToFile(int exportType, boolean explicit, File file) throws FileNotFoundException, |
|
|
|
|
|
PrismException |
|
|
{ |
|
|
{ |
|
|
if (numRewardStructs == 0) throw new PrismException("There are no transition rewards to export"); |
|
|
|
|
|
|
|
|
if (numRewardStructs == 0) |
|
|
|
|
|
throw new PrismException("There are no transition rewards to export"); |
|
|
int i; |
|
|
int i; |
|
|
String filename, allFilenames = ""; |
|
|
String filename, allFilenames = ""; |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
for (i = 0; i < numRewardStructs; i++) { |
|
|
filename = (file != null) ? file.getPath() : null; |
|
|
filename = (file != null) ? file.getPath() : null; |
|
|
if (filename != null && numRewardStructs > 1) { |
|
|
if (filename != null && numRewardStructs > 1) { |
|
|
filename = PrismUtils.addCounterSuffixToFilename(filename, i); |
|
|
filename = PrismUtils.addCounterSuffixToFilename(filename, i); |
|
|
allFilenames += ((i>0)?", ":"") + filename; |
|
|
|
|
|
|
|
|
allFilenames += ((i > 0) ? ", " : "") + filename; |
|
|
} |
|
|
} |
|
|
if (!explicit) { |
|
|
if (!explicit) { |
|
|
PrismMTBDD.ExportMatrix(transRewards[i], "C"+i, allDDRowVars, allDDColVars, odd, exportType, filename); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
PrismSparse.ExportMatrix(transRewards[i], "C"+i, allDDRowVars, allDDColVars, odd, exportType, filename); |
|
|
|
|
|
|
|
|
PrismMTBDD |
|
|
|
|
|
.ExportMatrix(transRewards[i], "C" + i, allDDRowVars, allDDColVars, odd, exportType, filename); |
|
|
|
|
|
} else { |
|
|
|
|
|
PrismSparse.ExportMatrix(transRewards[i], "C" + i, allDDRowVars, allDDColVars, odd, exportType, |
|
|
|
|
|
filename); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return (allFilenames.length()>0) ? allFilenames : null; |
|
|
|
|
|
|
|
|
return (allFilenames.length() > 0) ? allFilenames : null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// convert global state index to local indices |
|
|
// convert global state index to local indices |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String globalToLocal(long x) |
|
|
public String globalToLocal(long x) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
String s = ""; |
|
|
String s = ""; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s += "("; |
|
|
s += "("; |
|
|
for (i = 0; i < numVars-1; i++) { |
|
|
|
|
|
s += ((x/gtol[i+1]) + varList.getLow(i)) + ","; |
|
|
|
|
|
x = x % gtol[i+1]; |
|
|
|
|
|
|
|
|
for (i = 0; i < numVars - 1; i++) { |
|
|
|
|
|
s += ((x / gtol[i + 1]) + varList.getLow(i)) + ","; |
|
|
|
|
|
x = x % gtol[i + 1]; |
|
|
} |
|
|
} |
|
|
s += (x + varList.getLow(numVars-1)) + ")"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s += (x + varList.getLow(numVars - 1)) + ")"; |
|
|
|
|
|
|
|
|
return s; |
|
|
return s; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert global state index to local index |
|
|
// convert global state index to local index |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int globalToLocal(long x, int l) |
|
|
public int globalToLocal(long x, int l) |
|
|
{ |
|
|
{ |
|
|
int i; |
|
|
int i; |
|
|
|
|
|
|
|
|
for (i = 0; i < numVars-1; i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < numVars - 1; i++) { |
|
|
if (i == l) { |
|
|
if (i == l) { |
|
|
return (int)((x/gtol[i+1]) + varList.getLow(i)); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
x = x % gtol[i+1]; |
|
|
|
|
|
|
|
|
return (int) ((x / gtol[i + 1]) + varList.getLow(i)); |
|
|
|
|
|
} else { |
|
|
|
|
|
x = x % gtol[i + 1]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return (int)(x + varList.getLow(numVars-1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (int) (x + varList.getLow(numVars - 1)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear up (deref all dds, dd vars) |
|
|
// clear up (deref all dds, dd vars) |
|
|
|
|
|
|
|
|
public void clear() |
|
|
public void clear() |
|
|
|