Devlog #91 – Wave 70: CPM/PERT, k-NN, Buckling, Minimax Tree, Van Allen Belt & Lloyd Relaxation

Wave 70 spans engineering project scheduling, machine learning geometry, structural mechanics, game tree search, space physics, and computational geometry — six simulations that each reveal a beautiful mathematical structure hiding in everyday problems.

Wave 70 — 6 simulations added
621
Total simulations
6
New this wave
70
Wave number
91
Devlog #

New Simulations

📋

CPM/PERT Critical Path

Kahn topological sort + forward/backward passes on a DAG. Critical path in red (slack = 0). PERT three-point estimates with deadline probability via normal CDF. Drag durations to update live.

📊

k-Nearest Neighbours

80×60 decision region heatmap. 4 classes, 5 presets. Euclidean/Manhattan/Chebyshev distances. Uniform vs 1/d² weighting. LOOCV accuracy + k-accuracy curve showing overfit vs smoothing.

🏗️

Euler Column Buckling

P_cr = π²EI/(KL)². Four boundary conditions with K factors. Weak-axis I for rectangular/circular/I-beam. Johnson parabola transition for stocky columns. Pitchfork bifurcation plot.

♟️

Minimax with Alpha-Beta Pruning

DFS post-order minimax + α-β window pruning. Greyed subtrees show pruned branches. Best-first move ordering vs random: dramatic difference in nodes visited. 3 preset trees + random generator.

☢️

Van Allen Belt

Dipole magnetic field. Rotational Lorentz integrator. Spiral, mirror, and drift motion. Loss cone calculation. Correct L-shell field formula. Proton/electron with realistic mass ratio 1836.

Lloyd Relaxation

Iterative centroid shift on pixel-painted Voronoi. Energy E = Σρ|x-c|² decreases monotonically. 4 density modes. Delaunay overlay. Std-dev of areas converges to zero at equilibrium.

CPM/PERT: Critical Path Analysis

Project scheduling has a beautiful graph-theoretic backbone. The Critical Path Method (CPM) and Program Evaluation and Review Technique (PERT) share the same DAG structure but differ in how they handle activity duration uncertainty.

Topological Sort and Forward/Backward Pass

Kahn's algorithm finds a valid topological ordering of the activity DAG by repeatedly removing nodes with in-degree zero. The forward pass then computes Early Start and Early Finish times: ES_i = max(EF_j) over all predecessors j, and EF_i = ES_i + duration_i. The backward pass sets the project deadline and propagates backward: LS_i = LF_i − duration_i, LF_i = min(LS_k) over all successors k. Activities with zero float (LF − EF = 0) form the critical path — any delay there delays the whole project.

PERT Three-Point Estimation

PERT addresses duration uncertainty with three estimates per activity: optimistic (o), most likely (m), and pessimistic (p). The expected duration is t_e = (o + 4m + p) / 6 and the variance σ² = ((p−o)/6)². The project completion time is approximately normal with μ = sum of critical path expected durations and σ² = sum of critical path variances. The deadline probability panel shows the normal CDF P(T < deadline).

k-NN: Decision Boundaries from Local Voting

k-Nearest Neighbours is the archetypal non-parametric classifier — it makes no assumptions about the data distribution, storing all training points and classifying each query by majority vote among its k nearest neighbours.

Decision Region Computation

The simulation renders an 80×60 decision region grid — each cell is classified independently and coloured by class. Three distance metrics are offered: Euclidean (L2 norm, circular neighbourhoods), Manhattan (L1 norm, diamond-shaped), and Chebyshev (L∞ norm, square neighbourhoods). With 1/d² distance-weighting, closer neighbours cast stronger votes, producing smoother boundaries near training points.

Bias-Variance Trade-off via LOOCV

Leave-one-out cross-validation removes each training point, classifies it using the remaining points, and counts correct predictions. The k-accuracy curve reveals the fundamental trade-off: k=1 perfectly memorises the training set (overfitting, high variance) but generalises poorly; large k smooths the boundary but may underfit. The optimal k sits at the curve's peak.

Euler Column Buckling: Structural Stability

When a slender column under axial compression reaches Euler's critical load, it snaps sideways in a pitchfork bifurcation — the straight equilibrium becomes unstable and two buckled equilibria emerge. This is one of the most important structural failure modes in engineering.

