fix examples
This commit is contained in:
parent
bc218a416b
commit
e11132b51d
20 changed files with 406 additions and 101 deletions
|
|
@ -1,50 +1,65 @@
|
|||
from shapely.geometry import Polygon
|
||||
|
||||
from inire import CongestionOptions, NetSpec, ObjectiveWeights, RoutingOptions, RoutingProblem, RoutingResult, SearchOptions, route
|
||||
from inire import CongestionOptions, NetSpec, RoutingOptions, RoutingProblem, SearchOptions
|
||||
from inire.geometry.collision import RoutingWorld
|
||||
from inire.geometry.primitives import Port
|
||||
from inire.router._astar_types import AStarContext, AStarMetrics
|
||||
from inire.router._router import PathFinder
|
||||
from inire.router.cost import CostEvaluator
|
||||
from inire.router.danger_map import DangerMap
|
||||
from inire.utils.visualization import plot_routing_results
|
||||
|
||||
|
||||
def _run_request(
|
||||
bounds: tuple[float, float, float, float],
|
||||
bend_collision_type: object,
|
||||
net_id: str,
|
||||
start: Port,
|
||||
target: Port,
|
||||
) -> dict[str, RoutingResult]:
|
||||
problem = RoutingProblem(
|
||||
bounds=bounds,
|
||||
nets=(NetSpec(net_id, start, target, width=2.0),),
|
||||
)
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(
|
||||
bend_radii=(10.0,),
|
||||
bend_collision_type=bend_collision_type,
|
||||
sbend_radii=(),
|
||||
),
|
||||
objective=ObjectiveWeights(
|
||||
bend_penalty=50.0,
|
||||
sbend_penalty=150.0,
|
||||
),
|
||||
congestion=CongestionOptions(use_tiered_strategy=False),
|
||||
)
|
||||
return route(problem, options=options).results_by_net
|
||||
|
||||
|
||||
def main() -> None:
|
||||
print("Running Example 08: Custom Bend Geometry...")
|
||||
|
||||
bounds = (0, 0, 150, 150)
|
||||
engine = RoutingWorld(clearance=2.0)
|
||||
danger_map = DangerMap(bounds=bounds)
|
||||
danger_map.precompute([])
|
||||
evaluator = CostEvaluator(engine, danger_map, bend_penalty=50.0, sbend_penalty=150.0)
|
||||
metrics = AStarMetrics()
|
||||
start = Port(20, 20, 0)
|
||||
target = Port(100, 100, 90)
|
||||
|
||||
print("Routing with standard arc...")
|
||||
results_std = _run_request(bounds, "arc", "custom_bend", start, target)
|
||||
results_std = PathFinder(
|
||||
AStarContext(
|
||||
evaluator,
|
||||
RoutingProblem(
|
||||
bounds=bounds,
|
||||
nets=(NetSpec("custom_bend", start, target, width=2.0),),
|
||||
),
|
||||
RoutingOptions(
|
||||
search=SearchOptions(bend_radii=(10.0,), sbend_radii=()),
|
||||
congestion=CongestionOptions(max_iterations=1),
|
||||
),
|
||||
),
|
||||
metrics=metrics,
|
||||
).route_all()
|
||||
|
||||
custom_poly = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
||||
custom_poly = Polygon([(-10, -10), (10, -10), (10, 10), (-10, 10)])
|
||||
|
||||
print("Routing with custom bend geometry...")
|
||||
results_custom = _run_request(bounds, custom_poly, "custom_model", start, target)
|
||||
print("Routing with custom collision model...")
|
||||
results_custom = PathFinder(
|
||||
AStarContext(
|
||||
evaluator,
|
||||
RoutingProblem(
|
||||
bounds=bounds,
|
||||
nets=(NetSpec("custom_model", start, target, width=2.0),),
|
||||
),
|
||||
RoutingOptions(
|
||||
search=SearchOptions(
|
||||
bend_radii=(10.0,),
|
||||
bend_collision_type=custom_poly,
|
||||
sbend_radii=(),
|
||||
),
|
||||
congestion=CongestionOptions(max_iterations=1, use_tiered_strategy=False),
|
||||
),
|
||||
),
|
||||
metrics=AStarMetrics(),
|
||||
use_tiered_strategy=False,
|
||||
).route_all()
|
||||
|
||||
all_results = {**results_std, **results_custom}
|
||||
fig, _ax = plot_routing_results(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue