Preserve route identity through reservation and export

This commit is contained in:
Jan Petykiewicz 2026-11-29 00:12:59 -08:00
commit 286caa273b
2 changed files with 226 additions and 99 deletions

View file

@ -30,6 +30,7 @@ The fields below appear in constructor order. Use one layout unit for coordinate
| `clearance` | `2.0` | Finite, nonnegative spacing required between distinct nets and between a net and a keepout. At zero clearance, distinct nets must still be disjoint, including at vertices. Boundary contact with a keepout is allowed. |
| `safety_zone_radius` | `0.0021` | Tolerance for small obstacle intersections at a move's endpoints during search. |
| `self_clearance` | `0.0` | Optional spacing within one net. Applies between components when the intervening centerline is at least this long. Adjacent joins and components immediately on either side of one bend are exempt. Unintended contact is always checked. |
| `fixed_routes` | `()` | Completed or imported net geometry supplied as `FixedRoute(net_id, polygons)`. IDs must be unique across fixed and active nets. |
## Path seeds
@ -41,6 +42,7 @@ The fields below appear in constructor order. Use one layout unit for coordinate
| --- | --- |
| `RoutingRunResult.results_by_net` | A mapping from net ID to `RoutingResult`. |
| `RoutingResult.is_valid` and `outcome` | `is_valid` is true when the outcome is `completed`. Read `outcome` to distinguish success, a failed geometry check (`colliding`), a path that stopped short (`partial`), or an empty path (`unroutable`). |
| `RoutingResult.requested_net` and `effective_net` | The net as supplied and the net used by the worker, including resolved headings. |
| `RoutingResult.path` | Ordered path components from the source to the last reached state. An unroutable result has an empty path. |
| `RoutingResult.reached_target` | Whether the path reached the target position and heading. With heading inference, the check uses the chosen heading. Read `is_valid` for the result of geometry verification. |
| `RoutingResult.report` | `total_length` in layout units plus static, dynamic, and self-collision counts. `out_of_bounds` flags geometry outside the board. `discontinuous` flags missing or point-only joins, including at terminal faces. `invalid_geometry` flags invalid or empty physical polygons. `seed_error` identifies a supplied bend that cannot carry the net's width. `terminal_error` identifies an inaccessible start or target face. |

View file

@ -90,7 +90,7 @@ For a multi-net layout, apply the validity check to every net you intend to expo
## Reuse an existing route
- **Give the router a route it can move.** Put `result.as_seed()` in `initial_paths` under the net's ID. A seed uses the current start port, width, and geometry settings. Search can follow a partial seed from the first iteration and can leave it to find another approach. To build a hint from turns and straights, see the [path seed reference](api-reference.md#path-seeds).
- **Hold a route fixed.** Check `result.is_valid`, then replay its seed in the first group of `route_profiles` with search and refinement disabled. Later groups respect it as a distinct net, including at zero clearance. Verify the groups together before [exporting the layer](fabrication.md#check-the-export-grid).
- **Hold a route fixed.** Check `result.is_valid`, then use `FixedRoute.from_result(result)` and pass it in `fixed_routes` alongside the remaining nets. The next run respects it as a distinct net, including at zero clearance. Verify the groups together before [exporting the layer](fabrication.md#check-the-export-grid).
When terminal headings are inferred, store the two selected ports alongside the seed, width, and geometry options. Use those exact ports to replay the route and export the same polygons.
@ -128,8 +128,8 @@ Route a straight net, then reserve it while routing another net on the same laye
```python
from dataclasses import replace
from inire import NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.layout import route_profiles, verify_export_grid
from inire import FixedRoute, NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.layout import verify_export_grid
bounds = (0, -50, 100, 50)
options = RoutingOptions(search=SearchOptions(bend_radii=(10,)))
@ -137,16 +137,14 @@ fixed_net = NetSpec("fixed", Port(10, 0, 0), Port(90, 0, 0))
detour_net = NetSpec("detour", Port(50, -20, 90), Port(50, 20, 90))
problem = RoutingProblem(bounds=bounds, nets=(fixed_net, detour_net), clearance=0)
fixed = route(replace(problem, nets=(fixed_net,)), options=options).results_by_net["fixed"]
assert fixed.is_valid
replay_options = replace(
options, search=replace(options.search, node_limit=0), refinement=RefinementOptions(enabled=False),
)
problem = replace(problem, initial_paths={"fixed": fixed.as_seed()})
results = route_profiles(problem, [(("fixed",), replay_options), (("detour",), options)])
export = verify_export_grid(problem, results, grid=1.0)
remaining = replace(problem, nets=(detour_net,), fixed_routes=(FixedRoute.from_result(fixed),))
run = route(remaining, options=options)
export = verify_export_grid(remaining, run.results_by_net, grid=1.0)
if not export.is_valid:
raise ValueError(export.reports_by_net)
```
For imported metal or waveguide polygons, use `FixedRoute("existing_net", imported_polygons)`. Supply fixed polygons in their final layer coordinates. Export checks new routes against them and returns the new polygons.
To compare the two paths on a plot, see the [fixed-route example](../../examples/README.md#route-around-fixed-geometry).