Critical Load and Effective Length

The Euler critical load formula is P_cr = π²EI / (KL)² where E is Young's modulus, I is the second moment of area about the weak axis, L is the physical length, and K is the effective-length factor that depends on boundary conditions:

Johnson Parabola for Stocky Columns

Euler's formula is only valid for slender columns (KL/r > π√(2E/σ_y) where r = √(I/A) is the radius of gyration). For shorter columns, material yielding occurs before elastic buckling. The Johnson parabola P_cr/A = σ_y − (σ_y²/4π²E)(KL/r)² smoothly transitions from the yield limit to the Euler curve at the tangent point, covering the full slenderness range.

Minimax with Alpha-Beta Pruning

Minimax is the foundation of adversarial game tree search: the maximiser player picks the move with the highest minimax value; the minimiser picks the lowest. Alpha-beta pruning eliminates branches that cannot possibly affect the final decision — without changing the result, only the speed.

Alpha-Beta Window

Each node maintains a window (α, β) where α is the best score the maximiser is guaranteed and β is the best the minimiser is guaranteed. Pruning occurs when β ≤ α: the minimiser at a node has found a value ≤ α, so the maximiser above will never visit this node anyway. Grey subtrees in the visualisation show exactly which branches are cut.

The Power of Move Ordering

Alpha-beta's pruning effectiveness depends critically on move order. In the best case (best move always tried first), it reduces the node count from O(b^d) to O(b^(d/2)) — effectively doubling the search depth. The simulation runs random ordering and best-first ordering simultaneously, showing visited node counts that can differ by a factor of 5× or more on the same tree.

Van Allen Belt: Dipole Particle Trapping

The Van Allen radiation belts are zones of energetic charged particles trapped by Earth's magnetic dipole field. A charged particle in a magnetic field spirals around field lines, bounces between magnetic mirrors, and slowly drifts around the planet — three nested periodic motions.

Dipole Field and Lorentz Force

The magnetic dipole field components are B_r = 3rz/R⁵ and B_z = (3z²−R²)/R⁵ (in cylindrical coordinates). The Lorentz integrator advances the velocity via a rotation: half-kick, then rotate v around B by angle ω_c·dt (cyclotron frequency ω_c = qB/m), then half-kick. This conserves the magnetic moment μ = mv²_⊥/2B exactly for small dt.

Mirror and Drift Motion

As a particle spirals toward a magnetic pole, field lines converge and B increases. Since μ is adiabatically conserved, the perpendicular kinetic energy must increase — so parallel kinetic energy decreases to zero and the particle mirrors back. The loss cone is defined by sin²α_lc = B_equator/B_atmosphere; particles with pitch angles inside the loss cone hit the atmosphere. The L-shell parameter uses the exact formula B(L,λ) = (1/L³)√(1+3sin²λ)/cos⁶λ.

Lloyd Relaxation: Centroidal Voronoi Tessellation

Lloyd's algorithm (1982) iteratively improves a Voronoi tessellation toward a centroidal configuration where each site sits exactly at the centroid of its cell. The result is a beautifully uniform tiling used in mesh generation, halftoning, and facility location.

The Centroid Update and Energy Decrease

Each iteration: compute the Voronoi diagram, find the area centroid of each cell c = (Σw(x)·x / Σw(x)) weighted by a density function ρ(x), then move each site to its centroid. The quantisation energy E = Σ_i ∫_{V_i} ρ(x)|x−c_i|² dx decreases monotonically — Lloyd's is a coordinate descent on this energy. Convergence is guaranteed but can be slow near equilibrium; the energy inset graph shows the characteristic fast initial drop followed by a long tail.

Up Next

Wave 71 continues with PageRank power iteration (and dangling-node fix), Axelrod's round-robin iterated prisoner's dilemma tournament with 10 canonical strategies, Lichtenberg figure dielectric breakdown via SOR Laplace solver, PID controller tuning with Ziegler-Nichols autotuning, Archimedes principle with exact submerged-volume formulas for three hull shapes, and Paris-law fatigue crack growth with catastrophic fracture at K_IC.

← Devlog #90 Devlog #92 →