#include #include "util.h" #include "cudd.h" /* Towers of Hanoi problem using BDDs */ #define SIZE 10 /* number of disks */ /* number of towers = 3 */ DdManager * manager; /* BDD Manager */ DdNode * v1[SIZE][3]; /* the current state */ DdNode * v2[SIZE][3]; /* the next state */ /* v[i][j] = 1 means that disk i is in tower j */ DdNode * make_a_move(int i,int j,int k); DdNode * compute_image(DdNode * R, DdNode * T, DdNode * cube); int main(int argv, char ** argc) { DdNode * I; /* the initial state BDD */ DdNode * E; /* the final state BDD */ DdNode * T; /* the transition relation */ DdNode * R; DdNode * image; int i,j,found,num_steps; DdNode * tmp1, *tmp2; DdNode * cube; /* Initialize the BDD manager with default options */ manager = Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); /* enable dynamic reordering */ Cudd_AutodynEnable(manager,CUDD_REORDER_SAME); /* the cuurent and next state variables are interleaved, usually a good ordering to start with */ for(i=0;i=0;l--) { tmp1 = Cudd_bddAnd(manager,result,Cudd_Not(v1[l][j])); Cudd_Ref(tmp1); Cudd_RecursiveDeref(manager,result); result = tmp1; tmp1 = Cudd_bddAnd(manager,result,Cudd_Not(v1[l][k])); Cudd_Ref(tmp1); Cudd_RecursiveDeref(manager,result); result = tmp1; } /* move the current disk to tower k */ tmp1 = Cudd_bddAnd(manager,result,v2[i][k]); Cudd_Ref(tmp1); Cudd_RecursiveDeref(manager,result); result = tmp1; tmp1 = Cudd_bddAnd(manager,result,Cudd_Not(v2[i][(k+1)%3])); Cudd_Ref(tmp1); Cudd_RecursiveDeref(manager,result); result = tmp1; tmp1 = Cudd_bddAnd(manager,result,Cudd_Not(v2[i][(k+2)%3])); Cudd_Ref(tmp1); Cudd_RecursiveDeref(manager,result); result = tmp1; /* the other disks stay where they are */ for(l=0;l