#include #define tofiles 1 #define infinity (1<<30) /* close enough */ #define masktype unsigned long int #define ones(x) ((x&1)+((x>>1)&1)+((x>>2)&1)+((x>>3)&1)+((x>>4)&1)+((x>>5)&1)+((x>>6)&1)+((x>>7)&1)+((x>>8)&1)+((x>>9)&1)+((x>>10)&1)+((x>>11)&1)+((x>>12)&1)+((x>>13)&1)+((x>>14)&1)+((x>>15)&1)+((x>>16)&1)+((x>>17)&1)+((x>>18)&1)+((x>>19)&1)+((x>>20)&1)) #define highbit(x) ((x>>15)?(x>>19)?(x>>20)?20:19:(x>>17)?(x>>18)?18:17:(x>>16)?16:15:(x>>7)?(x>>11)?(x>>13)?(x>>14)?14:13:(x>>12)?12:11:(x>>9)?(x>>10)?10:9:(x>>8)?8:7:(x>>3)?(x>>5)?(x>>6)?6:5:(x>>4)?4:3:(x>>1)?(x>>2)?2:1:(x)?0:(-1)) #define max1(a,b) (((a)>b)?((a)>1)?(a):1:((b)>1)?(b):1) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)>(b)?(b):(a)) #define numClasses (1<<(k-1)) #define makesure(op,msg) {if((op)==0){fprintf(stderr,msg);exit(17);}} #define allocErr "Allocation Error" #define printset(x,f) for(c1=0;c1<16;c1++){if(x&(1<1)\n"); exit(1); } sscanf (argv[1],"%d",&ktemp); k = ktemp; b = bA[k]; if (k<2) { fprintf(stderr,"command needs one integer argument (>1)\n"); exit(1); } if (k>20) { fprintf(stderr,"Surely, you jest\n"); exit(1); } maskmaxminus = 1<<(k)-1; maskmaxplus = maskmaxminus*2; makesure(Sminus = (masktype *)calloc(b,sizeof(masktype)),allocErr); makesure(Splus = (masktype *)calloc(b,sizeof(masktype)),allocErr); makesure(j = (signed char *)calloc(b,sizeof(char)),allocErr); makesure(minK = (signed char *)calloc(b,sizeof(char)),allocErr); makesure(SclassMap = (unsigned long int *)calloc(numClasses,sizeof(long int)),allocErr); // makesure(Sclass =(unsigned long int *)calloc(b,sizeof(long int)),allocErr); makesure(succs = (unsigned long int *)calloc(numClasses*k,sizeof(long int)),allocErr); makesure(succInx=(unsigned long int *)calloc(b,sizeof(long int)),allocErr); makesure(preds = (unsigned long int *)calloc(numClasses*(k+1),sizeof(long int)),allocErr); makesure(predInx=(unsigned long int *)calloc(b,sizeof(long int)),allocErr); makesure(predLoc=(signed char *)calloc(b,sizeof(char)),allocErr); makesure(predCount = (unsigned long int *)calloc(numClasses,sizeof(long int)),allocErr); for (c=0;c>10)+1); // bracket(h,k); // h2=1; SclassCount=succCount=0; for (candSplus=0; candSplus<=maskmaxplus; candSplus+=2) { maskmaxtemp = min(maskmaxminus,(1<<(k-(highPlus=highbit(candSplus))))-1); // if (candSplus>>h2) {h2++;dotC;} for (candSminus=0; candSminus<=maskmaxtemp; candSminus++) { if (ones(candSplus) == ones(candSminus)) { highMinus=highbit(candSminus); SclassMap[SclassCount]=succCount; for (candj=1; candj>10)+1); } for (candSclass=0;candSclass>1) ==(Splus[candSrce]-(1<<(-j[candSrce]))))); } else /* situation (b) */ { adj=(((Sminus[candDest]<<1)==Sminus[candSrce]) && ((Splus[candDest]>>1)==(Splus[candSrce]+1-(1<<(-j[candSrce]))))); } } else if (j[candSrce]>0) { if (Sminus[candSrce]&1) /* situation (d) */ { adj=(((Splus[candDest]>>1)==Splus[candSrce]) && ((Sminus[candDest]<<1)==(Sminus[candSrce]-1+(1<<(j[candSrce]))))); } else /* situation (e) */ { adj=(((Splus[candDest]>>1)==(Splus[candSrce]+1)) && ((Sminus[candDest]<<1) ==(Sminus[candSrce]+(1<<(j[candSrce]))))); } } else /* situation (c) */ { if (((Splus[candDest]>>1)==Splus[candSrce]) && ((Sminus[candDest]<<1)==Sminus[candSrce])) {adj=1;} } } if (adj) /* there is an arc from candSrce to candDest */ { succInx[candSrce]=candSclass; preds[candSclass*(k+1)+predCount[candSclass]]=candSrce; predLoc[candSrce]=predCount[candSclass]; predCount[candSclass]++; candSclass=numClasses; } } } for (predsCount=predsPoint=c=0;c