Refactor routing internals and archive retry benchmarks

This commit is contained in:
Jan Petykiewicz 2026-11-26 19:58:46 -08:00
commit ea5cfe7f31

View file

@ -1,56 +1,40 @@
"""Core, Terminal-Bench, and fallback routing fixtures."""
from __future__ import annotations
from dataclasses import dataclass, replace
from itertools import pairwise, product
from json import loads
from math import pi
from pathlib import Path
from typing import TYPE_CHECKING
from dataclasses import replace
from shapely.geometry import Polygon, box
from inire import Bend90Seed, NetSpec, PathSeed, Port, RoutingOptions, RoutingProblem, SBendSeed, StraightSeed
from inire.router._bundle import ordered_bundle_terminal_headings
from inire.router._waypoints import compile_waypoints
from inire.tests.terminal_bench_scenario import LENGTH_COST, OBSTACLES, terminal_bench_options, terminal_bench_problem
if TYPE_CHECKING:
from inire.seeds import PathSegmentSeed
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
@dataclass(frozen=True, slots=True)
class BenchmarkCase:
name: str
description: str
problem: RoutingProblem
options: RoutingOptions
reference_paths: tuple[tuple[str, PathSeed], ...] = ()
def fixed_headings_problem(self) -> RoutingProblem:
if self.options.topology.infer_terminal_headings:
return ordered_bundle_terminal_headings(self.problem)
return self.problem
def _options(bend_radius: float, sbend_radius: float | None = None) -> RoutingOptions:
options = terminal_bench_options()
return replace(
options,
search=replace(options.search, bend_radii=(bend_radius,), sbend_radii=(sbend_radius or bend_radius,)),
objective=replace(
options.objective,
bend_penalty=(LENGTH_COST["bend90"] - 1) * (pi * bend_radius / 2) * (bend_radius / 10) ** 0.5,
),
)
def _open_or_shared_gate(name: str, description: str, heights: tuple[int, ...], *, wall: bool = False) -> BenchmarkCase:
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)
return BenchmarkCase(name, description, RoutingProblem((0, 0, 450, 300), nets, obstacles, clearance=6), _options(25), reference)
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:
@ -77,7 +61,7 @@ def _competing_detours() -> BenchmarkCase:
)
)
return BenchmarkCase(
"competing-detours", "Two nets compete for a short detour around the same obstacle", problem, _options(25), tuple(reference)
"competing-detours", "Two nets compete for a short detour around the same obstacle", problem, benchmark_options(25), tuple(reference)
)
@ -97,7 +81,7 @@ def _offset_gates(mirrored: bool = False) -> BenchmarkCase:
)
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, _options(30, 25), (("offset", seed),))
return BenchmarkCase(name, "A lateral shift between two narrow apertures", problem, benchmark_options(30, 25), (("offset", seed),))
def _reversed_heading() -> BenchmarkCase:
@ -110,7 +94,7 @@ def _reversed_heading() -> BenchmarkCase:
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, _options(30), (("return", seed),)
"reversed-heading", "East-facing ports require westward travel past an obstacle", problem, benchmark_options(30), (("return", seed),)
)
@ -126,7 +110,7 @@ def _mixed_width_gates() -> BenchmarkCase:
"mixed-width-gates",
"A narrow aperture fits only the narrow net",
problem,
_options(25),
benchmark_options(25),
reference,
)
@ -149,9 +133,15 @@ def _blocking_straight(*, turn_limited: bool = False) -> BenchmarkCase:
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, _options(25), reference
"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, _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:
@ -167,7 +157,7 @@ def _crossing_with_room() -> BenchmarkCase:
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, _options(25), reference
"crossing-with-room", "An unlocked junction with room to route around either straight", problem, benchmark_options(25), reference
)
@ -221,7 +211,7 @@ def _ordered_bundle_benchmarks() -> tuple[BenchmarkCase, ...]:
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 = _options(40)
radius_40 = benchmark_options(40)
return (
replace(
base,
@ -257,342 +247,7 @@ def _ordered_bundle_benchmarks() -> tuple[BenchmarkCase, ...]:
)
@dataclass(frozen=True, slots=True)
class _Gate:
left: int
right: int
openings: tuple[tuple[int, ...], ...]
@property
def tracks(self) -> tuple[int, ...]:
return tuple(y for opening in self.openings for y in opening)
def _band(first: int, pitch: int = 18, count: int = 9) -> tuple[int, ...]:
return tuple(range(first, first + pitch * count, pitch))
def _gate_path(columns: tuple[tuple[int, int], ...], tracks: tuple[int, ...], start_x: int, finish_x: int) -> PathSeed:
"""Construct a feasibility witness with S-bends centered between columns."""
segments: list[PathSegmentSeed] = []
x = start_x
for ((_, after), (before, _)), (start_y, end_y) in zip(pairwise(columns), pairwise(tracks), strict=True):
if start_y == end_y:
continue
sign = 1 if end_y > start_y else -1
remaining = abs(end_y - start_y)
bends = []
advance = 0
# These offsets have integer forward spans at radius 50.
for offset, span in ((40, 80), (20, 60), (4, 28)):
count, remaining = divmod(remaining, offset)
bends.extend([SBendSeed(sign * offset, 50)] * count)
advance += span * count
if remaining or before - after <= advance:
raise ValueError("The benchmark's track shift must fit between its columns")
entrance = (after + before - advance) // 2
segments.append(StraightSeed(entrance - x))
segments.extend(bends)
x = entrance + advance
segments.append(StraightSeed(finish_x - x))
return PathSeed(tuple(segments))
def _gate_benchmark(
name: str,
description: str,
launch: tuple[int, ...],
arrival: tuple[int, ...],
gates: tuple[_Gate, ...],
*,
widths: tuple[int, ...] = (2,) * 9,
westbound: tuple[int, ...] = (),
edge_walls: bool = True,
terminal_stagger: int = 0,
) -> BenchmarkCase:
bounds = (0, 0, 2400, 1000)
launch_x, arrival_x = 40, 2360
clearance = 6
obstacles = []
for gate in gates:
openings = []
first = 0
for tracks in gate.openings:
margin = max(widths[first : first + len(tracks)]) / 2 + clearance + 1
openings.append((tracks[0] - margin, tracks[-1] + margin))
first += len(tracks)
intervals = [(end, start) for (_, end), (start, _) in pairwise(openings)]
if edge_walls:
intervals.extend(((0, openings[0][0]), (openings[-1][1], bounds[3])))
if any(end <= start for start, end in intervals):
raise ValueError("The benchmark's gate openings must leave room for their walls")
obstacles.extend(box(gate.left, start, gate.right, end) for start, end in intervals)
first_column = launch_x + 2 * terminal_stagger
last_column = arrival_x - 2 * terminal_stagger
columns = ((first_column, first_column), *((gate.left, gate.right) for gate in gates), (last_column, last_column))
profiles = (launch, *(gate.tracks for gate in gates), arrival)
nets = []
references = []
for i, (width, track) in enumerate(zip(widths, zip(*profiles, strict=True), strict=True)):
net_id = f"net_{i:02d}"
left_x = launch_x + terminal_stagger * (i % 3)
right_x = arrival_x - terminal_stagger * ((i + 1) % 3)
path = _gate_path(columns, track, left_x, right_x)
if i in westbound:
start, target = Port(right_x, track[-1], 180), Port(left_x, track[0], 180)
# Reversal rotates the local frame by 180 degrees, preserving the signed S-bend offset.
path = PathSeed(path.segments[::-1])
else:
start, target = Port(left_x, track[0], 0), Port(right_x, track[-1], 0)
nets.append(NetSpec(net_id, start, target, width=width))
references.append((net_id, path))
options = _options(50)
options = replace(options, refinement=replace(options.refinement, enabled=False))
problem = RoutingProblem(bounds, tuple(nets), tuple(obstacles), clearance=clearance)
return BenchmarkCase(name, description, problem, options, tuple(references))
def _serial_gate_benchmarks() -> tuple[BenchmarkCase, ...]:
return (
_gate_benchmark(
"serial-alternating",
"Three single apertures make the entire bundle shift up, down, and up",
_band(300),
_band(340),
(_Gate(450, 520, (_band(340),)), _Gate(990, 1060, (_band(300),)), _Gate(1640, 1720, (_band(340),))),
),
_gate_benchmark(
"serial-staircase",
"Four apertures step a densely packed bundle upward in 20-unit increments",
_band(250, 12),
_band(350, 12),
tuple(_Gate(x, x + 65, (_band(y, 12),)) for x, y in zip((420, 850, 1290, 1760), (270, 290, 310, 330), strict=True)),
),
_gate_benchmark(
"serial-compression",
"Four apertures compress a bundle from 18-unit track pitch to 10 and allow a staged fan-out",
_band(300),
_band(300),
(
_Gate(450, 520, (_band(300),)),
_Gate(860, 930, (_band(316, 14),)),
_Gate(1340, 1400, (_band(332, 10),)),
_Gate(1820, 1880, (_band(316, 14),)),
),
),
_gate_benchmark(
"serial-terminal-jogs",
"Staggered ports bring small lateral shifts close to both ends of the gate sequence",
(296, 320, 344, 356, 380, 404, 416, 440, 464),
(344, 360, 376, 404, 420, 436, 464, 480, 496),
(_Gate(290, 350, (_band(300, 20),)), _Gate(1070, 1130, (_band(320, 20),)), _Gate(2030, 2100, (_band(340, 20),))),
),
_gate_benchmark(
"serial-close-walls",
"Four closely spaced walls limit the run-up for alternating 40-unit lateral shifts",
_band(500),
_band(500),
(
_Gate(720, 820, (_band(500),)),
_Gate(920, 1000, (_band(540),)),
_Gate(1110, 1190, (_band(500),)),
_Gate(1310, 1430, (_band(540),)),
),
),
)
def _split_gate_benchmarks() -> tuple[BenchmarkCase, ...]:
return (
_gate_benchmark(
"split-four-five",
"A single opening divides into four- and five-track branches and then merges",
_band(360),
_band(360),
(_Gate(470, 550, (_band(360),)), _Gate(1040, 1170, (_band(320, count=4), _band(472, count=5))), _Gate(1690, 1770, (_band(360),))),
),
_gate_benchmark(
"split-moving-divider",
"The first divider splits two and seven tracks, and the next splits five and four",
_band(350, 20),
_band(370, 20),
(
_Gate(420, 495, (_band(310, 20, 2), _band(410, 20, 7))),
_Gate(1000, 1110, (_band(330, 20, 5), _band(470, 20, 4))),
_Gate(1670, 1750, (_band(370, 20),)),
),
),
_gate_benchmark(
"split-three-branches",
"Nine tracks split into three apertures before two of the branches merge",
_band(380),
_band(380),
(
_Gate(460, 530, (_band(340, count=3), _band(434, count=3), _band(528, count=3))),
_Gate(1110, 1190, (_band(380, count=6), _band(528, count=3))),
_Gate(1710, 1790, (_band(380),)),
),
),
_gate_benchmark(
"split-mixed-width",
"The branch openings have distinct clearances for width-2, width-4, and width-6 tracks",
_band(270, 22),
_band(290, 22),
(
_Gate(450, 550, (_band(270, 22),)),
_Gate(1070, 1140, (_band(250, 22, 3), _band(336, 22, 3), _band(442, 22, 3))),
_Gate(1720, 1820, (_band(290, 22),)),
),
widths=(2, 2, 2, 4, 4, 4, 6, 6, 6),
),
_gate_benchmark(
"split-asymmetric-merge",
"Three unequal apertures close down to two as the central track joins the lower branch",
_band(470, 20),
_band(490, 20),
(
_Gate(470, 560, (_band(430, 20, 2), (510,), _band(570, 20, 6))),
_Gate(1000, 1080, (_band(470, 20, 3), _band(550, 20, 6))),
_Gate(1620, 1710, (_band(490, 20),)),
),
),
)
def _bypass_benchmarks() -> tuple[BenchmarkCase, ...]:
return (
_gate_benchmark(
"bypass-opposed-banks",
"A four-net westbound bank and a five-net eastbound bank detour around three free-standing obstacles",
_band(380),
_band(380),
(
_Gate(430, 620, (_band(340, count=4), _band(492, count=5))),
_Gate(1070, 1250, (_band(380, count=4), _band(472, count=5))),
_Gate(1720, 1890, (_band(340, count=4), _band(492, count=5))),
),
westbound=(0, 1, 2, 3),
edge_walls=False,
),
_gate_benchmark(
"bypass-interleaved-directions",
"Interleaved eastbound and westbound terminals detour around blockers with alternating cut points",
_band(370, 20),
_band(370, 20),
(
_Gate(410, 580, (_band(350, 20, 3), _band(450, 20, 6))),
_Gate(1010, 1200, (_band(350, 20, 5), _band(490, 20, 4))),
_Gate(1640, 1800, (_band(350, 20, 3), _band(450, 20, 6))),
),
westbound=(1, 3, 5, 7),
edge_walls=False,
),
_gate_benchmark(
"bypass-long-dividers",
"Long free-standing dividers leave short gaps to adjust lanes before the next bypass",
_band(300),
_band(340),
(
_Gate(290, 680, (_band(280, count=5), _band(430, count=4))),
_Gate(820, 1210, (_band(300, count=5), _band(430, count=4))),
_Gate(1380, 1790, (_band(320, count=5), _band(450, count=4))),
),
westbound=(5, 6, 7, 8),
edge_walls=False,
),
_gate_benchmark(
"bypass-three-branches",
"Two central obstacles per column create three detour choices with mixed travel directions",
_band(330, 20),
_band(330, 20),
(
_Gate(370, 530, (_band(290, 20, 3), _band(390, 20, 3), _band(490, 20, 3))),
_Gate(990, 1170, (_band(310, 20, 3), _band(390, 20, 3), _band(470, 20, 3))),
_Gate(1580, 1770, (_band(290, 20, 3), _band(390, 20, 3), _band(490, 20, 3))),
),
westbound=(3, 4, 5),
edge_walls=False,
),
_gate_benchmark(
"bypass-mixed-width",
"Wide westbound routes share the bypass area with six narrower eastbound routes",
_band(520, 22),
_band(500, 22),
(
_Gate(450, 600, (_band(500, 22, 3), _band(606, 22, 6))),
_Gate(1010, 1190, (_band(480, 22, 3), _band(606, 22, 6))),
_Gate(1650, 1810, (_band(480, 22, 6), _band(672, 22, 3))),
),
widths=(2, 2, 2, 3, 3, 3, 6, 6, 6),
westbound=(6, 7, 8),
edge_walls=False,
),
)
COMPLEX_BENCHMARK_CASES = (
*_ordered_bundle_benchmarks(),
*_serial_gate_benchmarks(),
*_split_gate_benchmarks(),
*_bypass_benchmarks(),
)
def _validation_benchmarks() -> tuple[BenchmarkCase, ...]:
return (
_gate_benchmark(
"holdout-staggered-five-gates",
"Staggered terminals and five unequal walls with alternating apertures",
_band(280, 16),
_band(320, 16),
tuple(
_Gate(left, right, (_band(y, 16),))
for left, right, y in ((300, 365, 300), (610, 710, 320), (930, 1020, 280), (1240, 1340, 300), (1760, 1840, 320))
),
terminal_stagger=31,
),
_gate_benchmark(
"holdout-staggered-opposed",
"Opposing travel with staggered banks and narrow gaps between three walls",
_band(520, 16),
_band(500, 16),
(_Gate(670, 820, (_band(520, 16),)), _Gate(925, 1040, (_band(480, 16),)), _Gate(1145, 1220, (_band(520, 16),))),
westbound=(0, 3, 5, 6),
terminal_stagger=24,
),
_gate_benchmark(
"holdout-uneven-split",
"Interleaved waveguide widths through three apertures and a single merge",
_band(360, 24),
_band(380, 24),
(
_Gate(440, 610, (_band(340, 24, 2), _band(408, 24, 4), _band(544, 24, 3))),
_Gate(1030, 1110, (_band(360, 24),)),
_Gate(1530, 1770, (_band(340, 24, 2), _band(408, 24, 4), _band(544, 24, 3))),
),
widths=(2, 5, 2, 4, 3, 6, 2, 5, 3),
terminal_stagger=23,
),
_gate_benchmark(
"holdout-uneven-bypass",
"Asymmetric free-standing obstacles with mixed widths and opposing launches",
_band(370, 24),
_band(350, 24),
(
_Gate(350, 510, (_band(330, 24, 4), _band(486, 24, 5))),
_Gate(810, 1150, (_band(350, 24, 3), _band(462, 24, 6))),
_Gate(1600, 1920, (_band(330, 24, 4), _band(486, 24, 5))),
),
widths=(4, 2, 6, 2, 5, 2, 3, 4, 2),
westbound=(1, 2, 7),
edge_walls=False,
terminal_stagger=41,
),
)
VALIDATION_BENCHMARK_CASES = _validation_benchmarks()
COMPLEX_BENCHMARK_CASES = (*_ordered_bundle_benchmarks(), *GATE_BENCHMARK_CASES)
def _fallback_benchmarks() -> tuple[BenchmarkCase, ...]:
@ -629,7 +284,7 @@ def _fallback_benchmarks() -> tuple[BenchmarkCase, ...]:
(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 = _options(10)
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)
@ -675,170 +330,13 @@ def _fallback_benchmarks() -> tuple[BenchmarkCase, ...]:
FALLBACK_BENCHMARK_CASES = _fallback_benchmarks()
def _external_benchmarks() -> tuple[BenchmarkCase, ...]:
fixture = Path(__file__).with_name("data") / "external_routing_benchmarks.json"
cases = []
for row in loads(fixture.read_text(encoding="utf-8"))["cases"]:
problem = RoutingProblem(
tuple(row["bounds"]),
tuple(NetSpec(net["id"], Port(*net["start"]), Port(*net["target"]), width=net["width"]) for net in row["nets"]),
tuple(Polygon(parts[0], parts[1:]) for parts in row["obstacles"]),
clearance=row["clearance"],
)
options = _options(row["bend_radius"])
options = replace(
options,
search=replace(options.search, min_straight_length=row["min_straight"]),
refinement=replace(options.refinement, enabled=False),
)
cases.append(BenchmarkCase(row["name"], f"Fixed-placement routing from {row['source']}", problem, options))
return tuple(cases)
EXTERNAL_BENCHMARK_CASES = _external_benchmarks()
_CROSSING_RADIUS = 25
_CROSSING_PORT_OFFSET = 14
_CROSSING_CLEARANCE = 4
def _crossing_keepout(x: int, y: int) -> Polygon:
# Recessed ports sit at the ends of access slots in a fixed 40-unit device.
# The remaining polygon reserves the crossing's core for the placed cell.
face, port = 20, _CROSSING_PORT_OFFSET
slot = _CROSSING_CLEARANCE + 2 # Unit guide half-width and access margin.
body = box(x - face, y - face, x + face, y + face)
for access in (
box(x - face, y - slot, x - port + slot, y + slot),
box(x + port - slot, y - slot, x + face, y + slot),
box(x - slot, y - face, x + slot, y - port + slot),
box(x - slot, y + port - slot, x + slot, y + face),
):
body = body.difference(access)
return body
def _crossing_leg_seed(net: NetSpec) -> PathSeed:
dx, dy = net.target.x - net.start.x, net.target.y - net.start.y
forward, offset = ((dx, dy), (dy, -dx), (-dx, -dy), (-dy, dx))[int(net.start.r) // 90]
if not offset:
return PathSeed((StraightSeed(forward),))
# Each stagger in the crossing grids uses a 20-unit offset. At radius
# 25 its forward span is exactly 40, leaving clearance at both ports.
assert abs(offset) == 20
assert forward > 40
first = (forward - 40) // 2
return PathSeed((StraightSeed(first), SBendSeed(offset, _CROSSING_RADIUS), StraightSeed(forward - first - 40)))
def _crossing_grid(
name: str,
description: str,
xs: tuple[int, ...],
ys: tuple[int, ...],
*,
staggered: bool = False,
) -> BenchmarkCase:
width, height = xs[-1] + 180, ys[-1] + 180
offset = _CROSSING_PORT_OFFSET
stagger = 20 if staggered else 0
cells = {
(row, column): (x + stagger * (row % 2), y + stagger * (column % 2)) for (row, y), (column, x) in product(enumerate(ys), enumerate(xs))
}
nets = []
def add_bank(label: str, ports: list[tuple[str, Port]], *, reverse: bool) -> None:
for (source, start), (sink, target) in zip(ports[::2], ports[1::2], strict=True):
if reverse:
nets.append(NetSpec(f"{label}:{sink}->{source}", target.translate(0, 0, 180), start.translate(0, 0, 180)))
else:
nets.append(NetSpec(f"{label}:{source}->{sink}", start, target))
for row in range(len(ys)):
left_y = cells[row, 0][1] - stagger
right_y = cells[row, len(xs) - 1][1] + stagger
ports = [("west", Port(30, left_y, 0))]
for column in range(len(xs)):
x, y = cells[row, column]
cell = f"x{row}_{column}"
ports.extend(((f"{cell}.w", Port(x - offset, y, 0)), (f"{cell}.e", Port(x + offset, y, 0))))
ports.append(("east", Port(width - 30, right_y, 0)))
add_bank(f"h{row}", ports, reverse=bool(row % 2))
for column in range(len(xs)):
bottom_x = cells[0, column][0] + stagger
top_x = cells[len(ys) - 1, column][0] - stagger
ports = [("south", Port(bottom_x, 30, 90))]
for row in range(len(ys)):
x, y = cells[row, column]
cell = f"x{row}_{column}"
ports.extend(((f"{cell}.s", Port(x, y - offset, 90)), (f"{cell}.n", Port(x, y + offset, 90))))
ports.append(("north", Port(top_x, height - 30, 90)))
add_bank(f"v{column}", ports, reverse=bool(column % 2))
problem = RoutingProblem(
(0, 0, width, height), tuple(nets), tuple(_crossing_keepout(*center) for center in cells.values()), clearance=_CROSSING_CLEARANCE
)
reference = tuple((net.net_id, _crossing_leg_seed(net)) for net in nets)
return BenchmarkCase(name, description, problem, _options(_CROSSING_RADIUS), reference)
def _crossing_obstructed_approaches() -> BenchmarkCase:
offset = _CROSSING_PORT_OFFSET
nets = (
NetSpec("west->x0.w", Port(30, 300, 0), Port(300 - offset, 300, 0)),
NetSpec("x0.e->south-east", Port(300 + offset, 300, 0), Port(530, 204, 270)),
NetSpec("south->x0.s", Port(280, 35, 90), Port(300, 300 - offset, 90)),
NetSpec("x0.n->north", Port(300, 300 + offset, 90), Port(300, 570, 90)),
)
west, east, south, north = nets
west_seed, _ = compile_waypoints(
((30, 300), (66, 300), (66, 215), (220, 215), (220, 300), (west.target.x, 300)), west.start, _CROSSING_RADIUS
)
east_seed, _ = compile_waypoints(((east.start.x, 300), (530, 300), (530, 204)), east.start, _CROSSING_RADIUS)
problem = RoutingProblem(
(0, 0, 600, 600),
nets,
(_crossing_keepout(300, 300), box(98, 265, 153, 335), box(402, 222, 468, 280)),
clearance=_CROSSING_CLEARANCE,
)
reference = (
(west.net_id, west_seed),
(east.net_id, east_seed),
(south.net_id, _crossing_leg_seed(south)),
(north.net_id, _crossing_leg_seed(north)),
)
return BenchmarkCase(
"crossing-obstructed-approaches",
"A fixed crossing with a blocked approach, offset launch, and turning exit",
problem,
_options(_CROSSING_RADIUS),
reference,
)
CROSSING_BENCHMARK_CASES = (
_crossing_grid("crossing-single", "Four straight legs at one placed crossing", (160,), (160,)),
_crossing_obstructed_approaches(),
_crossing_grid("crossing-aligned-grid", "Six placed crossings linked between opposite port banks", (160, 263, 366), (165, 285)),
_crossing_grid(
"crossing-staggered-grid",
"Nine staggered crossings with short S-bend links and offset terminal banks",
(175, 280, 395),
(160, 266, 388),
staggered=True,
),
)
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),
_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),