diff --git a/prism/src/explicit/CTMCSimple.java b/prism/src/explicit/CTMCSimple.java index d08afef9..2f980075 100644 --- a/prism/src/explicit/CTMCSimple.java +++ b/prism/src/explicit/CTMCSimple.java @@ -28,6 +28,8 @@ package explicit; import java.util.Map; +import prism.ModelType; + /** * Simple explicit-state representation of a CTMC. */ @@ -70,6 +72,14 @@ public class CTMCSimple extends DTMCSimple implements CTMC super(ctmc, permut); } + // Accessors (for ModelSimple, overrides DTMCSimple) + + @Override + public ModelType getModelType() + { + return ModelType.CTMC; + } + // Accessors (for CTMC) @Override diff --git a/prism/src/explicit/DTMCSimple.java b/prism/src/explicit/DTMCSimple.java index 3e04fc20..8bdc91dd 100644 --- a/prism/src/explicit/DTMCSimple.java +++ b/prism/src/explicit/DTMCSimple.java @@ -376,6 +376,45 @@ public class DTMCSimple extends ModelSimple implements DTMC } } + @Override + public void exportToPrismLanguage(String filename) throws PrismException + { + int i; + boolean first; + FileWriter out; + TreeMap sorted; + try { + // Output transitions to PRISM language file + out = new FileWriter(filename); + out.write(getModelType().keyword() + "\n"); + out.write("module M\nx : [0.." + (numStates-1) + "];\n"); + sorted = new TreeMap(); + for (i = 0; i < numStates; i++) { + // Extract transitions and sort by destination state index (to match PRISM-exported files) + for (Map.Entry e : trans.get(i)) { + sorted.put(e.getKey(), e.getValue()); + } + // Print out (sorted) transitions + out.write("[]x=" + i + "->"); + first = true; + for (Map.Entry e : sorted.entrySet()) { + if (first) + first = false; + else + out.write("+"); + // Note use of PrismUtils.formatDouble to match PRISM-exported files + out.write(PrismUtils.formatDouble(e.getValue()) + ":(x'=" + e.getKey() + ")"); + } + out.write(";\n"); + sorted.clear(); + } + out.write("endmodule\n"); + out.close(); + } catch (IOException e) { + throw new PrismException("Could not export " + getModelType() + " to file \"" + filename + "\"" + e); + } + } + @Override public String infoString() { diff --git a/prism/src/explicit/MDPSimple.java b/prism/src/explicit/MDPSimple.java index 1d118c8f..43f55ee4 100644 --- a/prism/src/explicit/MDPSimple.java +++ b/prism/src/explicit/MDPSimple.java @@ -500,6 +500,49 @@ public class MDPSimple extends ModelSimple implements MDP } } + @Override + public void exportToPrismLanguage(String filename) throws PrismException + { + int i, j; + boolean first; + FileWriter out; + TreeMap sorted; + try { + // Output transitions to PRISM language file + out = new FileWriter(filename); + out.write(getModelType().keyword() + "\n"); + out.write("module M\nx : [0.." + (numStates-1) + "];\n"); + sorted = new TreeMap(); + for (i = 0; i < numStates; i++) { + j = -1; + for (Distribution distr : trans.get(i)) { + j++; + // Extract transitions and sort by destination state index (to match PRISM-exported files) + for (Map.Entry e : distr) { + sorted.put(e.getKey(), e.getValue()); + } + // Print out (sorted) transitions + out.write("[]x=" + i + "->"); + first = true; + for (Map.Entry e : sorted.entrySet()) { + if (first) + first = false; + else + out.write("+"); + // Note use of PrismUtils.formatDouble to match PRISM-exported files + out.write(PrismUtils.formatDouble(e.getValue()) + ":(x'=" + e.getKey() + ")"); + } + out.write(";\n"); + sorted.clear(); + } + } + out.write("endmodule\n"); + out.close(); + } catch (IOException e) { + throw new PrismException("Could not export " + getModelType() + " to file \"" + filename + "\"" + e); + } + } + @Override public String infoString() { diff --git a/prism/src/explicit/ModelSimple.java b/prism/src/explicit/ModelSimple.java index 92286550..9a119e12 100644 --- a/prism/src/explicit/ModelSimple.java +++ b/prism/src/explicit/ModelSimple.java @@ -140,6 +140,8 @@ public abstract class ModelSimple implements Model public abstract void exportToDotFile(String filename, BitSet mark) throws PrismException; + public abstract void exportToPrismLanguage(String filename) throws PrismException; + public abstract String infoString(); @Override