diff --git a/prism/src/jdd/JDDVars.java b/prism/src/jdd/JDDVars.java index e6a86ef1..e115e13b 100644 --- a/prism/src/jdd/JDDVars.java +++ b/prism/src/jdd/JDDVars.java @@ -285,6 +285,58 @@ public class JDDVars implements Iterable return s; } + + + /** + * Converts a DD cubeset (conjunction of variables) + * to a corresponding JDDVars array.
+ *
[ REFS: the variables in the returned JDDVars container, DEREFS: cubeSet ] + */ + public static JDDVars fromCubeSet(JDDNode cubeSet) + { + try { + JDDVars result = new JDDVars(); + + JDDNode current = cubeSet; + // We do not need to bother with reference manipulation, + // as we only call getThen() and getElse(), which do not increase + // the refcount + while (!current.equals(JDD.ONE)) { + if (current.isConstant()) { + // may not be any other constant than ONE + throw new IllegalArgumentException("JDDVars.fromCubeSet: The argument is not a cubeset"); + } + if (!current.getElse().equals(JDD.ZERO)) { + // else always has to point to ZERO + throw new IllegalArgumentException("JDDVars.fromCubeSet: The argument is not a cubeset"); + } + + int index = current.getIndex(); + JDDNode var = JDD.Var(index); + result.addVar(var); + + current = current.getThen(); + } + + return result; + } finally { + JDD.Deref(cubeSet); + } + } + + /** + * Constructs a DD cubeset (conjunction of variables) + * corresponding to this JDDVars container.
+ *
[ REFS: result, DEREFS: none ] + */ + public JDDNode toCubeSet() + { + JDDNode result = JDD.Constant(1); + for (JDDNode var : vars) { + result = JDD.And(result, var.copy()); + } + return result; + } } //------------------------------------------------------------------------------