inire/examples/03_locked_paths.py

45 lines
1.5 KiB
Python
Raw Normal View History

2026-03-30 23:40:29 -07:00
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
2026-03-08 14:40:36 -07:00
from inire.utils.visualization import plot_routing_results
def main() -> None:
2026-03-30 21:22:20 -07:00
print("Running Example 03: Locked Paths...")
2026-03-08 14:40:36 -07:00
bounds = (0, -50, 100, 50)
2026-03-11 09:37:54 -07:00
print("Routing initial net...")
2026-03-30 23:40:29 -07:00
stack = build_routing_stack(
problem=RoutingProblem(
2026-03-30 15:32:29 -07:00
bounds=bounds,
nets=(NetSpec("netA", Port(10, 0, 0), Port(90, 0, 0), width=2.0),),
),
2026-03-30 23:40:29 -07:00
options=RoutingOptions(search=SearchOptions(bend_radii=(10.0,))),
)
engine = stack.world
evaluator = stack.evaluator
results_a = stack.finder.route_all()
2026-03-08 14:40:36 -07:00
2026-03-11 09:37:54 -07:00
print("Routing detour net around locked path...")
2026-03-30 23:40:29 -07:00
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,))),
2026-03-30 15:32:29 -07:00
),
2026-03-30 23:40:29 -07:00
).route_all()
2026-03-08 14:40:36 -07:00
results = {**results_a, **results_b}
fig, ax = plot_routing_results(results, [], bounds)
2026-03-08 23:34:18 -07:00
fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png")
2026-03-08 14:40:36 -07:00
if __name__ == "__main__":
main()