#!/usr/bin/env python3 """My own search for Heilbronn configurations: softmin continuation, pure Python. Usage: search.py N [SEED] [STARTS] [KEEP] > n.txt Method (own code, no numpy): maximize the smallest triangle by gradient ascent on a smooth softmin S_beta = -log(sum_i exp(-beta * A_i)) / beta over the doubled areas A_i = |cross| of all C(n,3) triangles, with the beta schedule raised over stages (continuation toward the true min). Analytic gradients; coordinates projected onto the unit square by clipping. Random uniform starts, coarse stages on all starts, the best KEEP starts finished at high beta. No literature coordinates are used. The true smallest triangle of the printed configuration is what verify.py judges exactly; floats are printed with 17 decimals so the exact value sits within ~1e-16 of the searched one. """ import itertools import math import random import sys def triples_of(n): return list(itertools.combinations(range(n), 3)) def smallest2(p): """The smallest doubled triangle area, true objective.""" xs = [q[0] for q in p] ys = [q[1] for q in p] best = None for i, j, k in TRI: ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] cr = (bx - ax) * (cy - ay) - (cx - ax) * (by - ay) if cr < 0.0: cr = -cr if best is None or cr < best: best = cr return best def softmin_step(p, tri, beta, step): """One projected gradient ascent step on the softmin; returns (S, true min A2).""" xs = [q[0] for q in p] ys = [q[1] for q in p] n = len(p) gx = [0.0] * n gy = [0.0] * n vals = [] for i, j, k in tri: ax, ay, bx, by, cx, cy = xs[i], ys[i], xs[j], ys[j], xs[k], ys[k] ux = bx - ax uy = by - ay vx = cx - ax vy = cy - ay cr = ux * vy - uy * vx a = cr if cr >= 0.0 else -cr vals.append([a, cr, i, j, k, ux, uy, vx, vy, 0.0]) m = min(v[0] for v in vals) z = 0.0 for v in vals: e = math.exp(-beta * (v[0] - m)) if beta * (v[0] - m) < 700.0 else 0.0 v[9] = e z += e s = m - math.log(z) / beta if z > 0.0 else m inv = 1.0 / z if z > 0.0 else 0.0 for v in vals: a, cr, i, j, k, ux, uy, vx, vy, e = v if e == 0.0: continue w = e * inv # d|cross|/d coord, via sign(cross) * d cross g = w if cr >= 0.0 else -w gx[i] += g * (uy - vy) # d cross/d ax = by-cy = uy-vy gy[i] += g * (vx - ux) # d cross/d ay = cx-bx = vx-ux gx[j] += g * vy # d cross/d bx = cy-ay = vy gy[j] += g * -vx # d cross/d by = -(cx-ax) = -vx gx[k] += g * -uy # d cross/d cx = -(by-ay) = -uy gy[k] += g * ux # d cross/d cy = bx-ax = ux for t in range(n): nx = xs[t] + step * gx[t] ny = ys[t] + step * gy[t] if nx < 0.0: nx = 0.0 elif nx > 1.0: nx = 1.0 if ny < 0.0: ny = 0.0 elif ny > 1.0: ny = 1.0 p[t] = (nx, ny) return s, m def run_start(rng, n, tri, coarse): """Coarse continuation from one random start; returns (best A2, points).""" p = [(rng.random(), rng.random()) for _ in range(n)] best = smallest2(p) kept = p[:] stages = coarse for beta, step, iters in stages: for _ in range(iters): s, m = softmin_step(p, tri, beta, step) if m > best: best = m kept = p[:] return best, kept def main(): global TRI args = [int(a) for a in sys.argv[1:5]] n = args[0] seed = args[1] if len(args) > 1 else 2026 starts = args[2] if len(args) > 2 else 24 keep = args[3] if len(args) > 3 else 4 rng = random.Random(seed) TRI = triples_of(n) coarse = [(30.0, 0.06, 50), (100.0, 0.04, 50), (400.0, 0.02, 60), (1500.0, 0.01, 60), (6000.0, 0.004, 50)] pool = [] for t in range(starts): best, kept = run_start(rng, n, TRI, coarse) pool.append((best, kept, rng.getstate())) pool.sort(reverse=True) pool = pool[:keep] print(f"# start {t + 1}/{starts}: min A2 {best / 2:.8f}", file=sys.stderr) fine = [(30000.0, 0.002, 80), (120000.0, 0.0008, 80), (600000.0, 0.0003, 60), (3000000.0, 0.0001, 60)] final_best, final_p = None, None for best0, kept, st in pool: p = kept[:] best = best0 for beta, step, iters in fine: for _ in range(iters): s, m = softmin_step(p, TRI, beta, step) if m > best: best = m if final_best is None or best > final_best: final_best, final_p = best, p[:] best, p = final_best, final_p print(f"# n = {n}: smallest triangle about {best / 2:.10f} " f"(search.py {n} {seed} {starts} {keep}, softmin continuation)", file=sys.stderr) for x, y in p: print(f"{x:.17f} {y:.17f}") if __name__ == "__main__": main()