rework structure of everything
This commit is contained in:
parent
dcc4d6436c
commit
941d3e01df
64 changed files with 3819 additions and 3559 deletions
|
|
@ -1,58 +1,46 @@
|
|||
from inire.geometry.collision import CollisionEngine
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router.astar import AStarContext, AStarMetrics
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.router.pathfinder import PathFinder
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
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...")
|
||||
|
||||
# 1. Setup Environment
|
||||
bounds = (0, 0, 100, 100)
|
||||
engine = CollisionEngine(clearance=2.0)
|
||||
|
||||
# A small obstacle cluster keeps the partial route visually interesting.
|
||||
obstacles = [
|
||||
box(35, 35, 45, 65),
|
||||
box(55, 35, 65, 65),
|
||||
]
|
||||
for obs in obstacles:
|
||||
engine.add_static_obstacle(obs)
|
||||
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),
|
||||
)
|
||||
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute(obstacles)
|
||||
|
||||
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
|
||||
# Keep the search budget intentionally tiny so the router returns a partial path.
|
||||
context = AStarContext(evaluator, node_limit=3, bend_radii=[10.0])
|
||||
metrics = AStarMetrics()
|
||||
|
||||
pf = PathFinder(context, metrics, warm_start=None)
|
||||
|
||||
# 2. Define Netlist: reaching the target requires additional turns the search budget cannot afford.
|
||||
netlist = {
|
||||
"budget_limited_net": (Port(10, 50, 0), Port(85, 60, 180)),
|
||||
}
|
||||
net_widths = {"budget_limited_net": 2.0}
|
||||
|
||||
# 3. Route
|
||||
print("Routing with a deliberately tiny node budget (should return a partial path)...")
|
||||
results = pf.route_all(netlist, net_widths)
|
||||
|
||||
# 4. Check Results
|
||||
res = results["budget_limited_net"]
|
||||
if not res.reached_target:
|
||||
print(f"Target not reached as expected. Partial path length: {len(res.path)} segments.")
|
||||
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.")
|
||||
|
||||
# 5. Visualize
|
||||
fig, ax = plot_routing_results(results, obstacles, bounds, netlist=netlist)
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue