/* ML type: varnum vector -> varnum vector -> pairSet */ EXTERNML value mlbdd_makepairset(value oldvar, value newvar) /* ML */ { int size, i, *o, *n; bddPair *pairs; value result; size = Wosize_val(oldvar); /* we use stat_alloc which guarantee that we get the memory (or it will raise an exception). */ o = (int *) stat_alloc(sizeof(int) * size); n = (int *) stat_alloc(sizeof(int) * size); for (i=0; i<size; i++) { o[i] = Int_val(Field(oldvar, i)); n[i] = Int_val(Field(newvar, i)); } pairs = bdd_newpair(); bdd_setpairs(pairs, o, n, size); /* memory allocated with stat_alloc, should be freed with stat_free.*/ stat_free((char *) o); stat_free((char *) n); result = mlbdd_alloc_final(2, &mlbdd_pair_finalize); PairSet_val(result) = pairs; return result; }
int main(int argc, char** argv) { bdd *c, *cp, *h, *hp, *t, *tp; bdd I, T, R; int n; if(argc < 2) { printf("usage: %s N\n",argv[0]); printf("\tN number of cyclers\n"); exit(1); } N = atoi(argv[1]); if (N <= 0) { printf("The number of cyclers must more than zero\n"); exit(2); } bdd_init(100000, 10000); bdd_setvarnum(N*6); c = (bdd *)malloc(sizeof(bdd)*N); cp = (bdd *)malloc(sizeof(bdd)*N); t = (bdd *)malloc(sizeof(bdd)*N); tp = (bdd *)malloc(sizeof(bdd)*N); h = (bdd *)malloc(sizeof(bdd)*N); hp = (bdd *)malloc(sizeof(bdd)*N); normvar = (int *)malloc(sizeof(int)*N*3); primvar = (int *)malloc(sizeof(int)*N*3); for (n=0 ; n<N*3 ; n++) { normvar[n] = n*2; primvar[n] = n*2+1; } normvarset = bdd_addref( bdd_makeset(normvar, N*3) ); pairs = bdd_newpair(); bdd_setpairs(pairs, primvar, normvar, N*3); for (n=0 ; n<N ; n++) { c[n] = bdd_ithvar(n*6); cp[n] = bdd_ithvar(n*6+1); t[n] = bdd_ithvar(n*6+2); tp[n] = bdd_ithvar(n*6+3); h[n] = bdd_ithvar(n*6+4); hp[n] = bdd_ithvar(n*6+5); } I = bdd_addref( initial_state(t,h,c) ); T = bdd_addref( transitions(t,tp,h,hp,c,cp) ); R = bdd_addref( reachable_states(I,T) ); /*if(has_deadlocks(R,T)) printf("Milner's Scheduler has deadlocks!\n"); */ printf("SatCount R = %.0f\n", bdd_satcount(R)); printf("Calc = %.0f\n", (double)N*pow(2.0,1.0+N)*pow(2.0,3.0*N)); bdd_done(); return 0; }