inire/examples/09_unroutable_best_effort.py

46 lines
1.7 KiB
Python
Raw Normal View History

2026-03-10 21:55:54 -07:00
from shapely.geometry import box
2026-03-30 15:32:29 -07:00
from inire import CongestionOptions, NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.utils.visualization import plot_routing_results
2026-03-10 21:55:54 -07:00
def main() -> None:
2026-03-29 01:26:22 -07:00
print("Running Example 09: Best-Effort Under Tight Search Budget...")
2026-03-10 21:55:54 -07:00
bounds = (0, 0, 100, 100)
2026-03-29 01:26:22 -07:00
obstacles = [
box(35, 35, 45, 65),
box(55, 35, 65, 65),
2026-03-11 09:37:54 -07:00
]
2026-03-30 15:32:29 -07:00
problem = RoutingProblem(
bounds=bounds,
nets=(NetSpec("budget_limited_net", Port(10, 50, 0), Port(85, 60, 180), width=2.0),),
static_obstacles=tuple(obstacles),
)
options = RoutingOptions(
search=SearchOptions(
node_limit=3,
bend_radii=(10.0,),
),
objective=ObjectiveWeights(
bend_penalty=50.0,
sbend_penalty=150.0,
),
2026-03-30 19:51:37 -07:00
congestion=CongestionOptions(warm_start_enabled=False),
2026-03-30 15:32:29 -07:00
)
2026-03-10 21:55:54 -07:00
2026-03-29 01:26:22 -07:00
print("Routing with a deliberately tiny node budget (should return a partial path)...")
2026-03-30 15:32:29 -07:00
run = route(problem, options=options)
result = run.results_by_net["budget_limited_net"]
if not result.reached_target:
print(f"Target not reached as expected. Partial path length: {len(result.path)} segments.")
2026-03-11 09:37:54 -07:00
else:
2026-03-29 01:26:22 -07:00
print("The route unexpectedly reached the target. Increase difficulty or reduce the node budget further.")
2026-03-11 09:37:54 -07:00
2026-03-30 15:32:29 -07:00
fig, _ax = plot_routing_results(run.results_by_net, list(obstacles), bounds, netlist={"budget_limited_net": (Port(10, 50, 0), Port(85, 60, 180))})
2026-03-10 21:55:54 -07:00
fig.savefig("examples/09_unroutable_best_effort.png")
print("Saved plot to examples/09_unroutable_best_effort.png")
2026-03-30 15:32:29 -07:00
2026-03-10 21:55:54 -07:00
if __name__ == "__main__":
main()