@@ -56,3 +56,79 @@ MTBDD BDDTools::pathsToSubroot(MTBDD root, uint32_t firstVar, MTBDD subroot)
5656{
5757 return RUN (paths_to_subroot, root, firstVar, subroot);
5858}
59+
60+ /* *
61+ * Encode a state as a BDD, using statebits 0..<statebits>, offsetted by <offset>+<priobits>
62+ * High-significant bits come before low-significant bits in the BDD
63+ */
64+ MTBDD BDDTools::encode_state (uint32_t state, MTBDD statevars)
65+ {
66+ // convert statevars to stack
67+ std::vector<unsigned int > vars;
68+ while (statevars != mtbdd_set_empty ()) {
69+ vars.push_back (mtbdd_set_first (statevars));
70+ statevars = mtbdd_set_next (statevars);
71+ }
72+ // create a cube
73+ auto cube = mtbdd_true;
74+ while (!vars.empty ()) {
75+ auto var = vars.back ();
76+ vars.pop_back ();
77+ if (state & 1 ) cube = mtbdd_makenode (var, mtbdd_false, cube);
78+ else cube = mtbdd_makenode (var, cube, mtbdd_false);
79+ state >>= 1 ;
80+ }
81+ return cube;
82+ }
83+
84+ /* *
85+ * Encode priority i.e. all states via priority <priority>
86+ */
87+ MTBDD BDDTools::encode_prio (int priority, int priobits)
88+ {
89+ MTBDD cube = mtbdd_true;
90+ for (int i=0 ; i<priobits; i++) {
91+ if (priority & 1 ) cube = mtbdd_makenode (priobits-i-1 , mtbdd_false, cube);
92+ else cube = mtbdd_makenode (priobits-i-1 , cube, mtbdd_false);
93+ priority >>= 1 ;
94+ }
95+ return cube;
96+ }
97+
98+
99+ /* *
100+ * Encode a priostate as a BDD, with priobits before statebits
101+ * High-significant bits come before low-significant bits in the BDD
102+ */
103+ MTBDD BDDTools::encode_priostate (uint32_t state, uint32_t priority, MTBDD statevars, MTBDD priovars)
104+ {
105+ // convert statevars to stack
106+ std::vector<unsigned int > vars;
107+ while (statevars != mtbdd_set_empty ()) {
108+ vars.push_back (mtbdd_set_first (statevars));
109+ statevars = mtbdd_set_next (statevars);
110+ }
111+ // create the cube
112+ auto cube = mtbdd_true;
113+ while (!vars.empty ()) {
114+ auto var = vars.back ();
115+ vars.pop_back ();
116+ if (state & 1 ) cube = mtbdd_makenode (var, mtbdd_false, cube);
117+ else cube = mtbdd_makenode (var, cube, mtbdd_false);
118+ state >>= 1 ;
119+ }
120+ // convert priovars to stack
121+ while (priovars != mtbdd_set_empty ()) {
122+ vars.push_back (mtbdd_set_first (priovars));
123+ priovars = mtbdd_set_next (priovars);
124+ }
125+ // create the rest of the cube
126+ while (!vars.empty ()) {
127+ auto var = vars.back ();
128+ vars.pop_back ();
129+ if (priority & 1 ) cube = mtbdd_makenode (var, mtbdd_false, cube);
130+ else cube = mtbdd_makenode (var, cube, mtbdd_false);
131+ priority >>= 1 ;
132+ }
133+ return cube;
134+ }
0 commit comments