An interactive MCMC Triangulation Explorer that simulates 2-2 Pachner moves (diagonal flips) on a triangulated grid, using Metropolis-Hastings sampling with path length as the Hamiltonian.
- Click to flip — Click any grid cell to perform a Pachner 2-2 move (diagonal flip)
- BFS shortest path — Automatically finds and renders the shortest path from START → END
- MCMC sampling — Metropolis-Hastings with configurable temperature and step count
- Animated MCMC — Watch the Markov chain explore triangulation space in real-time
- Energy histograms — Visualize the Boltzmann distribution over path lengths
- Configurable grid — Resize from 2×2 to 10×10 cells
cd web
python3 -m http.server 8080
# Open http://localhost:8080make
./pachner_sim # Interactive mode
./pachner_sim -m 500 # MCMC batch mode (500 steps)
./pachner_sim -m 500 -t 0.5 # With temperature 0.5
./pachner_sim -s 6 6 # Custom grid sizeIn 2D, a Pachner 2-2 move (also called a bistellar flip) flips the shared diagonal of two adjacent triangles in a triangulation. Given a quadrilateral divided by a \ diagonal, flipping it produces a / diagonal and vice versa.
| Concept | Implementation |
|---|---|
| State space | All 2^(n×m) triangulations of the grid |
| Transition | Pachner 2-2 move (diagonal flip) |
| Hamiltonian H | Shortest path length from START → END |
| Ground state | Triangulation minimizing path length |
| Metropolis criterion | Accept if ΔE ≤ 0; else accept with prob exp(−ΔE/T) |
PachnerGrid (state) → PathFinder (BFS) → Renderer (Canvas/Terminal)
↑
flip(r,c) = Pachner move = MCMC transition
MCMCAlgo/
├── web/ # Web application (localhost)
│ ├── index.html # Main page
│ ├── styles.css # Dark theme styling
│ └── app.js # Grid, pathfinding, MCMC, Canvas rendering
├── main.cpp # C++ interactive + MCMC batch mode
├── PachnerGrid.h # Grid data structure with flip logic
├── PathFinder.h # BFS shortest path
├── Renderer.h # ANSI terminal renderer
└── Makefile # C++17 build system
MIT