From e9ed72d0dcfa0776192d85da1873eb1c862c7659 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Fri, 27 Nov 2026 00:38:00 -0800 Subject: [PATCH] Demonstrate locked routes with two public routing calls --- examples/03_locked_paths.py | 50 +++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/examples/03_locked_paths.py b/examples/03_locked_paths.py index b00741f..987ba73 100644 --- a/examples/03_locked_paths.py +++ b/examples/03_locked_paths.py @@ -1,7 +1,4 @@ -from inire import NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions -from inire.router._astar_types import AStarContext -from inire.router._router import PathFinder -from inire.router._stack import build_routing_stack +from inire import NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route from inire.utils.visualization import plot_routing_results @@ -9,34 +6,33 @@ def main() -> None: print("Running Example 03: Locked Paths...") bounds = (0, -50, 100, 50) - print("Routing initial net...") - stack = build_routing_stack( - problem=RoutingProblem( - bounds=bounds, - nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0), width=2.0),), - ), - options=RoutingOptions(search=SearchOptions(bend_radii=(10.0,))), + options = RoutingOptions( + search=SearchOptions(bend_radii=(10.0,)), + # Isolate the lattice detour and use the fixed net only for clearance checks. + objective=ObjectiveWeights(danger_weight=0.0), + topology=TopologyOptions(mode="off"), ) - engine = stack.world - evaluator = stack.evaluator - results_a = stack.finder.route_all() + + print("Routing initial net...") + problem_a = RoutingProblem( + bounds=bounds, + nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0)),), + ) + results_a = route(problem_a, options=options).results_by_net + fixed = results_a["netA"] + assert fixed.is_valid print("Routing detour net around locked path...") - for polygon in results_a["netA"].locked_geometry: - engine.add_static_obstacle(polygon) - results_b = PathFinder( - AStarContext( - evaluator, - RoutingProblem( - bounds=bounds, - nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90), width=2.0),), - ), - RoutingOptions(search=SearchOptions(bend_radii=(10.0,))), - ), - ).route_all() + problem_b = RoutingProblem( + bounds=bounds, + nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90)),), + static_obstacles=fixed.locked_geometry, + ) + results_b = route(problem_b, options=options).results_by_net + assert results_b["netB"].is_valid results = {**results_a, **results_b} - fig, ax = plot_routing_results(results, [], bounds) + fig, _ax = plot_routing_results(results, [], bounds) fig.savefig("examples/03_locked_paths.png") print("Saved plot to examples/03_locked_paths.png")