Browse Source

Improvements to import from tra files (explicit lib).

git-svn-id: https://www.prismmodelchecker.org/svn/prism/prism/trunk@1591 bbc10eb1-c90d-0410-af57-cb519fbb1720
master
Dave Parker 16 years ago
parent
commit
85bcef53d2
  1. 20
      prism/src/explicit/DTMC.java
  2. 45
      prism/src/explicit/MDP.java

20
prism/src/explicit/DTMC.java

@ -225,7 +225,7 @@ public class DTMC extends Model
{
BufferedReader in;
String s, ss[];
int i, j, n;
int i, j, n, lineNum = 0;
double prob;
try {
@ -233,6 +233,7 @@ public class DTMC extends Model
in = new BufferedReader(new FileReader(new File(filename)));
// Parse first line to get num states
s = in.readLine();
lineNum = 1;
if (s == null)
throw new PrismException("Missing first line of .tra file");
ss = s.split(" ");
@ -241,13 +242,18 @@ public class DTMC extends Model
initialise(n);
// Go though list of transitions in file
s = in.readLine();
lineNum++;
while (s != null) {
ss = s.split(" ");
i = Integer.parseInt(ss[0]);
j = Integer.parseInt(ss[1]);
prob = Double.parseDouble(ss[2]);
setProbability(i, j, prob);
s = s.trim();
if (s.length() > 0) {
ss = s.split(" ");
i = Integer.parseInt(ss[0]);
j = Integer.parseInt(ss[1]);
prob = Double.parseDouble(ss[2]);
setProbability(i, j, prob);
}
s = in.readLine();
lineNum++;
}
// Close file
in.close();
@ -255,7 +261,7 @@ public class DTMC extends Model
System.out.println(e);
System.exit(1);
} catch (NumberFormatException e) {
throw new PrismException("Problem in .tra file for " + modelType);
throw new PrismException("Problem in .tra file (line " + lineNum + ") for " + modelType);
}
// Set initial state (assume 0)
initialStates.add(0);

45
prism/src/explicit/MDP.java

@ -353,7 +353,7 @@ public class MDP extends Model
BufferedReader in;
Distribution distr;
String s, ss[];
int i, j, k, iLast, kLast, n;
int i, j, k, iLast, kLast, n, lineNum = 0;
double prob;
try {
@ -361,6 +361,7 @@ public class MDP extends Model
in = new BufferedReader(new FileReader(new File(filename)));
// Parse first line to get num states
s = in.readLine();
lineNum = 1;
if (s == null)
throw new PrismException("Missing first line of .tra file");
ss = s.split(" ");
@ -372,26 +373,31 @@ public class MDP extends Model
kLast = -1;
distr = null;
s = in.readLine();
lineNum++;
while (s != null) {
ss = s.split(" ");
i = Integer.parseInt(ss[0]);
k = Integer.parseInt(ss[1]);
j = Integer.parseInt(ss[2]);
prob = Double.parseDouble(ss[3]);
// For a new state or distribution
if (i != iLast || k != kLast) {
// Add any previous distribution to the last state, create new one
if (distr != null) {
addChoice(iLast, distr);
s = s.trim();
if (s.length() > 0) {
ss = s.split(" ");
i = Integer.parseInt(ss[0]);
k = Integer.parseInt(ss[1]);
j = Integer.parseInt(ss[2]);
prob = Double.parseDouble(ss[3]);
// For a new state or distribution
if (i != iLast || k != kLast) {
// Add any previous distribution to the last state, create new one
if (distr != null) {
addChoice(iLast, distr);
}
distr = new Distribution();
}
distr = new Distribution();
// Add transition to the current distribution
distr.add(j, prob);
// Prepare for next iter
iLast = i;
kLast = k;
}
// Add transition to the current distribution
distr.add(j, prob);
// Prepare for next iter
iLast = i;
kLast = k;
s = in.readLine();
lineNum++;
}
// Add previous distribution to the last state
addChoice(iLast, distr);
@ -401,7 +407,7 @@ public class MDP extends Model
System.out.println(e);
System.exit(1);
} catch (NumberFormatException e) {
throw new PrismException("Problem in .tra file for " + modelType);
throw new PrismException("Problem in .tra file (line " + lineNum + ") for " + modelType);
}
// Set initial state (assume 0)
initialStates.add(0);
@ -684,7 +690,8 @@ public class MDP extends Model
s += numStates + " states";
s += ", " + numDistrs + " distributions";
s += ", " + numTransitions + " transitions";
s += ", dist max/avg = " + getMaxNumChoices() + "/" + PrismUtils.formatDouble2dp(((double) numDistrs) / numStates);
s += ", dist max/avg = " + getMaxNumChoices() + "/"
+ PrismUtils.formatDouble2dp(((double) numDistrs) / numStates);
return s;
}

Loading…
Cancel
Save