Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cargo test -p tiling-search # the search, on random tili

uv run maxplus-solve new5-flat --max-solutions all --validate # run a solver from the command line
uv run maxplus-solve new5 --mode relief --option lookahead=true --option order=random --seed 3
uv run maxplus-solve rat1-flat --solver cp_sat.placements --max-solutions all --option coverage=false # CP-SAT, needs the cp-sat extra
uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab # regenerate fixtures and keys
uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab --check # compare, write nothing
```
Expand All @@ -40,7 +41,7 @@ uv run python scripts/import_fixtures.py --source ../tropical-puzzle-lab --check

- `crates/tiling-core`: domain types. No dependencies on the other crates.
- `crates/tiling-geometry`: convex geometry, contact matching, candidate generation, cavities. Depends on core. Primitives take `&[Vec2]`; proptest strategies are in `src/testing.rs`, public behind the `testing` feature so that `tiling-search` can test on the same random tilings.
- `crates/tiling-search`: custom solvers, one module each (`contact_dfs`), and `canonical`, which decides when two assemblies are the same. Depends on core and geometry.
- `crates/tiling-search`: custom solvers, one module each (`contact_dfs`), `enumerate`, which lists placements and their conflicts for solvers that choose from a list, and `canonical`, which decides when two assemblies are the same. Depends on core and geometry.
- `crates/tiling-py`: PyO3 bindings, built by maturin as `maxplus_solvers._native`. Converts types and forwards calls; no algorithms.
- `python/maxplus_solvers`: the user-facing package: models, importers, solver adapters, validation, experiments. When a function is added to `_native`, add it to `_native.pyi` too. `_native` takes a polygon as a sequence of pairs, a pose as `(x, y, theta)` and a roof as `(z0, gx, gy)`.
- `models.py` holds the contracts; `schemas/instance-v1.json` is their JSON form and `tiling-core` mirrors the instance types. Change all three together.
Expand Down Expand Up @@ -87,7 +88,8 @@ Rules:
- **Slow tests still run.** The `slow` marker is for deselecting locally (`-m "not slow"`); CI runs everything.
- **Completeness and uniqueness are explicit claims.** A result says whether the search was exhaustive and over which candidate set. "No solution found" and CP-SAT `INFEASIBLE` are relative to the candidates generated unless completeness is proven.
- **Layering is one-way:** core ← geometry ← search ← py. Python reaches Rust only through `_native`.
- **Production solvers cross the Python/Rust boundary once per solve.** Prototypes may call individual geometry primitives; a Rust solver receives the instance and runs to completion.
- **Production solvers cross the Python/Rust boundary once per solve.** Prototypes may call individual geometry primitives; a Rust solver receives the instance and runs to completion. `cp_sat.placements` makes its one call for the list of placements and their conflicts; everything it then needs, down to which placement a tray rotation turns each into, is in that answer.
- **A model solver knows no geometry.** `solvers/cp_sat.py` builds constraints from the indices `_native.placement_model` returns and never computes with a placement's coordinates. CP-SAT runs with one worker and no objective, so that its counts can be repeated.
- **Units are millimetres and radians,** matching the browser player. Polygons are convex and counter-clockwise, in local coordinates about the area centroid. A pose rotates by `theta` then translates by `(x, y)`.
- **`f64` with explicit tolerances is not exactness.** Don't describe a floating-point result as a mathematical proof.
- **Optional dependencies stay optional.** OR-Tools, Shapely and the analysis stack are extras; the Rust solvers must run without them.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Python owns orchestration and analysis. Rust owns the geometry and the search.

## Status

**Contracts and fixtures.** The instance format, the sanitizing importer and the benchmark corpus exist: 16 puzzles from Tropical Puzzle Lab and 4 synthetic ones with known solution counts, each with an answer key that only tests read. An independent validator checks an assembly against the browser player's completion rules. The Rust geometry kernel (separating-axis depth, convex clipping, containment, edge signatures, roof continuity) is in place and agrees with the validator on random poses of every fixture's pieces. Two solvers exist. `python.contact_dfs` is a Python prototype of the contact search. `rust.contact_dfs` is that search in Rust with roofs, pruning and symmetry handling: it solves all 16 corpus puzzles, runs every search to its end, and returns assemblies that pass the validator. Each of its rules can be switched off, because the question here is what makes a puzzle hard and what helps, not how fast one solver is; [docs/algorithms.md](docs/algorithms.md) has the measurements. The work is laid out in [docs/roadmap.md](docs/roadmap.md), and the design in [docs/architecture.md](docs/architecture.md).
**Contracts and fixtures.** The instance format, the sanitizing importer and the benchmark corpus exist: 16 puzzles from Tropical Puzzle Lab and 4 synthetic ones with known solution counts, each with an answer key that only tests read. An independent validator checks an assembly against the browser player's completion rules. The Rust geometry kernel (separating-axis depth, convex clipping, containment, edge signatures, roof continuity) is in place and agrees with the validator on random poses of every fixture's pieces. Three solvers exist. `python.contact_dfs` is a Python prototype of the contact search. `rust.contact_dfs` is that search in Rust with roofs, pruning and symmetry handling: it solves all 16 corpus puzzles, runs every search to its end, and returns assemblies that pass the validator. `cp_sat.placements` hands the placements that search reaches to OR-Tools CP-SAT as a plain choice problem, and returns the same assemblies by other means. Each rule of either can be switched off, because the question here is what makes a puzzle hard and what helps, not how fast one solver is; [docs/algorithms.md](docs/algorithms.md) has the measurements. The work is laid out in [docs/roadmap.md](docs/roadmap.md), and the design in [docs/architecture.md](docs/architecture.md).

```python
from maxplus_solvers import load_puzzle
Expand Down
45 changes: 10 additions & 35 deletions crates/tiling-geometry/src/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::cavity::{Cavity, cavities};
use crate::contact::{ContactTolerance, Corner, EdgeRef, free_corners, pose_at_corner};
use crate::graph::{EdgeGraph, Shape};
use crate::polygon::{is_convex_ccw, outside_depth, transform};
use crate::relief::{roof_height, seam_mismatch};
use crate::relief::{roof_height, seam_step};
use crate::sat::penetration_depth;

