inire/inire/tests/terminal_bench_scenario.py

66 lines
2.4 KiB
Python

from __future__ import annotations
from math import pi
from shapely.geometry import box
from inire import CongestionOptions, NetSpec, ObjectiveWeights, Port, RoutingOptions, RoutingProblem, SearchOptions, TopologyOptions
# Board 1 from the layout_spec.json in Terminal-Bench PR 345, head 249d125b.
# https://github.com/harbor-framework/terminal-bench/pull/345
BOARD = (0, 0, 2500, 1000)
OBSTACLES = (
(450, 80, 550, 480),
(450, 520, 550, 920),
(1910, 130, 2010, 491.5),
(1910, 510, 2010, 851.5),
(940, 680, 1040, 983),
(980, 50, 1080, 475),
(1350, 18, 1537, 620),
)
ENDPOINTS = (
((12, 460), (2412, 150)),
((12, 470), (2412, 250)),
((12, 480), (2412, 350)),
((12, 490), (902, 900)),
((12, 500), (2412, 500)),
((12, 510), (2412, 650)),
((12, 520), (2412, 750)),
((12, 530), (2412, 850)),
((12, 450), (1112, 991)),
)
NET_WIDTH = 2.0
CLEARANCE = 6.0
MIN_SEPARATION = 8.0
BEND_RADIUS = 50.0
LENGTH_COST = {"straight": 1.0, "bend90": 4.0, "sbend": 13.0}
def terminal_bench_problem() -> RoutingProblem:
# The input specifies points. The inire comparison fixes both headings east.
# Keep source units in this corpus case to match inire's integer search lattice.
return RoutingProblem(
bounds=BOARD,
nets=tuple(
NetSpec(f"net_{index:02d}", Port(*start, 0), Port(*target, 0), width=NET_WIDTH) for index, (start, target) in enumerate(ENDPOINTS)
),
static_obstacles=tuple(box(*bounds) for bounds in OBSTACLES),
clearance=CLEARANCE,
)
def terminal_bench_options(*, node_limit: int = 500, max_iterations: int = 2) -> RoutingOptions:
# At one bend radius the arc surcharge maps to inire's radius-scaled penalty.
# S-bend cost is offset-dependent upstream. Use a fixed search penalty and
# measure the weighted component lengths directly when reporting results.
return RoutingOptions(
search=SearchOptions(node_limit=node_limit, bend_radii=(BEND_RADIUS,), sbend_radii=(BEND_RADIUS,)),
objective=ObjectiveWeights(
bend_penalty=(LENGTH_COST["bend90"] - 1) * (pi * BEND_RADIUS / 2) * (BEND_RADIUS / 10) ** 0.5,
sbend_penalty=500.0,
danger_weight=0.0,
),
congestion=CongestionOptions(max_iterations=max_iterations, base_penalty=1000.0, use_tiered_strategy=False),
topology=TopologyOptions(mode="off"),
)