5.4 KiB
Architecture Overview
inire is a single-package Python router with a small stable API at the package root and a larger semi-private implementation under inire.geometry and inire.router.
Stable Surface
- The supported entrypoint is
route(problem, options=...). - Stable public types live at the package root and include
RoutingProblem,RoutingOptions,NetSpec,Port,RoutingResult, andRoutingRunResult. - Deep imports such as
inire.router._router.PathFinderandinire.geometry.collision.RoutingWorldare intentionally accessible for advanced workflows, but they are unstable.
Current Module Layout
inire/model.py: Immutable request and option dataclasses.inire/results.py: Immutable routing results plus the per-runRouteMetricssnapshot.inire/seeds.py: Serializable path-seed primitives.inire/geometry/primitives.py: Integer Manhattan ports and small transform helpers.inire/geometry/components.py:Straight,Bend90, andSBendgeometry generation.inire/geometry/collision.py: Routing-world collision, congestion, ray-cast, and path-verification logic.inire/geometry/static_obstacle_index.pyandinire/geometry/dynamic_path_index.py: Spatial-index management for static obstacles and routed paths, including dynamic per-object indices, per-net grid occupancy, congestion grid membership, and per-net dynamic envelopes.inire/router/_search.py,_astar_moves.py,_astar_admission.py,_astar_types.py: The state-lattice A* search loop and move admission pipeline.inire/router/_router.py: The negotiated-congestion driver and refinement orchestration.inire/router/_automatic.pyselects and verifies planner candidates for the default public routing mode. It retries at the configured lattice search ceiling when the first pass falls short of the routing bound.inire/router/_topology.pybuilds alternative corridors through triangulated free space and ranks portal lanes using capacity, route overlap, and estimated turn clearance.inire/router/_bundle.pyconstructs ordered routes from rectangular barriers and terminal order for the opt-in bundle mode._waypoints.pycompiles its turns and S-bends into physical path seeds.inire/router/refiner.py: Post-route path simplification for completed paths.inire/router/cost.pyandinire/router/danger_map.py: Search scoring and obstacle-proximity biasing.inire/utils/visualization.py: Plotting and diagnostics helpers.
Routing Stack
The public route() function dispatches automatic planner selection and explicit modes. Both use route_once() in inire/router/_stack.py to run a single mode and collect its diagnostics. Each attempt builds a routing stack composed of:
RoutingWorldfor collision state.DangerMapfor static-obstacle proximity costs.CostEvaluatorfor move scoring and heuristic support.AStarContextfor caches and search configuration.PathFinderfor negotiated congestion, rip-up/reroute, and refinement.
The search state is a snapped Manhattan (x, y, r) port. From each state the router expands straight segments, 90-degree bends, and compact S-bends, then validates candidates against static geometry, dynamic congestion, and optional self-collision checks.
When enabled, topological planning runs before the first iteration. The lattice uses its waypoint suggestions during search. Seed mode additionally realizes and verifies paths inside candidate corridors before handing them off for negotiated routing and refinement.
Notes On Current Behavior
- Static obstacles and routed paths are treated as single-layer geometry; automatic crossings are not supported.
- The danger-map implementation uses sampled obstacle-boundary points and a KD-tree, not a dense distance-transform grid.
- The visibility subsystem keeps a lazy static corner index for default
tangent_cornerguidance and only builds the exact corner-to-corner graph on demand forexact_cornerqueries. use_tiered_strategycan swap in a cheaper bend proxy on the first congestion iteration.- Negotiated congestion now re-verifies every reached-target path at the end of each iteration against the final installed dynamic geometry, and it stops early if the conflict graph stalls for consecutive iterations.
- In the late all-reached low-edge regime, negotiated congestion reroutes only the current conflict set instead of all nets. The heaviest remaining late reroutes can be capped and carried forward by restoring their incumbent reached-target paths when more search would just churn before pair-local repair.
- After best-snapshot restoration, the router runs a bounded pair-local scratch reroute on final two-net reached-target conflict pairs. That repair phase clones static obstacles from the live collision world, treats all outside-pair geometry as fixed blockers, tries both pair orders, and only keeps the result if whole-set reverify improves.
- Final
RoutingResultvalidity is determined by explicit post-route verification, not only by search-time pruning.
Performance Visibility
RoutingRunResult.metrics includes both A* counters and index/cache/verification counters. The committed example-corpus baseline for those counters is tracked in docs/performance.md and docs/performance_baseline.json.
The topological routing experiment compares soft corridor guidance and corridor-first seed generation with the state-lattice baseline.