356 lines
15 KiB
Python
356 lines
15 KiB
Python
"""Core, Terminal-Bench, and fallback routing fixtures."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import replace
|
|
|
|
from shapely.geometry import Polygon, box
|
|
|
|
from inire import Bend90Seed, NetSpec, PathSeed, Port, RoutingProblem, SBendSeed, StraightSeed
|
|
from inire.tests.routing_benchmark_case import BenchmarkCase, benchmark_options
|
|
from inire.tests.routing_crossing_benchmarks import CROSSING_BENCHMARK_CASES as CROSSING_BENCHMARK_CASES
|
|
from inire.tests.routing_external_benchmarks import EXTERNAL_BENCHMARK_CASES as EXTERNAL_BENCHMARK_CASES
|
|
from inire.tests.routing_gate_benchmarks import (
|
|
GATE_BENCHMARK_CASES,
|
|
VALIDATION_BENCHMARK_CASES as VALIDATION_BENCHMARK_CASES,
|
|
_band,
|
|
_Gate,
|
|
_gate_benchmark,
|
|
)
|
|
from inire.tests.terminal_bench_scenario import OBSTACLES, terminal_bench_options, terminal_bench_problem
|
|
|
|
|
|
def _open_or_shared_gate(
|
|
name: str,
|
|
description: str,
|
|
heights: tuple[int, ...],
|
|
*,
|
|
wall: bool = False,
|
|
expected_routed: int | None = None,
|
|
) -> BenchmarkCase:
|
|
# A 34-unit aperture with 2-unit guides and 6-unit clearance leaves 20 units
|
|
# for centerlines. At 8-unit pitch this admits at most three routes.
|
|
obstacles = (box(200, 0, 250, 132), box(200, 166, 250, 300)) if wall else ()
|
|
nets = tuple(NetSpec(f"track_{y}", Port(25, y, 0), Port(425, y, 0)) for y in heights)
|
|
reference = tuple((net.net_id, PathSeed((StraightSeed(400),))) for net in nets if not wall or 139 <= net.start.y <= 159)
|
|
problem = RoutingProblem((0, 0, 450, 300), nets, obstacles, clearance=6)
|
|
return BenchmarkCase(name, description, problem, benchmark_options(25), reference, expected_routed)
|
|
|
|
|
|
def _competing_detours() -> BenchmarkCase:
|
|
nets = tuple(NetSpec(net_id, Port(60, y, 0), Port(740, y, 0)) for net_id, y in (("lower", 270), ("upper", 300)))
|
|
problem = RoutingProblem((0, 0, 800, 600), nets, (box(300, 170, 480, 460),), clearance=6)
|
|
reference = []
|
|
for net_id, first_turn, second_turn, vertical in (("lower", "CW", "CCW", 75), ("upper", "CCW", "CW", 130)):
|
|
reference.append(
|
|
(
|
|
net_id,
|
|
PathSeed(
|
|
(
|
|
StraightSeed(100),
|
|
Bend90Seed(25, first_turn),
|
|
StraightSeed(vertical),
|
|
Bend90Seed(25, second_turn),
|
|
StraightSeed(350),
|
|
Bend90Seed(25, second_turn),
|
|
StraightSeed(vertical),
|
|
Bend90Seed(25, first_turn),
|
|
StraightSeed(130),
|
|
)
|
|
),
|
|
)
|
|
)
|
|
return BenchmarkCase(
|
|
"competing-detours", "Two nets compete for a short detour around the same obstacle", problem, benchmark_options(25), tuple(reference)
|
|
)
|
|
|
|
|
|
def _offset_gates(mirrored: bool = False) -> BenchmarkCase:
|
|
# A 25-unit S-bend radius and 20-unit offset give an exact 40-unit forward span.
|
|
launch_y, arrival_y = (120, 100) if mirrored else (100, 120)
|
|
problem = RoutingProblem(
|
|
bounds=(0, 0, 600, 260),
|
|
nets=(NetSpec("offset", Port(30, launch_y, 0), Port(570, arrival_y, 0)),),
|
|
static_obstacles=(
|
|
box(200, 0, 240, launch_y - 10),
|
|
box(200, launch_y + 10, 240, 260),
|
|
box(400, 0, 440, arrival_y - 10),
|
|
box(400, arrival_y + 10, 440, 260),
|
|
),
|
|
clearance=6,
|
|
)
|
|
seed = PathSeed((StraightSeed(220), SBendSeed(arrival_y - launch_y, 25), StraightSeed(280)))
|
|
name = "offset-gates-mirrored" if mirrored else "offset-gates"
|
|
return BenchmarkCase(name, "A lateral shift between two narrow apertures", problem, benchmark_options(30, 25), (("offset", seed),))
|
|
|
|
|
|
def _reversed_heading() -> BenchmarkCase:
|
|
problem = RoutingProblem(
|
|
bounds=(0, 0, 700, 320),
|
|
nets=(NetSpec("return", Port(520, 150, 0), Port(200, 70, 0)),),
|
|
static_obstacles=(box(280, 90, 430, 215),),
|
|
clearance=6,
|
|
)
|
|
bend = Bend90Seed(30, "CCW")
|
|
seed = PathSeed((StraightSeed(60), bend, StraightSeed(40), bend, StraightSeed(440), bend, StraightSeed(120), bend, StraightSeed(60)))
|
|
return BenchmarkCase(
|
|
"reversed-heading", "East-facing ports require westward travel past an obstacle", problem, benchmark_options(30), (("return", seed),)
|
|
)
|
|
|
|
|
|
def _mixed_width_gates() -> BenchmarkCase:
|
|
nets = (
|
|
NetSpec("narrow", Port(25, 100, 0), Port(425, 100, 0), width=2),
|
|
NetSpec("wide", Port(25, 200, 0), Port(425, 200, 0), width=8),
|
|
)
|
|
obstacles = (box(200, 0, 250, 92), box(200, 108, 250, 181), box(200, 219, 250, 300))
|
|
problem = RoutingProblem((0, 0, 450, 300), nets, obstacles, clearance=6)
|
|
reference = tuple((net.net_id, PathSeed((StraightSeed(400),))) for net in nets)
|
|
return BenchmarkCase(
|
|
"mixed-width-gates",
|
|
"A narrow aperture fits only the narrow net",
|
|
problem,
|
|
benchmark_options(25),
|
|
reference,
|
|
)
|
|
|
|
|
|
def _blocking_straight(*, turn_limited: bool = False) -> BenchmarkCase:
|
|
inset = 14 if turn_limited else 2
|
|
vertical_start, vertical_target = (130, 170) if turn_limited else (30, 270)
|
|
problem = RoutingProblem(
|
|
bounds=(0, 0, 400, 300),
|
|
nets=(
|
|
NetSpec("horizontal", Port(inset, 150, 0), Port(400 - inset, 150, 0)),
|
|
NetSpec("vertical", Port(200, vertical_start, 90), Port(200, vertical_target, 90)),
|
|
),
|
|
clearance=6,
|
|
)
|
|
down, up = Bend90Seed(25, "CW"), Bend90Seed(25, "CCW")
|
|
detour = PathSeed(
|
|
(StraightSeed(42 - inset), down, StraightSeed(82), up, StraightSeed(215), up, StraightSeed(82), down, StraightSeed(43 - inset))
|
|
)
|
|
reference = (("horizontal", detour), ("vertical", PathSeed((StraightSeed(vertical_target - vertical_start),))))
|
|
if turn_limited:
|
|
return BenchmarkCase(
|
|
"blocking-turn-room",
|
|
"A straight leaves side passages but challenges the other net's launch turn",
|
|
problem,
|
|
benchmark_options(25),
|
|
reference,
|
|
)
|
|
return BenchmarkCase(
|
|
"blocking-straight", "A legal straight divides the board and traps a second net", problem, benchmark_options(25), reference
|
|
)
|
|
|
|
|
|
def _crossing_with_room() -> BenchmarkCase:
|
|
problem = RoutingProblem(
|
|
bounds=(0, 0, 400, 300),
|
|
nets=(
|
|
NetSpec("horizontal", Port(80, 150, 0), Port(320, 150, 0)),
|
|
NetSpec("vertical", Port(200, 30, 90), Port(200, 270, 90)),
|
|
),
|
|
clearance=6,
|
|
)
|
|
cw, ccw = Bend90Seed(25, "CW"), Bend90Seed(25, "CCW")
|
|
bypass = PathSeed((StraightSeed(10), cw, StraightSeed(85), ccw, StraightSeed(120), ccw, StraightSeed(85), cw, StraightSeed(10)))
|
|
reference = (("horizontal", PathSeed((StraightSeed(240),))), ("vertical", bypass))
|
|
return BenchmarkCase(
|
|
"crossing-with-room", "An unlocked junction with room to route around either straight", problem, benchmark_options(25), reference
|
|
)
|
|
|
|
|
|
def _detour() -> BenchmarkCase:
|
|
problem = RoutingProblem(
|
|
bounds=(0, 0, 800, 600),
|
|
clearance=6,
|
|
static_obstacles=(box(300, 170, 480, 430),),
|
|
nets=(NetSpec("detour", Port(60, 300, 0), Port(740, 300, 0)),),
|
|
)
|
|
down, up = Bend90Seed(50, "CW"), Bend90Seed(50, "CCW")
|
|
seed = PathSeed((StraightSeed(100), down, StraightSeed(50), up, StraightSeed(280), up, StraightSeed(50), down, StraightSeed(100)))
|
|
return BenchmarkCase("detour", "One net with a choice of two obstacle bypasses", problem, terminal_bench_options(), (("detour", seed),))
|
|
|
|
|
|
_TERMINAL_BENCH = terminal_bench_problem()
|
|
|
|
|
|
def _terminal_bench_point_cases() -> tuple[BenchmarkCase, ...]:
|
|
options = terminal_bench_options()
|
|
options = replace(
|
|
options,
|
|
topology=replace(options.topology, mode="bundle", infer_terminal_headings=True),
|
|
refinement=replace(options.refinement, enabled=False),
|
|
)
|
|
x0, _, x1, y1 = OBSTACLES[-1]
|
|
one_track = replace(_TERMINAL_BENCH, static_obstacles=(*_TERMINAL_BENCH.static_obstacles[:-1], box(x0, 16, x1, y1)))
|
|
return (
|
|
BenchmarkCase("terminal-bench-point-terminals", "PR 345 with freely oriented point terminals", _TERMINAL_BENCH, options),
|
|
BenchmarkCase(
|
|
"terminal-bench-clearance-5",
|
|
"Point terminals with the clearance reduced from 6 to 5",
|
|
replace(_TERMINAL_BENCH, clearance=5),
|
|
options,
|
|
),
|
|
BenchmarkCase(
|
|
"terminal-bench-narrow-bottom",
|
|
"Point terminals with a 16-unit opening below the tower",
|
|
one_track,
|
|
options,
|
|
),
|
|
)
|
|
|
|
|
|
_TERMINAL_BENCH_POINT_CASES = _terminal_bench_point_cases()
|
|
|
|
|
|
def _ordered_bundle_benchmarks() -> tuple[BenchmarkCase, ...]:
|
|
base = _TERMINAL_BENCH_POINT_CASES[0]
|
|
|
|
def obstacles(changes: dict[int, tuple[float, float, float, float]]) -> RoutingProblem:
|
|
return replace(base.problem, static_obstacles=tuple(box(*changes.get(i, bounds)) for i, bounds in enumerate(OBSTACLES)))
|
|
|
|
radius_40 = benchmark_options(40)
|
|
return (
|
|
replace(
|
|
base,
|
|
name="bundle-offset-barriers",
|
|
description="Move both paired barriers toward the launches, changing turning room before and after the barriers",
|
|
problem=obstacles({0: (410, 80, 510, 480), 1: (410, 520, 510, 920), 2: (1865, 130, 1970, 491.5), 3: (1865, 510, 1970, 851.5)}),
|
|
),
|
|
replace(
|
|
base,
|
|
name="bundle-three-bottom-tracks",
|
|
description="The taller lower opening admits the return and two through tracks below the tower",
|
|
problem=obstacles({6: (1350, 27, 1537, 620)}),
|
|
),
|
|
replace(
|
|
base,
|
|
name="bundle-tall-wide-tower",
|
|
description="A taller and wider tower constrains the middle crossover and the lower tracks' descent",
|
|
problem=obstacles({6: (1320, 18, 1610, 644)}),
|
|
),
|
|
replace(
|
|
base,
|
|
name="bundle-shifted-shelf",
|
|
description="Shift the north and south obstacles to the east and widen the south obstacle",
|
|
problem=obstacles({4: (962, 680, 1062, 983), 5: (994, 50, 1134, 475)}),
|
|
),
|
|
replace(
|
|
base,
|
|
name="bundle-radius-40",
|
|
description="Reduce the bend radius to 40 and narrow the tower's bottom opening to 16",
|
|
problem=obstacles({6: (1350, 16, 1537, 620)}),
|
|
options=replace(base.options, search=radius_40.search, objective=radius_40.objective),
|
|
),
|
|
)
|
|
|
|
|
|
COMPLEX_BENCHMARK_CASES = (*_ordered_bundle_benchmarks(), *GATE_BENCHMARK_CASES)
|
|
|
|
|
|
def _fallback_benchmarks() -> tuple[BenchmarkCase, ...]:
|
|
detours = _competing_detours()
|
|
detours = replace(detours, options=replace(detours.options, refinement=replace(detours.options.refinement, enabled=False)))
|
|
irregular = Polygon([(300, 190), (328, 170), (458, 182), (480, 225), (464, 415), (425, 440), (340, 460), (310, 381)])
|
|
channel = _gate_benchmark(
|
|
"fallback-beveled-gates",
|
|
"Nine nets through three staggered apertures with beveled obstacle faces",
|
|
_band(350),
|
|
_band(370),
|
|
(_Gate(470, 550, (_band(350),)), _Gate(1070, 1170, (_band(390),)), _Gate(1670, 1760, (_band(370),))),
|
|
)
|
|
beveled = tuple(
|
|
Polygon(
|
|
[
|
|
(left, low + 12),
|
|
(left + 12, low),
|
|
(right - 12, low),
|
|
(right, low + 12),
|
|
(right, high - 12),
|
|
(right - 12, high),
|
|
(left + 12, high),
|
|
(left, high - 12),
|
|
]
|
|
)
|
|
for left, low, right, high in (shape.bounds for shape in channel.problem.static_obstacles)
|
|
)
|
|
|
|
custom_nets = tuple(
|
|
NetSpec(f"turn_{i}", Port(20, y, 0), Port(x, y + 50, 90)) for i, (x, y) in enumerate(((240, 40), (200, 110), (160, 180)))
|
|
)
|
|
custom_routes = tuple(
|
|
(net.net_id, PathSeed((StraightSeed(net.target.x - net.start.x - 10), Bend90Seed(10, "CCW"), StraightSeed(40)))) for net in custom_nets
|
|
)
|
|
custom_problem = RoutingProblem((0, 0, 320, 300), custom_nets, (box(90, 65, 130, 90), box(110, 137, 160, 153)), clearance=4)
|
|
custom_options = benchmark_options(10)
|
|
custom_options = replace(custom_options, refinement=replace(custom_options.refinement, enabled=False))
|
|
custom_outline = Polygon([(0, -11), (11, -11), (11, 0), (9, 0), (9, -9), (0, -9)])
|
|
custom_proxy = box(0, -11, 11, 0)
|
|
proxy_options = replace(
|
|
custom_options,
|
|
search=replace(custom_options.search, bend_physical_geometry="arc", bend_proxy_geometry=custom_proxy, sbend_radii=()),
|
|
)
|
|
physical_options = replace(proxy_options, search=replace(proxy_options.search, bend_physical_geometry=custom_outline))
|
|
parallel = _open_or_shared_gate(
|
|
"fallback-partial-seed", "One complete and one partial caller seed alongside an unseeded net", (122, 142, 162)
|
|
)
|
|
complete_id, partial_id, _ = (net.net_id for net in parallel.problem.nets)
|
|
parallel_seeds = {complete_id: dict(parallel.reference_paths)[complete_id], partial_id: PathSeed((StraightSeed(45),))}
|
|
|
|
return (
|
|
replace(
|
|
detours,
|
|
name="fallback-irregular-island",
|
|
description="Two competing detours around an irregular polygon",
|
|
problem=replace(detours.problem, static_obstacles=(irregular,)),
|
|
),
|
|
replace(channel, problem=replace(channel.problem, static_obstacles=beveled)),
|
|
BenchmarkCase(
|
|
"fallback-custom-proxy", "Three arc bends with rectangular collision proxies", custom_problem, proxy_options, custom_routes
|
|
),
|
|
BenchmarkCase(
|
|
"fallback-custom-physical", "Three bends realized with an explicit physical polygon", custom_problem, physical_options, custom_routes
|
|
),
|
|
replace(
|
|
detours,
|
|
name="fallback-seeded-detour",
|
|
description="Caller supplies one feasible detour around a shared obstacle",
|
|
problem=replace(detours.problem, initial_paths=dict(detours.reference_paths[:1])),
|
|
),
|
|
replace(
|
|
parallel,
|
|
problem=replace(parallel.problem, initial_paths=parallel_seeds),
|
|
options=replace(parallel.options, refinement=replace(parallel.options.refinement, enabled=False)),
|
|
),
|
|
)
|
|
|
|
|
|
FALLBACK_BENCHMARK_CASES = _fallback_benchmarks()
|
|
|
|
|
|
DETOUR = _detour()
|
|
BENCHMARK_CASES = (
|
|
_open_or_shared_gate("open-bundle", "Four parallel routes on an open board", (122, 131, 140, 149)),
|
|
DETOUR,
|
|
_competing_detours(),
|
|
_open_or_shared_gate("shared-gate", "Three nets fit through one aperture", (140, 149, 158), wall=True),
|
|
_open_or_shared_gate("overloaded-gate", "Four nets contend for a three-track aperture", (131, 140, 149, 158), wall=True, expected_routed=3),
|
|
_mixed_width_gates(),
|
|
_blocking_straight(),
|
|
_blocking_straight(turn_limited=True),
|
|
_crossing_with_room(),
|
|
_offset_gates(),
|
|
_offset_gates(mirrored=True),
|
|
_reversed_heading(),
|
|
BenchmarkCase(
|
|
"terminal-bench-pair",
|
|
"Nets 03 and 04 share obstacles and compete for space",
|
|
replace(_TERMINAL_BENCH, nets=_TERMINAL_BENCH.nets[3:5]),
|
|
terminal_bench_options(),
|
|
),
|
|
BenchmarkCase("terminal-bench", "Nine-net PR 345 board with fixed east headings", _TERMINAL_BENCH, terminal_bench_options()),
|
|
*_TERMINAL_BENCH_POINT_CASES,
|
|
*COMPLEX_BENCHMARK_CASES,
|
|
)
|