|
|
@ -353,7 +353,7 @@ public class MDP extends Model |
|
|
BufferedReader in; |
|
|
BufferedReader in; |
|
|
Distribution distr; |
|
|
Distribution distr; |
|
|
String s, ss[]; |
|
|
String s, ss[]; |
|
|
int i, j, k, iLast, kLast, n; |
|
|
|
|
|
|
|
|
int i, j, k, iLast, kLast, n, lineNum = 0; |
|
|
double prob; |
|
|
double prob; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
@ -361,6 +361,7 @@ public class MDP extends Model |
|
|
in = new BufferedReader(new FileReader(new File(filename))); |
|
|
in = new BufferedReader(new FileReader(new File(filename))); |
|
|
// Parse first line to get num states |
|
|
// Parse first line to get num states |
|
|
s = in.readLine(); |
|
|
s = in.readLine(); |
|
|
|
|
|
lineNum = 1; |
|
|
if (s == null) |
|
|
if (s == null) |
|
|
throw new PrismException("Missing first line of .tra file"); |
|
|
throw new PrismException("Missing first line of .tra file"); |
|
|
ss = s.split(" "); |
|
|
ss = s.split(" "); |
|
|
@ -372,26 +373,31 @@ public class MDP extends Model |
|
|
kLast = -1; |
|
|
kLast = -1; |
|
|
distr = null; |
|
|
distr = null; |
|
|
s = in.readLine(); |
|
|
s = in.readLine(); |
|
|
|
|
|
lineNum++; |
|
|
while (s != null) { |
|
|
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(); |
|
|
s = in.readLine(); |
|
|
|
|
|
lineNum++; |
|
|
} |
|
|
} |
|
|
// Add previous distribution to the last state |
|
|
// Add previous distribution to the last state |
|
|
addChoice(iLast, distr); |
|
|
addChoice(iLast, distr); |
|
|
@ -401,7 +407,7 @@ public class MDP extends Model |
|
|
System.out.println(e); |
|
|
System.out.println(e); |
|
|
System.exit(1); |
|
|
System.exit(1); |
|
|
} catch (NumberFormatException e) { |
|
|
} 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) |
|
|
// Set initial state (assume 0) |
|
|
initialStates.add(0); |
|
|
initialStates.add(0); |
|
|
@ -684,7 +690,8 @@ public class MDP extends Model |
|
|
s += numStates + " states"; |
|
|
s += numStates + " states"; |
|
|
s += ", " + numDistrs + " distributions"; |
|
|
s += ", " + numDistrs + " distributions"; |
|
|
s += ", " + numTransitions + " transitions"; |
|
|
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; |
|
|
return s; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|