Demonstrate locked routes with two public routing calls

This commit is contained in:
Jan Petykiewicz 2026-11-27 00:38:00 -08:00
commit e9ed72d0dc

View file

@ -1,7 +1,4 @@
from inire import NetSpec, Port, RoutingOptions, RoutingProblem, SearchOptions from inire import NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
from inire.router._astar_types import AStarContext
from inire.router._router import PathFinder
from inire.router._stack import build_routing_stack
from inire.utils.visualization import plot_routing_results from inire.utils.visualization import plot_routing_results
@ -9,34 +6,33 @@ def main() -> None:
print("Running Example 03: Locked Paths...") print("Running Example 03: Locked Paths...")
bounds = (0, -50, 100, 50) bounds = (0, -50, 100, 50)
print("Routing initial net...") options = RoutingOptions(
stack = build_routing_stack( search=SearchOptions(bend_radii=(10.0,)),
problem=RoutingProblem( # Isolate the lattice detour and use the fixed net only for clearance checks.
bounds=bounds, objective=ObjectiveWeights(danger_weight=0.0),
nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0), width=2.0),), topology=TopologyOptions(mode="off"),
),
options=RoutingOptions(search=SearchOptions(bend_radii=(10.0,))),
) )
engine = stack.world
evaluator = stack.evaluator print("Routing initial net...")
results_a = stack.finder.route_all() 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...") print("Routing detour net around locked path...")
for polygon in results_a["netA"].locked_geometry: problem_b = RoutingProblem(
engine.add_static_obstacle(polygon) bounds=bounds,
results_b = PathFinder( nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90)),),
AStarContext( static_obstacles=fixed.locked_geometry,
evaluator, )
RoutingProblem( results_b = route(problem_b, options=options).results_by_net
bounds=bounds, assert results_b["netB"].is_valid
nets=(NetSpec("netB", Port(50, -20, 90), Port(50, 20, 90), width=2.0),),
),
RoutingOptions(search=SearchOptions(bend_radii=(10.0,))),
),
).route_all()
results = {**results_a, **results_b} 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") fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png") print("Saved plot to examples/03_locked_paths.png")