Skip to content

Commit 101c1cc

Browse files
authored
Merge pull request #53 from wytseoortwijn/relprev_and_relnext
#52 Contribute BDD operations `relnext` and `relprev` and their restricted variants
2 parents 44857ad + 0ba5fbe commit 101c1cc

File tree

3 files changed

+1108
-9
lines changed

3 files changed

+1108
-9
lines changed

src/main/java/com/github/javabdd/BDD.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,60 @@ public BDD relprod(BDD that, BDDVarSet var) {
586586
*/
587587
public abstract BDD satOne(BDDVarSet var, boolean pol);
588588

589+
/**
590+
* Computes the BDD that represents the set of successor states from {@code states}, i.e., the ones reachable by
591+
* taking one forward step from states in {@code states}, where this BDD is the (partial) transition relation to
592+
* consider. It is assumed that old-state and new-state BDD variables are interleaved in this transition relation,
593+
* starting with the old-state variable, i.e., each old-state variable comes directly before its corresponding
594+
* new-state variable.
595+
*
596+
* @param states The BDD representing the set of states.
597+
* @param vars The BDD representing the set of variables that are relevant to consider for determining successor
598+
* states. This variable set <i>must</i> include all variables that occur in the transition relation BDD. Moreover,
599+
* for every new-state variable that is in {@code vars}, {@code relnext} considers the corresponding old-state
600+
* variable to be relevant as well, regardless of whether it's included in {@code vars} or not.
601+
* @return The BDD representing the set of successor states from {@code states}.
602+
*/
603+
public abstract BDD relnext(BDD states, BDDVarSet vars);
604+
605+
/**
606+
* Computes {@code and(relnext(states, vars), restriction)} as a single BDD operation.
607+
*
608+
* @param states The BDD representing the set of states.
609+
* @param restriction The BDD representing the restriction to apply to the BDD representing the successor states.
610+
* @param vars The BDD representing the set of relevant variables to consider. See {@link #relnext(BDD, BDDVarSet)
611+
* relnext} for further details.
612+
* @return The BDD representing the restricted set of successor states from {@code states}.
613+
*/
614+
public abstract BDD relnextRestricted(BDD states, BDD restriction, BDDVarSet vars);
615+
616+
/**
617+
* Computes the BDD that represents the set of predecessor states from {@code states}, i.e., the ones reachable by
618+
* taking one backward step from states in {@code states}, where this BDD is the (partial) transition relation to
619+
* consider. It is assumed that old-state and new-state BDD variables are interleaved in this transition relation,
620+
* starting with the old-state variable, i.e., each old-state variable comes directly before its corresponding
621+
* new-state variable.
622+
*
623+
* @param states The BDD representing the set of states.
624+
* @param vars The BDD representing the set of variables that are relevant to consider for determining predecessor
625+
* states. This variable set <i>must</i> include all variables that occur in the transition relation BDD. Moreover,
626+
* for every new-state variable that is in {@code vars}, {@code relprev} considers the corresponding old-state
627+
* variable to be relevant as well, regardless of whether it's included in {@code vars} or not.
628+
* @return The BDD representing the set of predecessor states from {@code states}.
629+
*/
630+
public abstract BDD relprev(BDD states, BDDVarSet vars);
631+
632+
/**
633+
* Computes {@code and(relprev(states, vars), restriction)} as a single BDD operation.
634+
*
635+
* @param states The BDD representing the set of states.
636+
* @param restriction The BDD representing the restriction to apply to the BDD representing the predecessor states.
637+
* @param vars The BDD representing the set of relevant variables to consider. See {@link #relprev(BDD, BDDVarSet)
638+
* relprev} for further details.
639+
* @return The BDD representing the restricted set of predecessor states from {@code states}.
640+
*/
641+
public abstract BDD relprevRestricted(BDD states, BDD restriction, BDDVarSet vars);
642+
589643
/**
590644
* Finds all satisfying variable assignments.
591645
*

src/main/java/com/github/javabdd/BDDFactoryIntImpl.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ public abstract class BDDFactoryIntImpl extends BDDFactory {
8686

8787
protected abstract /* bdd */int veccompose_impl(/* bdd */int v, BDDPairing p);
8888

89+
protected abstract /* bdd */int relnext_impl(/* bdd */int states, /* bdd */int relation, /* bdd */int vars);
90+
91+
protected abstract /* bdd */int relnextRestricted_impl(/* bdd */int states, /* bdd */int relation,
92+
/* bdd */int restriction, /* bdd */int vars);
93+
94+
protected abstract /* bdd */int relprev_impl(/* bdd */int relation, /* bdd */int states, /* bdd */int vars);
95+
96+
protected abstract /* bdd */int relprevRestricted_impl(/* bdd */int relation, /* bdd */int states,
97+
/* bdd */int restriction, /* bdd */int vars);
98+
8999
protected abstract int nodeCount_impl(/* bdd */int v);
90100

91101
protected abstract double pathCount_impl(/* bdd */int v);
@@ -325,6 +335,26 @@ public BDD veccompose(BDDPairing pair) {
325335
public BDDVarSet toVarSet() {
326336
return makeBDDVarSet(v);
327337
}
338+
339+
@Override
340+
public BDD relnext(BDD states, BDDVarSet vars) {
341+
return makeBDD(relnext_impl(unwrap(states), v, unwrap(vars)));
342+
}
343+
344+
@Override
345+
public BDD relnextRestricted(BDD states, BDD restriction, BDDVarSet vars) {
346+
return makeBDD(relnextRestricted_impl(unwrap(states), v, unwrap(restriction), unwrap(vars)));
347+
}
348+
349+
@Override
350+
public BDD relprev(BDD states, BDDVarSet vars) {
351+
return makeBDD(relprev_impl(v, unwrap(states), unwrap(vars)));
352+
}
353+
354+
@Override
355+
public BDD relprevRestricted(BDD states, BDD restriction, BDDVarSet vars) {
356+
return makeBDD(relprevRestricted_impl(v, unwrap(states), unwrap(restriction), unwrap(vars)));
357+
}
328358
}
329359

330360
public class IntBDDWithFinalizer extends IntBDD {

0 commit comments

Comments
 (0)