// returns 1 on success, 0 if there are no cubes extern int firstCube( int r, int n, int cube[] ) { int origR = r; memset(cube, -1, n*sizeof(*cube) ); while( r >= 2 ) { cube[bdd_level2var(LEVEL(r))] = 0; r = LOW(r); } if( r == 0 ) return nextCube( origR, n, cube ); else return 1; }
// returns -1 if we're already at the last path, 0 if the next path is // non-accepting, 1 if the next path is accepting int nextPath( int r, int n, int cube[] ) { int stack[n]; int top = 0; int top0 = 0; int i; while( r >= 2 ) { stack[top++] = r; if( cube[bdd_level2var(LEVEL(r))] == 0 ) { top0 = top; r = LOW(r); } else if( cube[bdd_level2var(LEVEL(r))] == 1 ) { r = HIGH(r); } else { for( i = 0; i < n; i++ ) fprintf(stderr, "%d ", cube[i]); fprintf( stderr, "internal error %d\n", cube[bdd_level2var(LEVEL(r))] ); *((int*)0) = 5; } } // No zeros => we're already at the last path. if( top0 == 0 ) return -1; // Cut off the end of the path. for( i = top0; i < top; i++ ) { cube[bdd_level2var(LEVEL(stack[i]))] = -1; } // Switch the zero to a one. r = stack[top0-1]; cube[bdd_level2var(LEVEL(r))] = 1; r = HIGH(r); // Fill in the other zeros. while(1) { if( r < 2 ) return r; cube[bdd_level2var(LEVEL(r))] = 0; r = LOW(r); } }
/* ML type: level -> varnum */ EXTERNML value mlbdd_bdd_level2var(value lev) /* ML */ { return Val_long(bdd_level2var(Int_val(lev))); }