Browse Source

Add methods to the explicit.Model interface to get a (cached) PredecessorRelation. [from Joachim Klein]

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@10192 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 11 years ago
parent
commit
f4ab03013f
  1. 19
      prism/src/explicit/Model.java
  2. 30
      prism/src/explicit/ModelExplicit.java
  3. 29
      prism/src/explicit/SubNondetModel.java

19
prism/src/explicit/Model.java

@ -253,4 +253,21 @@ public interface Model
* Report info/stats about the model, tabulated, as a string. * Report info/stats about the model, tabulated, as a string.
*/ */
public String infoStringTable(); public String infoStringTable();
}
/** Has this model a stored PredecessorRelation? */
public boolean hasStoredPredecessorRelation();
/**
* If there is a PredecessorRelation stored for this model, return that.
* Otherwise, create one and return that. If {@code storeIfNew},
* store it for later use.
*
* @param parent a PrismComponent (for obtaining the log)
* @param storeIfNew if the predecessor relation is newly created, store it
*/
public PredecessorRelation getPredecessorRelation(prism.PrismComponent parent, boolean storeIfNew);
/** Clear any stored predecessor relation, e.g., because the model was modified */
public void clearPredecessorRelation();
}

30
prism/src/explicit/ModelExplicit.java

@ -69,6 +69,11 @@ public abstract class ModelExplicit implements Model
/** (Optionally) some labels (atomic propositions) associated with the model, /** (Optionally) some labels (atomic propositions) associated with the model,
* represented as a String->BitSet mapping from their names to the states that satisfy them. */ * represented as a String->BitSet mapping from their names to the states that satisfy them. */
protected Map<String, BitSet> labels = new TreeMap<String, BitSet>(); protected Map<String, BitSet> labels = new TreeMap<String, BitSet>();
/**
* (Optionally) the stored predecessor relation. Becomes inaccurate after the model is changed!
*/
protected PredecessorRelation predecessorRelation = null;
// Mutators // Mutators
@ -439,4 +444,29 @@ public abstract class ModelExplicit implements Model
return false; return false;
return true; return true;
} }
@Override
public boolean hasStoredPredecessorRelation() {
return (predecessorRelation != null);
}
@Override
public PredecessorRelation getPredecessorRelation(prism.PrismComponent parent, boolean storeIfNew) {
if (predecessorRelation != null) {
return predecessorRelation;
}
PredecessorRelation pre = PredecessorRelation.forModel(parent, this);
if (storeIfNew) {
predecessorRelation = pre;
}
return pre;
}
@Override
public void clearPredecessorRelation() {
predecessorRelation = null;
}
} }

29
prism/src/explicit/SubNondetModel.java

@ -62,6 +62,11 @@ public class SubNondetModel implements NondetModel
private Map<Integer, Map<Integer, Integer>> actionLookupTable = new HashMap<Integer, Map<Integer, Integer>>(); private Map<Integer, Map<Integer, Integer>> actionLookupTable = new HashMap<Integer, Map<Integer, Integer>>();
private Map<Integer, Integer> inverseStateLookupTable = new HashMap<Integer, Integer>(); private Map<Integer, Integer> inverseStateLookupTable = new HashMap<Integer, Integer>();
/**
* (Optionally) the stored predecessor relation. Becomes inaccurate after the model is changed!
*/
protected PredecessorRelation predecessorRelation;
private int numTransitions = 0; private int numTransitions = 0;
private int maxNumChoices = 0; private int maxNumChoices = 0;
private int numChoices = 0; private int numChoices = 0;
@ -495,4 +500,28 @@ public class SubNondetModel implements NondetModel
{ {
return actionLookupTable.get(s).get(i); return actionLookupTable.get(s).get(i);
} }
@Override
public boolean hasStoredPredecessorRelation() {
return (predecessorRelation != null);
}
@Override
public PredecessorRelation getPredecessorRelation(prism.PrismComponent parent, boolean storeIfNew) {
if (predecessorRelation != null) {
return predecessorRelation;
}
PredecessorRelation pre = PredecessorRelation.forModel(parent, this);
if (storeIfNew) {
predecessorRelation = pre;
}
return pre;
}
@Override
public void clearPredecessorRelation() {
predecessorRelation = null;
}
} }
Loading…
Cancel
Save