|
|
|
@ -32,7 +32,9 @@ import dv.*; |
|
|
|
import jdd.*; |
|
|
|
import odd.*; |
|
|
|
import parser.VarList; |
|
|
|
import parser.type.*;; |
|
|
|
import parser.type.*; |
|
|
|
|
|
|
|
; |
|
|
|
|
|
|
|
// Class for state-indexed vectors of (integer or double) values, represented by a vector of doubles |
|
|
|
|
|
|
|
@ -62,6 +64,7 @@ public class StateValuesDV implements StateValues |
|
|
|
boolean printSparse = true; |
|
|
|
boolean printMatlab = false; |
|
|
|
boolean printStates = true; |
|
|
|
boolean printIndices = true; |
|
|
|
|
|
|
|
// CONSTRUCTORS |
|
|
|
|
|
|
|
@ -136,7 +139,8 @@ public class StateValuesDV implements StateValues |
|
|
|
// open file for reading |
|
|
|
in = new BufferedReader(new FileReader(file)); |
|
|
|
// read remaining lines |
|
|
|
s = in.readLine(); lineNum++; |
|
|
|
s = in.readLine(); |
|
|
|
lineNum++; |
|
|
|
while (s != null) { |
|
|
|
s = s.trim(); |
|
|
|
if (!("".equals(s))) { |
|
|
|
@ -146,18 +150,17 @@ public class StateValuesDV implements StateValues |
|
|
|
setElement(count, d); |
|
|
|
count++; |
|
|
|
} |
|
|
|
s = in.readLine(); lineNum++; |
|
|
|
s = in.readLine(); |
|
|
|
lineNum++; |
|
|
|
} |
|
|
|
// close file |
|
|
|
in.close(); |
|
|
|
// check size |
|
|
|
if (count < size) |
|
|
|
throw new PrismException("Too few values in file \"" + file + "\" (" + count + ", not " + size + ")"); |
|
|
|
} |
|
|
|
catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
throw new PrismException("File I/O error reading from \"" + file + "\""); |
|
|
|
} |
|
|
|
catch (NumberFormatException e) { |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
throw new PrismException("Error detected at line " + lineNum + " of file \"" + file + "\""); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -180,7 +183,7 @@ public class StateValuesDV implements StateValues |
|
|
|
|
|
|
|
public void add(StateValues sp) |
|
|
|
{ |
|
|
|
values.add(((StateValuesDV)sp).values); |
|
|
|
values.add(((StateValuesDV) sp).values); |
|
|
|
} |
|
|
|
|
|
|
|
// multiply vector by a constant |
|
|
|
@ -286,7 +289,7 @@ public class StateValuesDV implements StateValues |
|
|
|
|
|
|
|
tmp = values.sumOverDDVars(model.getAllDDRowVars(), odd, newModel.getODD(), sumVars.getMinVarIndex(), sumVars.getMaxVarIndex()); |
|
|
|
|
|
|
|
return (StateValues)new StateValuesDV(tmp, newModel); |
|
|
|
return (StateValues) new StateValuesDV(tmp, newModel); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -344,7 +347,19 @@ public class StateValuesDV implements StateValues |
|
|
|
*/ |
|
|
|
public void print(PrismLog log) throws PrismException |
|
|
|
{ |
|
|
|
print(log, true, false, true); |
|
|
|
print(log, true, false, true, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Print vector to a log/file. |
|
|
|
* @param log The log |
|
|
|
* @param printSparse Print non-zero elements only? |
|
|
|
* @param printMatlab Print in Matlab format? |
|
|
|
* @param printStates Print states (variable values) for each element? |
|
|
|
*/ |
|
|
|
public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolean printStates) throws PrismException |
|
|
|
{ |
|
|
|
print(log, printSparse, printMatlab, printStates, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -353,8 +368,9 @@ public class StateValuesDV implements StateValues |
|
|
|
* @param printSparse Print non-zero elements only? |
|
|
|
* @param printMatlab Print in Matlab format? |
|
|
|
* @param printStates Print states (variable values) for each element? |
|
|
|
* @param printIndices Print state indices for each element? |
|
|
|
*/ |
|
|
|
public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolean printStates) throws PrismException |
|
|
|
public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolean printStates, boolean printIndices) throws PrismException |
|
|
|
{ |
|
|
|
int i; |
|
|
|
|
|
|
|
@ -362,6 +378,7 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
this.printSparse = printSparse; |
|
|
|
this.printMatlab = printMatlab; |
|
|
|
this.printStates = printStates; |
|
|
|
this.printIndices = printIndices; |
|
|
|
|
|
|
|
// header for matlab format |
|
|
|
if (printMatlab) |
|
|
|
@ -385,7 +402,7 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
// footer for matlab format |
|
|
|
if (printMatlab && !printSparse) |
|
|
|
log.println("];"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Recursive part of print method. |
|
|
|
@ -415,16 +432,32 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
// recurse |
|
|
|
else { |
|
|
|
if (o.getEOff() > 0) { |
|
|
|
currentVarLevel++; if (currentVarLevel == varSizes[currentVar]) { currentVar++; currentVarLevel=0; } |
|
|
|
printRec(level+1, o.getElse(), n); |
|
|
|
currentVarLevel--; if (currentVarLevel == -1) { currentVar--; currentVarLevel=varSizes[currentVar]-1; } |
|
|
|
currentVarLevel++; |
|
|
|
if (currentVarLevel == varSizes[currentVar]) { |
|
|
|
currentVar++; |
|
|
|
currentVarLevel = 0; |
|
|
|
} |
|
|
|
printRec(level + 1, o.getElse(), n); |
|
|
|
currentVarLevel--; |
|
|
|
if (currentVarLevel == -1) { |
|
|
|
currentVar--; |
|
|
|
currentVarLevel = varSizes[currentVar] - 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (o.getTOff() > 0) { |
|
|
|
varValues[currentVar] += (1 << (varSizes[currentVar]-1-currentVarLevel)); |
|
|
|
currentVarLevel++; if (currentVarLevel == varSizes[currentVar]) { currentVar++; currentVarLevel=0; } |
|
|
|
printRec(level+1, o.getThen(), (int)(n+o.getEOff())); |
|
|
|
currentVarLevel--; if (currentVarLevel == -1) { currentVar--; currentVarLevel=varSizes[currentVar]-1; } |
|
|
|
varValues[currentVar] -= (1 << (varSizes[currentVar]-1-currentVarLevel)); |
|
|
|
varValues[currentVar] += (1 << (varSizes[currentVar] - 1 - currentVarLevel)); |
|
|
|
currentVarLevel++; |
|
|
|
if (currentVarLevel == varSizes[currentVar]) { |
|
|
|
currentVar++; |
|
|
|
currentVarLevel = 0; |
|
|
|
} |
|
|
|
printRec(level + 1, o.getThen(), (int) (n + o.getEOff())); |
|
|
|
currentVarLevel--; |
|
|
|
if (currentVarLevel == -1) { |
|
|
|
currentVar--; |
|
|
|
currentVarLevel = varSizes[currentVar] - 1; |
|
|
|
} |
|
|
|
varValues[currentVar] -= (1 << (varSizes[currentVar] - 1 - currentVarLevel)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -436,7 +469,7 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
*/ |
|
|
|
public void printFiltered(PrismLog log, JDDNode filter) throws PrismException |
|
|
|
{ |
|
|
|
printFiltered(log, filter, true, false, true); |
|
|
|
printFiltered(log, filter, true, false, true, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -448,6 +481,20 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
* @param printStates Print states (variable values) for each element? |
|
|
|
*/ |
|
|
|
public void printFiltered(PrismLog log, JDDNode filter, boolean printSparse, boolean printMatlab, boolean printStates) throws PrismException |
|
|
|
{ |
|
|
|
printFiltered(log, filter, printSparse, printMatlab, printStates, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Print part of a vector to a log/file (non-zero entries only). |
|
|
|
* @param log The log |
|
|
|
* @param filter A BDD specifying which states to print for. |
|
|
|
* @param printSparse Print non-zero elements only? |
|
|
|
* @param printMatlab Print in Matlab format? |
|
|
|
* @param printStates Print states (variable values) for each element? |
|
|
|
* @param printIndices Print state indices for each element? |
|
|
|
*/ |
|
|
|
public void printFiltered(PrismLog log, JDDNode filter, boolean printSparse, boolean printMatlab, boolean printStates, boolean printIndices) throws PrismException |
|
|
|
{ |
|
|
|
int i; |
|
|
|
|
|
|
|
@ -455,6 +502,7 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
this.printSparse = printSparse; |
|
|
|
this.printMatlab = printMatlab; |
|
|
|
this.printStates = printStates; |
|
|
|
this.printIndices = printIndices; |
|
|
|
|
|
|
|
// header for matlab format |
|
|
|
if (printMatlab) |
|
|
|
@ -508,22 +556,40 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
// recurse |
|
|
|
else { |
|
|
|
if (o.getEOff() > 0) { |
|
|
|
currentVarLevel++; if (currentVarLevel == varSizes[currentVar]) { currentVar++; currentVarLevel=0; } |
|
|
|
JDD.Ref(filter); JDD.Ref(vars.getVar(level)); |
|
|
|
currentVarLevel++; |
|
|
|
if (currentVarLevel == varSizes[currentVar]) { |
|
|
|
currentVar++; |
|
|
|
currentVarLevel = 0; |
|
|
|
} |
|
|
|
JDD.Ref(filter); |
|
|
|
JDD.Ref(vars.getVar(level)); |
|
|
|
newFilter = JDD.Apply(JDD.TIMES, filter, JDD.Not(vars.getVar(level))); |
|
|
|
printFilteredRec(level+1, o.getElse(), n, newFilter); |
|
|
|
printFilteredRec(level + 1, o.getElse(), n, newFilter); |
|
|
|
JDD.Deref(newFilter); |
|
|
|
currentVarLevel--; if (currentVarLevel == -1) { currentVar--; currentVarLevel=varSizes[currentVar]-1; } |
|
|
|
currentVarLevel--; |
|
|
|
if (currentVarLevel == -1) { |
|
|
|
currentVar--; |
|
|
|
currentVarLevel = varSizes[currentVar] - 1; |
|
|
|
} |
|
|
|
} |
|
|
|
if (o.getTOff() > 0) { |
|
|
|
varValues[currentVar] += (1 << (varSizes[currentVar]-1-currentVarLevel)); |
|
|
|
currentVarLevel++; if (currentVarLevel == varSizes[currentVar]) { currentVar++; currentVarLevel=0; } |
|
|
|
JDD.Ref(filter); JDD.Ref(vars.getVar(level)); |
|
|
|
varValues[currentVar] += (1 << (varSizes[currentVar] - 1 - currentVarLevel)); |
|
|
|
currentVarLevel++; |
|
|
|
if (currentVarLevel == varSizes[currentVar]) { |
|
|
|
currentVar++; |
|
|
|
currentVarLevel = 0; |
|
|
|
} |
|
|
|
JDD.Ref(filter); |
|
|
|
JDD.Ref(vars.getVar(level)); |
|
|
|
newFilter = JDD.Apply(JDD.TIMES, filter, vars.getVar(level)); |
|
|
|
printFilteredRec(level+1, o.getThen(), (int)(n+o.getEOff()), newFilter); |
|
|
|
printFilteredRec(level + 1, o.getThen(), (int) (n + o.getEOff()), newFilter); |
|
|
|
JDD.Deref(newFilter); |
|
|
|
currentVarLevel--; if (currentVarLevel == -1) { currentVar--; currentVarLevel=varSizes[currentVar]-1; } |
|
|
|
varValues[currentVar] -= (1 << (varSizes[currentVar]-1-currentVarLevel)); |
|
|
|
currentVarLevel--; |
|
|
|
if (currentVarLevel == -1) { |
|
|
|
currentVar--; |
|
|
|
currentVarLevel = varSizes[currentVar] - 1; |
|
|
|
} |
|
|
|
varValues[currentVar] -= (1 << (varSizes[currentVar] - 1 - currentVarLevel)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -536,30 +602,40 @@ public void print(PrismLog log, boolean printSparse, boolean printMatlab, boolea |
|
|
|
counter++; |
|
|
|
// do printing |
|
|
|
if (!printSparse || d != 0) { |
|
|
|
if (printSparse) |
|
|
|
outputLog.print(printMatlab ? "v(" + (n + 1) + ")" : n); |
|
|
|
if (printStates && !printMatlab) { |
|
|
|
outputLog.print(":("); |
|
|
|
j = varList.getNumVars(); |
|
|
|
for (i = 0; i < j; i++) { |
|
|
|
// integer variable |
|
|
|
if (varList.getType(i) instanceof TypeInt) { |
|
|
|
outputLog.print(varValues[i]+varList.getLow(i)); |
|
|
|
} |
|
|
|
// boolean variable |
|
|
|
else { |
|
|
|
outputLog.print(varValues[i] == 1); |
|
|
|
if (printMatlab) { |
|
|
|
if (printSparse) { |
|
|
|
outputLog.println("v(" + (n + 1) + ")=" + d + ";"); |
|
|
|
} else { |
|
|
|
outputLog.println(d); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (printIndices) |
|
|
|
outputLog.print(n); |
|
|
|
if (printStates) { |
|
|
|
outputLog.print(":("); |
|
|
|
j = varList.getNumVars(); |
|
|
|
for (i = 0; i < j; i++) { |
|
|
|
// integer variable |
|
|
|
if (varList.getType(i) instanceof TypeInt) { |
|
|
|
outputLog.print(varValues[i] + varList.getLow(i)); |
|
|
|
} |
|
|
|
// boolean variable |
|
|
|
else { |
|
|
|
outputLog.print(varValues[i] == 1); |
|
|
|
} |
|
|
|
if (i < j - 1) |
|
|
|
outputLog.print(","); |
|
|
|
} |
|
|
|
if (i < j-1) outputLog.print(","); |
|
|
|
outputLog.print(")"); |
|
|
|
} else { |
|
|
|
if (printIndices || printStates) |
|
|
|
outputLog.print("="); |
|
|
|
outputLog.println(d); |
|
|
|
} |
|
|
|
outputLog.print(")"); |
|
|
|
} |
|
|
|
if (printSparse) |
|
|
|
outputLog.print("="); |
|
|
|
outputLog.print(d); |
|
|
|
if (printMatlab && printSparse) |
|
|
|
outputLog.print(";"); |
|
|
|
outputLog.println(); |
|
|
|
//return true; |
|
|
|
} else { |
|
|
|
//return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|