Illustrate the intermediate stages of complex-routing example 1
This commit is contained in:
parent
365c14c59a
commit
c3e420eadb
1 changed files with 402 additions and 86 deletions
|
|
@ -1,51 +1,6 @@
|
|||
"""Automatically route Terminal-Bench PR 345 and export waypoints."""
|
||||
"""Compatibility entry point for the nine-net waypoint exporter."""
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from dataclasses import replace
|
||||
from json import dumps
|
||||
from pathlib import Path
|
||||
from time import perf_counter
|
||||
|
||||
from shapely.geometry import box
|
||||
|
||||
from inire import TopologyOptions, route
|
||||
from inire.router._waypoints import export_waypoints
|
||||
from inire.router.cost import weighted_path_length
|
||||
from inire.tests.terminal_bench_scenario import LENGTH_COST, terminal_bench_options, terminal_bench_problem
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--output", type=Path, help="Write the verified waypoint plan to this JSON file.")
|
||||
parser.add_argument("--reference-lane-plan", action="store_true", help="Replay the manually supplied reference for comparison.")
|
||||
parser.add_argument("--single-bottom-track", action="store_true", help="Replay the manual reference with one bottom track.")
|
||||
args = parser.parse_args()
|
||||
|
||||
options = terminal_bench_options(max_iterations=1)
|
||||
options = replace(options, refinement=replace(options.refinement, enabled=False))
|
||||
started = perf_counter()
|
||||
if args.reference_lane_plan or args.single_bottom_track:
|
||||
from inire.tests.terminal_bench_lane_plan import terminal_bench_lane_problem # noqa: PLC0415
|
||||
|
||||
problem = terminal_bench_lane_problem(share_bottom_passage=not args.single_bottom_track)
|
||||
else:
|
||||
problem = terminal_bench_problem()
|
||||
options = replace(options, topology=TopologyOptions(mode="bundle", infer_terminal_headings=True))
|
||||
run = route(problem, options=options)
|
||||
elapsed = perf_counter() - started
|
||||
board = box(*problem.bounds)
|
||||
if run.results_by_net.keys() != {net.net_id for net in problem.nets}:
|
||||
parser.exit(1, "The route results do not cover the full waypoint plan\n")
|
||||
for net_id, result in run.results_by_net.items():
|
||||
if not result.is_valid or any(not board.covers(shape) for shape in result.locked_geometry):
|
||||
parser.exit(1, f"Lane plan failed inire verification for {net_id}\n")
|
||||
|
||||
cost = weighted_path_length((component for result in run.results_by_net.values() for component in result.path), LENGTH_COST)
|
||||
total = len(problem.nets)
|
||||
print(f"{total}/{total} verified, benchmark-weighted length {cost:.2f}, {run.metrics.nodes_expanded} A* expansions, {elapsed:.3f} s")
|
||||
if args.output is not None:
|
||||
waypoints = {net_id: export_waypoints(result.path) for net_id, result in run.results_by_net.items()}
|
||||
args.output.write_text(dumps({"nets": {net_id: {"waypoints": path} for net_id, path in waypoints.items()}}, indent=2) + "\n")
|
||||
from scripts.route_complex_routing_example import main
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue