diff --git a/prism/src/jdd/JDD.java b/prism/src/jdd/JDD.java index 08a32d3e..f329955d 100644 --- a/prism/src/jdd/JDD.java +++ b/prism/src/jdd/JDD.java @@ -977,6 +977,44 @@ public class JDD return rv; } + /** + * Splits the given MTBDD by the different values that can be + * occur for those valuations that match {@code filter}.
+ * Returns a TreeMap with the double values as the keys and + * a 0/1-MTBDD for the valuations in {@code dd} that satisfy {@code filter} + * and map to the given key as the value. + *
[ REFS: result (value JDDNodes in the map), DEREFS: dd, filter ] + */ + public static TreeMap SplitByValue(JDDNode dd, JDDNode filter) + { + TreeMap result = new TreeMap<>(); + + // As long as the filter is non-empty... + while (!filter.equals(ZERO)) { + // set all values outside of the filter to +infty + dd = JDD.ITE(filter.copy(), dd, JDD.PLUS_INFINITY.copy()); + + // find the minimum value + double value = FindMin(dd); + // extract the 0/1-MTBDD with the valuations that lead to this value + JDDNode ddWithValue = Equals(dd.copy(), value); + if (value == Double.POSITIVE_INFINITY) { + // ensure that we only get those valuations that match filter + ddWithValue = JDD.And(ddWithValue, filter.copy()); + } + // store in map + result.put(value, ddWithValue); + // update filter to remove all valuations that were put in the map + filter = JDD.And(filter, Not(ddWithValue.copy())); + } + + // cleanup + JDD.Deref(dd); + JDD.Deref(filter); + + return result; + } + /** * returns dd restricted to first non-zero path (cube) *
[ REFS: result, DEREFS: dd ]