inire/docs/complex-routing-example-1.md

124 lines
7.5 KiB
Markdown
Raw Normal View History

# Complex-routing example 1
Follow the outer return, `net_08`, from the input ports to its final eastbound arrival. Run from the repository root.
```sh
python examples/advanced_layouts.py \
--case complex-routing-example-1 \
--output-dir /tmp/inire-complex-routing-example-1
```
Origin. [Board 1 from Terminal-Bench pull request 345](https://raw.githubusercontent.com/harbor-framework/terminal-bench/249d125b59c0a5352d9e132195cfead6d81446be/tasks/photonic-waveguide-routing/environment/layout_spec.json).
## 1. Load the board and set the routing target
The 2,500 by 1,000 board has seven keepouts and nine nets. Width is 2, clearance is 6, and both bend radii are 50. All ports require eastbound travel. Automatic starts with a target of nine verified nets after checking port conflicts and track capacity.
![The nine input nets surround seven rectangular keepouts. A cut at x = 500 has openings at the bottom, center, and top of the board.](figures/complex-routing-example-1-input.png)
Open circles mark sources and filled squares mark targets. The inset shows 24 tracks fitting through the purple cut after allowing for width and clearance.
- [Board inputs](../examples/advanced-layouts.json)
- [Problem builder](../examples/advanced_layouts.py#L37)
- [Capacity calculation](../inire/router/_capacity.py#L29)
## 2. Assign lanes and compile path seeds
The bundle planner groups nets by their passages and spaces the lanes at a pitch of 9. The first `net_08` plan takes the bottom lane at `y = 1`, rises on the right, and approaches its target heading west.
![Colored waypoint lines separate the lower, upper, short, and return routes. A close-up shows net_08 at y = 1 and net_00 at y = 10 beneath the tower.](figures/complex-routing-example-1-lanes.png)
The dots mark waypoints. In the lower inset, only `net_08` and `net_00` fit below the tower. The planner compiles straight runs, right-angle corners, and diagonals into straight, quarter-turn, and S-bend seeds.
- [Lane assignment](../inire/router/_bundle.py#L114)
- [Waypoint compiler](../inire/router/_waypoints.py#L33)
## 3. Fit the required eastbound arrival
The turnaround planner shifts the upper shelf route `net_07` and brings `net_08` beneath it. The return rises west of its target and takes a final right turn. The planner recompiles both changed seeds.
![Two views show the materialized shelf and return paths. In the initial plan net_08 arrives westbound. In the turnaround candidate it passes below the shelf, rises left of the target, and arrives eastbound.](figures/complex-routing-example-1-turnaround.png)
Compare the heading arrows above the red target squares.
- [Turnaround candidates](../inire/router/_perimeter.py#L103)
## 4. Verify the seeds and refine the layout
A worker in mode `off` replays the `bundle-turnaround` seeds with a zero-node budget. It checks the resulting polygons against the board, keepouts, and other routes. All nine verify, so automatic skips search.
![The upper panel shows the physical paths of the first four nets in installation order. The lower panel shows all nine paths after verification.](figures/complex-routing-example-1-verification.png)
The upper panel shows the first four paths in installation order. The lower panel shows all nine checked together.
Automatic replays the seeds again with refinement enabled. The refiner replaces sections of `net_05` and `net_07`, preserving all nine verified nets and lowering the configured objective.
![The refined net_07 stays near the top edge longer and descends close to its target. Its earlier approach is dashed, and the outer return remains visible below it.](figures/complex-routing-example-1-refinement.png)
Compare the solid and dashed approaches of `net_07` near the top edge.
- [Seeded worker](../inire/router/_automatic.py#L173)
- [Physical verification](../inire/geometry/collision.py#L687)
- [Refinement handoff](../inire/router/_automatic.py#L610)
## 5. Inspect the result
Find the two stages under `runs[0].samples[0].stages` in the benchmark JSON. Both report zero A* expansions.
```sh
python -m scripts.compare_topological_routing \
--case complex-routing-example-1 --profile public-defaults --mode automatic \
--json /tmp/inire-complex-routing-example-1-stages.json
```
| Stage | Planner | Operation | Verified nets |
| --- | --- | --- | --- |
| 0 | `bundle-turnaround` | Verify the compiled seeds | 9 |
| 1, selected | `bundle-turnaround` | Refine and verify the layout | 9 |
The point-terminal variant accepts a westbound arrival for `net_08`, so the original bundle needs no turnaround. Rerun the gallery command with `--case complex-routing-example-1-point-terminals` to see the result.
- [Both layouts in the gallery](../examples/advanced.md#complex-routing-example-1)
- [Waypoint export](benchmark-fixtures.md#complex-routing-example-1)
## Compare all routing modes
Each run uses 100 nodes per search and one congestion iteration, with warm start and refinement disabled. Set `infer_terminal_headings=True` for `bundle` so `net_08` can arrive westbound. Fixed eastbound headings raise a mismatch in that mode.
| Mode | With triangulation available | Without triangulation |
| --- | --- | --- |
| `automatic` | 9/9 verified. The turnaround plan completes the layout without building a mesh. | 9/9 verified through the same turnaround plan. Automatic uses lattice search if constructive planning leaves work. |
| `off` | 0/9 verified at this budget. The worker runs lattice search directly. | Same search and result. |
| `guide` | 1/9 verified. The worker builds a mesh and suggests corridors to lattice search. | Raises a dependency error when planning corridors. |
| `seed` | 1/9 verified. The worker builds a mesh and searches for starting paths inside the corridors before its routing iteration. | Raises a dependency error when planning corridors. |
| `bundle` | 9/9 verified. The worker builds and verifies ordered tracks directly from the board geometry. | Same plan and result. |
![Five panels show route outcomes at the same search budget. Automatic and bundle verify all nine nets. Off, guide, and seed leave partial paths.](figures/complex-routing-example-1-modes.png)
### Triangulation support
An active corridor search needs Shapely 2.1+ with GEOS 3.10+. Check the versions in the environment that runs Inire.
```sh
python -c 'import shapely; print(shapely.__version__, shapely.geos_version_string)'
```
Automatic builds a mesh when it reaches corridor search on a compatible backend. Here the turnaround plan finishes first. Shapely 2.0.7 supports lattice and constructive routing. Guide and seed can also replay supplied paths without a mesh at `node_limit=0`.
- [Shapely installation](https://shapely.readthedocs.io/en/2.1.2/installation.html)
- [Constrained triangulation API](https://shapely.readthedocs.io/en/2.1.2/reference/shapely.constrained_delaunay_triangles.html)
## Compare a guide-mode search
To see the corridor model on the same board, run `net_08` on its own in guide mode.
![A triangle mesh and highlighted cells guide the isolated net toward its target. A zoom near the source shows purple expanded positions and a red partial path ending before the target.](figures/complex-routing-example-1-guide.png)
Left, the mesh, green corridor cells, and dashed guide. Right, purple expanded positions and the red partial path at the 12-node limit.
```sh
python -m scripts.render_complex_routing_example --output-dir /tmp/inire-complex-routing-example-1
```
- [Corridor planning](topological-routing.md#corridor-planning-and-realization)
- [Figure generator](../scripts/render_complex_routing_example.py)