inire/examples/03_locked_paths.py

45 lines
1.5 KiB
Python

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.utils.visualization import plot_routing_results
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,))),
)
engine = stack.world
evaluator = stack.evaluator
results_a = stack.finder.route_all()
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()
results = {**results_a, **results_b}
fig, ax = plot_routing_results(results, [], bounds)
fig.savefig("examples/03_locked_paths.png")
print("Saved plot to examples/03_locked_paths.png")
if __name__ == "__main__":
main()