inire/examples/03_locked_paths.py

41 lines
1.4 KiB
Python
Raw Normal View History

from inire import NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
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)
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"),
2026-03-30 23:40:29 -07:00
)
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
2026-03-08 14:40:36 -07:00
2026-03-11 09:37:54 -07:00
print("Routing detour net around locked path...")
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
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()