82 lines
3.9 KiB
Python
82 lines
3.9 KiB
Python
from unittest.mock import Mock
|
|
|
|
from shapely.geometry import box
|
|
|
|
from inire import CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
|
|
from inire.geometry.sbend import exact_sbend_spans
|
|
from inire.router import _columns
|
|
from inire.router._columns import _jog_pivots, _schedules, column_seed_candidates
|
|
from inire.tests.terminal_bench_scenario import LENGTH_COST
|
|
|
|
|
|
def test_sbend_schedule_requires_a_window_long_enough_for_exact_spans() -> None:
|
|
profiles = [[(10, 30, 50)], [(30, 50, 70)]]
|
|
widths = (2, 2, 2)
|
|
spans = exact_sbend_spans(25, max_span=50)
|
|
short = _schedules(((0, 0), (35, 35)), profiles, widths, 2, 25, spans, LENGTH_COST, weighted=False, sbend_penalty=0)
|
|
assert list(short) == []
|
|
|
|
long = _schedules(((0, 0), (50, 50)), profiles, widths, 2, 25, spans, LENGTH_COST, weighted=False, sbend_penalty=0)
|
|
[(rows, transitions)] = list(long)
|
|
assert rows == ((10, 30, 50), (30, 50, 70))
|
|
assert [(sequence.span, sequence.offsets) for sequence in transitions[0]] == [(40, (20,))] * 3
|
|
|
|
|
|
def test_sbend_sequence_skips_table_growth_for_shifts_larger_than_the_window(monkeypatch) -> None:
|
|
make_sequence = Mock(wraps=_columns._BendSequence)
|
|
monkeypatch.setattr(_columns, "_BendSequence", make_sequence)
|
|
choose = _columns._bend_sequences({10: 30}, 25, LENGTH_COST, weighted=False, sbend_penalty=0)
|
|
make_sequence.reset_mock()
|
|
|
|
assert choose(100, 40) is None
|
|
assert choose(-100, 40) is None
|
|
make_sequence.assert_not_called()
|
|
assert choose(-10, 30).offsets == (-10,)
|
|
|
|
|
|
def test_exact_sbend_spans_filter_by_window_and_configured_offsets() -> None:
|
|
assert exact_sbend_spans(25, max_span=40, offsets=(-20, 10, 40, 0)) == {10: 30, 20: 40}
|
|
assert exact_sbend_spans(25, max_span=39, offsets=(-20,)) == {}
|
|
|
|
|
|
def test_large_unused_sbend_radius_skips_column_enumeration(monkeypatch) -> None:
|
|
def unexpected_enumeration(*_args, **_kwargs):
|
|
raise AssertionError("A single net is ineligible for column planning")
|
|
|
|
monkeypatch.setattr(_columns, "exact_sbend_spans", unexpected_enumeration)
|
|
net = NetSpec("line", Port(10, 50, 0), Port(200, 50, 0))
|
|
problem = RoutingProblem((0, 0, 300, 100), (net,))
|
|
search = SearchOptions(node_limit=2, bend_radii=(), sbend_radii=(1_000_000_000,))
|
|
|
|
assert route(problem, options=RoutingOptions(search=search)).results_by_net[net.net_id].is_valid
|
|
|
|
|
|
def test_column_windows_bound_enumeration_for_a_large_sbend_radius() -> None:
|
|
nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(95, y + 5, 0)) for y in (20, 40, 60))
|
|
problem = RoutingProblem((0, 0, 100, 100), nets, (box(40, 0, 60, 10),))
|
|
search = SearchOptions(sbend_radii=(1_000_000_000,))
|
|
|
|
assert list(column_seed_candidates(problem, search, LENGTH_COST, weighted=False)) == []
|
|
|
|
|
|
def test_automatic_routing_skips_column_profiles_with_too_many_partitions(monkeypatch) -> None:
|
|
def unexpected_profiles(*_args, **_kwargs):
|
|
raise AssertionError("The column has more than five million track assignments")
|
|
|
|
monkeypatch.setattr(_columns, "_column_profiles", unexpected_profiles)
|
|
nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(200, y, 0)) for y in range(400, 560, 20))
|
|
keepouts = tuple(box(90, y, 110, y + 3) for y in range(10, 340, 15))
|
|
problem = RoutingProblem((0, 0, 210, 600), nets, keepouts, clearance=0)
|
|
options = RoutingOptions(
|
|
search=SearchOptions(node_limit=20, bend_radii=(), sbend_radii=(10,)),
|
|
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
|
|
refinement=RefinementOptions(enabled=False),
|
|
)
|
|
|
|
results = route(problem, options=options).results_by_net
|
|
assert all(results[net.net_id].is_valid for net in nets)
|
|
|
|
|
|
def test_jog_transition_rejects_an_offset_that_cannot_fit_two_bends() -> None:
|
|
assert _jog_pivots((10, 40), (17, 40), (0, 100), (2, 2), 2, 5, 1) is None
|
|
assert _jog_pivots((10, 40), (25, 40), (0, 100), (2, 2), 2, 5, 1) == (8, None)
|