/// One way to put a piece down, and the contact that produced it.
Expand Down Expand Up @@ -298,7 +298,6 @@ impl Assembly {
return 0.0;
};
let reach = bounds(world);
let n = world.len();
let mut worst: f64 = 0.0;
for &other in &self.stack {
let Some(other_roof) = &self.shapes[other].roof else {
Expand All @@ -311,39 +310,15 @@ impl Assembly {
else {
continue;
};
let m = other_world.len();
for i in 0..n {
let (a0, a1) = (world[i], world[(i + 1) % n]);
let length = (a1[0] - a0[0]).hypot(a1[1] - a0[1]);
let u = [(a1[0] - a0[0]) / length, (a1[1] - a0[1]) / length];
for j in 0..m {
let (b0, b1) = (other_world[j], other_world[(j + 1) % m]);
// Position of a point along this edge, and its distance off the edge's line.
let along = |p: Vec2| u[0] * (p[0] - a0[0]) + u[1] * (p[1] - a0[1]);
let off = |p: Vec2| (u[0] * (p[1] - a0[1]) - u[1] * (p[0] - a0[0])).abs();
// A neighbour's edge on the same line runs the other way.
let (start, end) = (along(b1), along(b0));
if end <= start
|| off(b0) > self.tolerance.length
|| off(b1) > self.tolerance.length
{
continue;
}
let (from, to) = (start.max(0.0), end.min(length));
if to - from <= self.tolerance.length {
continue;
}
let at = |t: f64| [a0[0] + t * u[0], a0[1] + t * u[1]];
worst = worst.max(seam_mismatch(
roof,
pose,
other_roof,
other_pose,
at(from),
at(to),
));
}
}
worst = worst.max(seam_step(
world,
roof,
pose,
other_world,
other_roof,
other_pose,
self.tolerance.length,
));
}
worst
}
Expand Down
Loading
Loading