Browse Source
Fixes in explicit CTMC solving + some CTMDP stuff.
Fixes in explicit CTMC solving + some CTMDP stuff.
git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@1824 bbc10eb1-c90d-0410-af57-cb519fbb1720master
8 changed files with 301 additions and 18 deletions
-
2prism/src/explicit/CTMC.java
-
17prism/src/explicit/CTMCModelChecker.java
-
5prism/src/explicit/CTMCSimple.java
-
5prism/src/explicit/CTMDP.java
-
14prism/src/explicit/CTMDPModelChecker.java
-
22prism/src/explicit/CTMDPSimple.java
-
2prism/src/explicit/DTMCEmbeddedSimple.java
-
252prism/src/explicit/DTMCUniformisedSimple.java
@ -0,0 +1,252 @@ |
|||||
|
//============================================================================== |
||||
|
// |
||||
|
//Copyright (c) 2002- |
||||
|
//Authors: |
||||
|
//* Dave Parker <david.parker@comlab.ox.ac.uk> (University of Oxford) |
||||
|
// |
||||
|
//------------------------------------------------------------------------------ |
||||
|
// |
||||
|
//This file is part of PRISM. |
||||
|
// |
||||
|
//PRISM is free software; you can redistribute it and/or modify |
||||
|
//it under the terms of the GNU General Public License as published by |
||||
|
//the Free Software Foundation; either version 2 of the License, or |
||||
|
//(at your option) any later version. |
||||
|
// |
||||
|
//PRISM is distributed in the hope that it will be useful, |
||||
|
//but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
//GNU General Public License for more details. |
||||
|
// |
||||
|
//You should have received a copy of the GNU General Public License |
||||
|
//along with PRISM; if not, write to the Free Software Foundation, |
||||
|
//Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||||
|
// |
||||
|
//============================================================================== |
||||
|
|
||||
|
package explicit; |
||||
|
|
||||
|
import java.util.*; |
||||
|
|
||||
|
import prism.PrismException; |
||||
|
|
||||
|
/** |
||||
|
* Simple explicit-state representation of a DTMC, constructed (implicitly) as the uniformised DTMC of a CTMC. |
||||
|
* This class is read-only: most of data is pointers to other model info. |
||||
|
*/ |
||||
|
public class DTMCUniformisedSimple implements DTMC |
||||
|
{ |
||||
|
// Parent CTMC |
||||
|
protected CTMCSimple ctmc; |
||||
|
// Uniformisation rate |
||||
|
protected double q; |
||||
|
// Number of extra transitions added (just for stats) |
||||
|
protected int numExtraTransitions; |
||||
|
|
||||
|
/** |
||||
|
* Constructor: create from CTMC and uniformisation rate q. |
||||
|
*/ |
||||
|
public DTMCUniformisedSimple(CTMCSimple ctmc, double q) |
||||
|
{ |
||||
|
this.ctmc = ctmc; |
||||
|
this.q = q; |
||||
|
int numStates = ctmc.getNumStates(); |
||||
|
numExtraTransitions = 0; |
||||
|
for (int i = 0; i < numStates; i++) { |
||||
|
if (ctmc.getTransitions(i).get(i) == 0 && ctmc.getTransitions(i).sumAllBut(i) < q) { |
||||
|
numExtraTransitions++; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Constructor: create from CTMC and its default uniformisation rate. |
||||
|
*/ |
||||
|
public DTMCUniformisedSimple(CTMCSimple ctmc) |
||||
|
{ |
||||
|
this(ctmc, ctmc.getDefaultUniformisationRate()); |
||||
|
} |
||||
|
|
||||
|
// Accessors (for Model) |
||||
|
|
||||
|
public int getNumStates() |
||||
|
{ |
||||
|
return ctmc.getNumStates(); |
||||
|
} |
||||
|
|
||||
|
public int getNumInitialStates() |
||||
|
{ |
||||
|
return ctmc.getNumInitialStates(); |
||||
|
} |
||||
|
|
||||
|
public Iterable<Integer> getInitialStates() |
||||
|
{ |
||||
|
return ctmc.getInitialStates(); |
||||
|
} |
||||
|
|
||||
|
public int getFirstInitialState() |
||||
|
{ |
||||
|
return ctmc.getFirstInitialState(); |
||||
|
} |
||||
|
|
||||
|
public boolean isInitialState(int i) |
||||
|
{ |
||||
|
return ctmc.isInitialState(i); |
||||
|
} |
||||
|
|
||||
|
public int getNumTransitions() |
||||
|
{ |
||||
|
return ctmc.getNumTransitions() + numExtraTransitions; |
||||
|
} |
||||
|
|
||||
|
public boolean isSuccessor(int s1, int s2) |
||||
|
{ |
||||
|
// TODO |
||||
|
throw new Error("Not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public boolean allSuccessorsInSet(int s, BitSet set) |
||||
|
{ |
||||
|
// TODO |
||||
|
throw new Error("Not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public boolean someSuccessorsInSet(int s, BitSet set) |
||||
|
{ |
||||
|
// TODO |
||||
|
throw new Error("Not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public int getNumChoices(int s) |
||||
|
{ |
||||
|
// Always 1 for a DTMC |
||||
|
return 1; |
||||
|
} |
||||
|
|
||||
|
public void checkForDeadlocks() throws PrismException |
||||
|
{ |
||||
|
// No deadlocks by definition |
||||
|
} |
||||
|
|
||||
|
public void checkForDeadlocks(BitSet except) throws PrismException |
||||
|
{ |
||||
|
// No deadlocks by definition |
||||
|
} |
||||
|
|
||||
|
public void exportToPrismExplicit(String baseFilename) throws PrismException |
||||
|
{ |
||||
|
throw new PrismException("Export not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public void exportToDotFile(String filename) throws PrismException |
||||
|
{ |
||||
|
throw new PrismException("Export not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public void exportToDotFile(String filename, BitSet mark) throws PrismException |
||||
|
{ |
||||
|
throw new PrismException("Export not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public String infoString() |
||||
|
{ |
||||
|
return ctmc.infoString() + " + " + numExtraTransitions + " self-loops"; |
||||
|
} |
||||
|
|
||||
|
// Accessors (for DTMC) |
||||
|
|
||||
|
public double getTransitionReward(int s) |
||||
|
{ |
||||
|
// TODO |
||||
|
throw new Error("Not yet supported"); |
||||
|
} |
||||
|
|
||||
|
public void mvMult(double vect[], double result[], BitSet subset, boolean complement) |
||||
|
{ |
||||
|
int s, numStates; |
||||
|
numStates = ctmc.getNumStates(); |
||||
|
// Loop depends on subset/complement arguments |
||||
|
if (subset == null) { |
||||
|
for (s = 0; s < numStates; s++) |
||||
|
result[s] = mvMultSingle(s, vect); |
||||
|
} else if (complement) { |
||||
|
for (s = subset.nextClearBit(0); s < numStates; s = subset.nextClearBit(s + 1)) |
||||
|
result[s] = mvMultSingle(s, vect); |
||||
|
} else { |
||||
|
for (s = subset.nextSetBit(0); s >= 0; s = subset.nextSetBit(s + 1)) |
||||
|
result[s] = mvMultSingle(s, vect); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public double mvMultSingle(int s, double vect[]) |
||||
|
{ |
||||
|
int k; |
||||
|
double sum, d, prob; |
||||
|
Distribution distr; |
||||
|
|
||||
|
distr = ctmc.getTransitions(s); |
||||
|
sum = d = 0.0; |
||||
|
for (Map.Entry<Integer, Double> e : distr) { |
||||
|
k = (Integer) e.getKey(); |
||||
|
prob = (Double) e.getValue(); |
||||
|
// Non-diagonal entries |
||||
|
if (k != s) { |
||||
|
sum += prob; |
||||
|
d += (prob / q) * vect[k]; |
||||
|
} |
||||
|
} |
||||
|
// Diagonal entry |
||||
|
if (sum < q) { |
||||
|
d += (1 - sum/q) * vect[s]; |
||||
|
} |
||||
|
|
||||
|
return d; |
||||
|
} |
||||
|
|
||||
|
public void mvMultRew(double vect[], double result[], BitSet subset, boolean complement) |
||||
|
{ |
||||
|
int s, numStates; |
||||
|
numStates = ctmc.getNumStates(); |
||||
|
// Loop depends on subset/complement arguments |
||||
|
if (subset == null) { |
||||
|
for (s = 0; s < numStates; s++) |
||||
|
result[s] = mvMultRewSingle(s, vect); |
||||
|
} else if (complement) { |
||||
|
for (s = subset.nextClearBit(0); s < numStates; s = subset.nextClearBit(s + 1)) |
||||
|
result[s] = mvMultRewSingle(s, vect); |
||||
|
} else { |
||||
|
for (s = subset.nextSetBit(0); s >= 0; s = subset.nextSetBit(s + 1)) |
||||
|
result[s] = mvMultRewSingle(s, vect); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public double mvMultRewSingle(int s, double vect[]) |
||||
|
{ |
||||
|
// TODO |
||||
|
throw new Error("Not yet supported"); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String toString() |
||||
|
{ |
||||
|
String s = ""; |
||||
|
s += "ctmc: " + ctmc; |
||||
|
s = ", q: " + q; |
||||
|
return s; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean equals(Object o) |
||||
|
{ |
||||
|
if (o == null || !(o instanceof DTMCUniformisedSimple)) |
||||
|
return false; |
||||
|
DTMCUniformisedSimple dtmc = (DTMCUniformisedSimple) o; |
||||
|
if (!ctmc.equals(dtmc.ctmc)) |
||||
|
return false; |
||||
|
if (q != dtmc.q) |
||||
|
return false; |
||||
|
if (numExtraTransitions != dtmc.numExtraTransitions) |
||||
|
return false; |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue