Demonstrate locked routes with two public routing calls
This commit is contained in:
parent
0c059cc7d6
commit
e9ed72d0dc
1 changed files with 22 additions and 26 deletions
|
|
@ -1,7 +1,4 @@
|
|||
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 import NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions, route
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
|
||||
|
||||
|
|
@ -9,34 +6,33 @@ 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,))),
|
||||
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"),
|
||||
)
|
||||
engine = stack.world
|
||||
evaluator = stack.evaluator
|
||||
results_a = stack.finder.route_all()
|
||||
|
||||
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
|
||||
|
||||
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()
|
||||
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
|
||||
|
||||
results = {**results_a, **results_b}
|
||||
fig, ax = plot_routing_results(results, [], bounds)
|
||||
fig, _ax = plot_routing_results(results, [], bounds)
|
||||
fig.savefig("examples/03_locked_paths.png")
|
||||
print("Saved plot to examples/03_locked_paths.png")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue