Prune S-bend sequences that cannot fit the window
This commit is contained in:
parent
ff36f94e8f
commit
1723bf338f
2 changed files with 17 additions and 0 deletions
|
|
@ -270,6 +270,9 @@ def _bend_sequences(
|
||||||
@lru_cache(maxsize=4096)
|
@lru_cache(maxsize=4096)
|
||||||
def choose(delta: int, usable: int) -> _BendSequence | None:
|
def choose(delta: int, usable: int) -> _BendSequence | None:
|
||||||
magnitude = abs(delta)
|
magnitude = abs(delta)
|
||||||
|
# A circular S-bend advances at least as far as it shifts.
|
||||||
|
if magnitude > usable:
|
||||||
|
return None
|
||||||
while len(sequences) <= magnitude:
|
while len(sequences) <= magnitude:
|
||||||
height = len(sequences)
|
height = len(sequences)
|
||||||
candidates = [
|
candidates = [
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
from shapely.geometry import box
|
from shapely.geometry import box
|
||||||
|
|
||||||
from inire import CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
|
from inire import CongestionOptions, NetSpec, Port, RefinementOptions, RoutingOptions, RoutingProblem, SearchOptions, route
|
||||||
|
|
@ -20,6 +22,18 @@ def test_sbend_schedule_requires_a_window_long_enough_for_exact_spans() -> None:
|
||||||
assert [(sequence.span, sequence.offsets) for sequence in transitions[0]] == [(40, (20,))] * 3
|
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:
|
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=40, offsets=(-20, 10, 40, 0)) == {10: 30, 20: 40}
|
||||||
assert exact_sbend_spans(25, max_span=39, offsets=(-20,)) == {}
|
assert exact_sbend_spans(25, max_span=39, offsets=(-20,)) == {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue