inire/examples/09_unroutable_best_effort.py

46 lines
1.6 KiB
Python

from shapely.geometry import box
from inire import CongestionOptions, NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, route
from inire.utils.visualization import plot_routing_results
def main() -> None:
print("Running Example 09: Best-Effort Under Tight Search Budget...")
bounds = (0, 0, 100, 100)
obstacles = [
box(35, 35, 45, 65),
box(55, 35, 65, 65),
]
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,
),
congestion=CongestionOptions(warm_start=None),
)
print("Routing with a deliberately tiny node budget (should return a partial path)...")
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.")
else:
print("The route unexpectedly reached the target. Increase difficulty or reduce the node budget further.")
fig, _ax = plot_routing_results(run.results_by_net, list(obstacles), bounds, netlist={"budget_limited_net": (Port(10, 50, 0), Port(85, 60, 180))})
fig.savefig("examples/09_unroutable_best_effort.png")
print("Saved plot to examples/09_unroutable_best_effort.png")
if __name__ == "__main__":
main()