Browse Source

Refactor (symbolic) steady-state computation.

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@5614 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 14 years ago
parent
commit
d71fde3538
  1. 111
      prism/src/prism/ProbModelChecker.java

111
prism/src/prism/ProbModelChecker.java

@ -1620,17 +1620,19 @@ public class ProbModelChecker extends NonProbModelChecker
*/ */
public StateValues computeSteadyStateProbs(JDDNode tr, StateValues initDist) throws PrismException public StateValues computeSteadyStateProbs(JDDNode tr, StateValues initDist) throws PrismException
{ {
// bscc stuff
Vector<JDDNode> vectBSCCs;
JDDNode notInBSCCs;
// mtbdd stuff
JDDNode start, bscc;
// other stuff
// BSCC stuff
Vector<JDDNode> vectBSCCs = null;
JDDNode notInBSCCs = null;
// MTBDD stuff
JDDNode start = null, bscc;
// Other stuff
StateValues probs = null, solnProbs = null; StateValues probs = null, solnProbs = null;
double probBSCCs[]; double probBSCCs[];
int numBSCCs, allInOneBSCC;
int numBSCCs = 0, allInOneBSCC;
// compute bottom strongly connected components (bsccs)
try {
// Compute bottom strongly connected components (bsccs)
if (bsccComp) { if (bsccComp) {
SCCComputer sccComputer = prism.getSCCComputer(model); SCCComputer sccComputer = prism.getSCCComputer(model);
sccComputer.computeBSCCs(); sccComputer.computeBSCCs();
@ -1638,7 +1640,7 @@ public class ProbModelChecker extends NonProbModelChecker
notInBSCCs = sccComputer.getNotInBSCCs(); notInBSCCs = sccComputer.getNotInBSCCs();
numBSCCs = vectBSCCs.size(); numBSCCs = vectBSCCs.size();
} }
// unless we've been told to skip it
// Unless we've been told to skip it
else { else {
mainLog.println("\nSkipping BSCC computation..."); mainLog.println("\nSkipping BSCC computation...");
vectBSCCs = new Vector<JDDNode>(); vectBSCCs = new Vector<JDDNode>();
@ -1659,31 +1661,18 @@ public class ProbModelChecker extends NonProbModelChecker
} }
} }
// if all initial states are in a single bscc, it's easy...
// If all initial states are in a single BSCC, it's easy...
// Just compute steady-state probabilities for the BSCC
if (allInOneBSCC != -1) { if (allInOneBSCC != -1) {
mainLog.println("\nInitial states all in one BSCC (so no reachability probabilities computed)"); mainLog.println("\nInitial states all in one BSCC (so no reachability probabilities computed)");
// get bscc
bscc = vectBSCCs.elementAt(allInOneBSCC); bscc = vectBSCCs.elementAt(allInOneBSCC);
// compute steady-state probabilities for the bscc
try {
solnProbs = computeSteadyStateProbsForBSCC(trans, bscc); solnProbs = computeSteadyStateProbsForBSCC(trans, bscc);
} catch (PrismException e) {
JDD.Deref(start);
for (int b = 0; b < numBSCCs; b++) {
JDD.Deref(vectBSCCs.elementAt(b));
}
JDD.Deref(notInBSCCs);
throw e;
}
} }
// otherwise have to consider all the bsccs
// Otherwise, have to consider all the BSCCs
else { else {
// initialise total probabilities vector
// Initialise total probabilities vector
switch (engine) { switch (engine) {
case Prism.MTBDD: case Prism.MTBDD:
solnProbs = new StateValuesMTBDD(JDD.Constant(0), model); solnProbs = new StateValuesMTBDD(JDD.Constant(0), model);
@ -1696,78 +1685,62 @@ public class ProbModelChecker extends NonProbModelChecker
break; break;
} }
// compute prob of reaching each bscc from initial state
// Compute prob of reaching each BSCC from initial state
probBSCCs = new double[numBSCCs]; probBSCCs = new double[numBSCCs];
for (int b = 0; b < numBSCCs; b++) { for (int b = 0; b < numBSCCs; b++) {
mainLog.println("\nComputing probability of reaching BSCC " + (b + 1)); mainLog.println("\nComputing probability of reaching BSCC " + (b + 1));
// get bscc
bscc = vectBSCCs.elementAt(b); bscc = vectBSCCs.elementAt(b);
// compute probabilities
try {
// Compute probabilities
probs = computeUntilProbs(trans, trans01, notInBSCCs, bscc); probs = computeUntilProbs(trans, trans01, notInBSCCs, bscc);
} catch (PrismException e) {
JDD.Deref(start);
for (b = 0; b < numBSCCs; b++) {
JDD.Deref(vectBSCCs.elementAt(b));
}
JDD.Deref(notInBSCCs);
solnProbs.clear();
throw e;
}
// compute probability of reaching BSCC, which is dot product of
// Compute probability of reaching BSCC, which is dot product of
// vectors for initial distribution and probabilities of reaching it // vectors for initial distribution and probabilities of reaching it
probBSCCs[b] = probs.dotProduct(initDist); probBSCCs[b] = probs.dotProduct(initDist);
mainLog.print("\nProbability of reaching BSCC " + (b + 1) + ": " + probBSCCs[b] + "\n"); mainLog.print("\nProbability of reaching BSCC " + (b + 1) + ": " + probBSCCs[b] + "\n");
// free vector
// Free vector
probs.clear(); probs.clear();
} }
// compute steady-state for each bscc
// Compute steady-state probs for each BSCC
for (int b = 0; b < numBSCCs; b++) { for (int b = 0; b < numBSCCs; b++) {
mainLog.println("\nComputing steady-state probabilities for BSCC " + (b + 1)); mainLog.println("\nComputing steady-state probabilities for BSCC " + (b + 1));
// get bscc
bscc = vectBSCCs.elementAt(b); bscc = vectBSCCs.elementAt(b);
// compute steady-state probabilities for the bscc
try {
// Compute steady-state probabilities for the BSCC
probs = computeSteadyStateProbsForBSCC(trans, bscc); probs = computeSteadyStateProbsForBSCC(trans, bscc);
} catch (PrismException e) {
JDD.Deref(start);
for (b = 0; b < numBSCCs; b++) {
JDD.Deref(vectBSCCs.elementAt(b));
}
JDD.Deref(notInBSCCs);
solnProbs.clear();
throw e;
}
// print out probabilities
// Print out probabilities
if (verbose) { if (verbose) {
mainLog.print("\nBSCC " + (b + 1) + " Steady-State Probabilities: \n"); mainLog.print("\nBSCC " + (b + 1) + " Steady-State Probabilities: \n");
probs.print(mainLog); probs.print(mainLog);
} }
// times by bscc reach prob, add to total
// Multiply by BSCC reach prob, add to total
probs.timesConstant(probBSCCs[b]); probs.timesConstant(probBSCCs[b]);
solnProbs.add(probs); solnProbs.add(probs);
// free vector
// Free vector
probs.clear(); probs.clear();
} }
} }
} catch (PrismException e) {
// Tidy up and pass on the exception
if (start != null)
JDD.Deref(start);
for (int b = 0; b < numBSCCs; b++) {
if (vectBSCCs.elementAt(b) != null)
JDD.Deref(vectBSCCs.elementAt(b));
}
if (start != notInBSCCs)
JDD.Deref(notInBSCCs);
if (solnProbs != null)
solnProbs.clear();
throw e;
}
// derefs
// Tidy up
if (start != null)
JDD.Deref(start); JDD.Deref(start);
for (int b = 0; b < numBSCCs; b++) { for (int b = 0; b < numBSCCs; b++) {
if (vectBSCCs.elementAt(b) != null)
JDD.Deref(vectBSCCs.elementAt(b)); JDD.Deref(vectBSCCs.elementAt(b));
} }
if (start != notInBSCCs)
JDD.Deref(notInBSCCs); JDD.Deref(notInBSCCs);
return solnProbs; return solnProbs;

Loading…
Cancel
Save