Remove the dependency fallback and joint portal lane retry, make tiered search opt-in, and consolidate tests while adding low-length-cost routing boards.
50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
from dataclasses import replace
|
|
|
|
import pytest
|
|
from shapely.geometry import Polygon, box
|
|
|
|
from inire import CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
|
|
from inire.results import CapacityLimit
|
|
from inire.router._capacity import cut_capacity
|
|
|
|
|
|
def test_cut_capacity_counts_strict_crossings_and_requires_rectangular_obstacles() -> None:
|
|
through = tuple(NetSpec(str(y), Port(5, y, 0), Port(95, y, 0)) for y in (15, 40, 75))
|
|
arriving = NetSpec("arriving", Port(5, 45, 0), Port(46, 45, 0))
|
|
departing = NetSpec("departing", Port(44, 50, 0), Port(95, 50, 0))
|
|
vertical = NetSpec("vertical", Port(45, 10, 90), Port(45, 90, 90))
|
|
obstacles = (box(20, 0, 50, 30), box(20, 5, 50, 15), box(40, 34, 60, 100))
|
|
problem = RoutingProblem((0, 0, 100, 100), (*through, arriving, departing, vertical), obstacles, clearance=1)
|
|
|
|
options = RoutingOptions()
|
|
assert cut_capacity(problem, options) == CapacityLimit(45, 3, 1, 4)
|
|
|
|
triangle = Polygon([(10, 10), (20, 10), (10, 20)])
|
|
assert cut_capacity(replace(problem, static_obstacles=(*obstacles, triangle)), options) is None
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
('heading', 'clearance', 'second_width', 'conflict'),
|
|
[
|
|
(90, 1e-07, 2 - 1e-07, True),
|
|
(90, 0.25, 1.5, False),
|
|
],
|
|
)
|
|
def test_automatic_bound_matches_terminal_face_clearance(heading, clearance, second_width, conflict) -> None:
|
|
nets = tuple(
|
|
NetSpec(net_id, Port(10, y, 0).rotated(heading, (50, 50)), Port(90, y, 0).rotated(heading, (50, 50)), width)
|
|
for net_id, y, width in (("a", 20, 2), ("clear", 40, 2), ("b", 22, second_width))
|
|
)
|
|
problem = RoutingProblem((0, 0, 100, 100), nets, clearance=clearance)
|
|
options = RoutingOptions(
|
|
search=SearchOptions(node_limit=20, bend_radii=(), sbend_radii=()),
|
|
congestion=CongestionOptions(max_iterations=1),
|
|
refinement=RefinementOptions(enabled=False),
|
|
)
|
|
|
|
run = route(problem, options=options)
|
|
|
|
assert run.automatic is not None
|
|
assert run.automatic.port_conflicts == ((("a", "b"),) if conflict else ())
|
|
assert run.automatic.max_routed == len(nets) - int(conflict)
|
|
assert len(run.automatic.verified_net_ids) <= run.automatic.max_routed
|