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

11 KiB

Complex-routing example 1

Follow the outer return, net_08, from the input ports through the bundle plan and its final eastbound turn. Run the fixed-heading example from the repository root to render the complete layout. Example gallery

python examples/advanced_layouts.py \
  --case complex-routing-example-1 \
  --output-dir /tmp/inire-complex-routing-example-1

Origin. The problem uses board 1 from Terminal-Bench pull request 345. Pinned layout specification

1. Load the board and set the routing target

build_problem() reads the example entry into a RoutingProblem and RoutingOptions. The board is 2,500 by 1,000 units with seven rectangular keepouts and nine nets. The guides are 2 units wide, the clearance is 6, and both kinds of bends use radius 50. The fixed-heading case starts with no seeds and requires each net to launch and arrive heading east. Example inputs · Problem builder

route() dispatches to automatic routing. The router checks whether any aligned terminal pairs are too close and whether a vertical cut has fewer tracks than nets that need to cross it. The board passes both checks, so automatic asks the constructive planners to verify all nine nets. Automatic entry point · Capacity checks

The nine input nets surround seven rectangular keepouts. A cut at x = 500 has openings at the bottom, center, and top of the board.

Open circles mark source ports and filled squares mark targets. The purple cut crosses the first pair of keepouts. The side panel shows the raw open intervals and the track centers that fit after allowing for guide width and clearance. This cut can carry 24 tracks for nine nets.

2. Assign lanes and compile path seeds

The bundle planner groups the obstacles into two barriers with openings and three obstacles between them. It sorts the launches by height and separates the short connection net_03, the lower and upper groups, and the outer return net_08. The planner budgets 7 units from a keepout edge to a guide centerline and uses a 9-unit pitch between neighboring lanes. It reserves the bottommost lane for the return and has room for one more lane beneath the tower. Layout recognition · Lane assignment

For net_08, the initial plan drops from (12, 450) to the bottom lane at y = 1, crosses east, climbs on the right, and heads west to (1112, 991). The planner compiles the waypoints into straight, 90-degree bend, and S-bend seeds as appropriate. A Manhattan corner becomes a quarter turn with room for its tangencies. A diagonal step in a bundle waypoint list represents an S-bend with an exact grid span. Bundle seed construction · Waypoint compiler

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.

The dots mark waypoints in the proposed seeds. The lower inset shows the two continuous lanes below the tower. The other lower routes rise above that obstacle.

3. Fit the required eastbound arrival

Automatic routing compares the bundle's inferred headings with the input. Only net_08 differs. Its initial bundle arrives from the east heading west. The turnaround planner adjusts the upper shelf route net_07 and brings net_08 back below it. Near the target, net_08 rises west of x = 1112 and takes a final right turn to arrive heading east. The planner recompiles the two changed seeds and submits the full set for verification. Constructive planner dispatch · Turnaround candidates

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.

The arrow above each red target square shows the arrival heading.

4. Verify the seeds and refine the layout

The first bundle-turnaround candidate verifies all nine nets. Automatic routing runs a worker in mode off for one verification pass with a zero-node search limit and refinement disabled. The worker materializes each seed into physical polygons, installs the paths, and rechecks the installed layout for port joins, board containment, and collisions. The full coverage lets automatic routing skip its search trials. Seeded worker setup · Seed installation · Physical verification

The upper panel shows the physical paths of the first four nets in installation order. The lower panel shows all nine paths after verification.

The upper panel reconstructs the first four installed paths from the worker's verified seeds. The lower panel shows the full set checked together.

Automatic then replays the verified seeds in a worker with refinement enabled. The refiner tries replacing sections with at least four 90-degree bends and verifies the resulting layout. In this run, refinement changes net_05 and net_07 and keeps all nine nets verified. The refined layout wins on the configured objective, which includes component penalties as well as length. Refinement handoff · Trial comparison

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.

5. Inspect the result

The example counts RoutingResult.is_valid and plots each path from its physical polygons. To see the router's decisions, run the same board with the benchmark CLI and inspect the selected stage and its zero A* node count. The JSON records both stages under runs[0].samples[0].stages. Plotting code

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

To see how heading inference changes the route, rerun the gallery command with --case complex-routing-example-1-point-terminals. Automatic accepts the westbound arrival for net_08, verifies the original bundle plan, and then refines it. Both stages again verify nine nets with zero A* expansions. Point-terminal figure · Waypoint export command

Compare all routing modes

These runs use the same nine-net board with a 100-node limit per search, one congestion iteration, warm start disabled, and refinement disabled. The table compares a run with triangulation available against a run with that capability disabled. Each mode keeps the input headings except bundle, which uses infer_terminal_headings=True so net_08 can arrive westbound. Explicit bundle with the original fixed eastbound headings raises a heading mismatch for that net.

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.

Triangulation support

Corridor planning uses Shapely's constrained Delaunay triangulation to keep triangle edges inside free space and respect keepout boundaries. It requires Shapely 2.1 or later and GEOS 3.10 or later. On supported platforms a Shapely wheel bundles GEOS. In a pip environment, use python -m pip install --upgrade "shapely>=2.1". A source build needs a compatible system GEOS. Shapely triangulation reference · Shapely installation guide

Check the versions in the environment that runs Inire.

python -c 'import shapely; print(shapely.__version__, shapely.geos_version_string)'

Inire supports Shapely 2.0.7 for lattice routing and constructive plans. With a compatible backend, automatic already uses triangulation whenever it needs corridor search. Here the ordered bundle and turnaround cover all nine nets, so automatic can move directly to verification. Explicit guide and seed also verify supplied paths without a mesh when node_limit=0.

The successful bundle run above reaches verification before the corridor search. To see that search's working model, the figure generator runs net_08 by itself in guide mode on the same board. The left panel shows the actual triangulation, corridor cells in green, and the guide through them as a dashed line. The right panel zooms in on the expanded positions and physical partial path returned when A* reaches its 12-node budget. Corridor planning

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.

Regenerate the stage figures from the planners, routing results, and expanded nodes. Figure source

python -m scripts.render_complex_routing_example --output-dir /tmp/inire-complex-routing-example-1