Reuse column profiles across S-bend limit passes
This commit is contained in:
parent
13b2d8b7de
commit
5804ba568f
2 changed files with 36 additions and 11 deletions
|
|
@ -512,16 +512,20 @@ def _column_sbend_schedules(
|
|||
columns, widths, windows, preferences = layout.columns, layout.widths, layout.spans, layout.preferences
|
||||
# The first pass uses moderate lateral shifts. Later passes relax the
|
||||
# spacing or try smaller or larger bends if a transition will not fit.
|
||||
limits = tuple(dict.fromkeys(min(2 * radius - 1, ceil(radius * frac)) for frac in (0.8, 0.4, 1.44)))
|
||||
limits = (min(2 * radius - 1, ceil(radius * frac)) for frac in (0.8, 0.4, 1.44))
|
||||
span_sets = dict.fromkeys(tuple((d, span) for d, span in spans.items() if d <= maximum) for maximum in limits)
|
||||
active_span_sets = tuple(dict(span_set) for span_set in span_sets if span_set)
|
||||
|
||||
# Keep the base and extra-spacing profiles for the current slack setting.
|
||||
@lru_cache(maxsize=2 * len(columns))
|
||||
def profiles_for(column_index: int, spacing_slack: int, wall_slack: int) -> list[Profile]:
|
||||
return _column_profiles(
|
||||
problem, columns[column_index], widths, residues, preferences[column_index], spacing_slack, wall_slack, modulus,
|
||||
)
|
||||
|
||||
seen = set()
|
||||
for spacing_slack, wall_slack, maximum in product((5, 3, 2, 1, 0, 7), (1, 0), limits):
|
||||
active_spans = {d: span for d, span in spans.items() if d <= maximum}
|
||||
if not active_spans:
|
||||
continue
|
||||
interior = [
|
||||
_column_profiles(problem, column, widths, residues, preference, spacing_slack, wall_slack, modulus)
|
||||
for column, preference in zip(columns, preferences, strict=True)
|
||||
]
|
||||
for spacing_slack, wall_slack, active_spans in product((5, 3, 2, 1, 0, 7), (1, 0), active_span_sets):
|
||||
interior = [profiles_for(i, spacing_slack, wall_slack) for i in range(len(columns))]
|
||||
if weighted:
|
||||
adjacent = [[launch], *interior, [arrival]]
|
||||
reachable_offsets = (0, *(
|
||||
|
|
@ -534,9 +538,9 @@ def _column_sbend_schedules(
|
|||
reachable = tuple(tuple(tuple(y + d for d in offsets) for y in anchor) for anchor, offsets in anchors)
|
||||
seeded = _column_profiles(problem, column, widths, residues, preference, spacing_slack, wall_slack, modulus, reachable)
|
||||
interior[i] = sorted(set(interior[i] + seeded))
|
||||
for i, (column, preference) in enumerate(zip(columns, preferences, strict=True)):
|
||||
for i, column in enumerate(columns):
|
||||
if column.openings[0][0] == problem.bounds[1] or column.openings[-1][1] == problem.bounds[3]:
|
||||
roomier = _column_profiles(problem, column, widths, residues, preference, spacing_slack + 5, wall_slack, modulus)
|
||||
roomier = profiles_for(i, spacing_slack + 5, wall_slack)
|
||||
interior[i] = sorted(set(interior[i] + roomier[:45]))
|
||||
profiles = [[launch], *interior, [arrival]]
|
||||
for rows, moves in _schedules(
|
||||
|
|
|
|||
|
|
@ -243,6 +243,27 @@ def test_sbend_column_profiles_match_exhaustive_ranking_without_using_a_product(
|
|||
assert _columns._column_profiles(*args) == exhaustive
|
||||
|
||||
|
||||
@pytest.mark.parametrize("weighted", [False, True])
|
||||
def test_sbend_column_passes_reuse_profiles_and_skip_duplicate_span_sets(monkeypatch, weighted) -> None:
|
||||
profile_calls = Mock(wraps=_columns._column_profiles)
|
||||
schedule_calls = Mock(wraps=_columns._schedules)
|
||||
monkeypatch.setattr(_columns, "_column_profiles", profile_calls)
|
||||
monkeypatch.setattr(_columns, "_schedules", schedule_calls)
|
||||
nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(400, y + 800, 0)) for y in (40, 110, 180))
|
||||
column_positions = (80, 180, 280)
|
||||
keepouts = tuple(box(x, y, x + 20, y + 2) for x in column_positions for y in range(100, 700, 100))
|
||||
problem = RoutingProblem((0, 0, 410, 1700), nets, keepouts, clearance=0)
|
||||
search = SearchOptions(bend_radii=(), sbend_radii=(10,))
|
||||
|
||||
assert list(column_seed_candidates(problem, search, LENGTH_COST, weighted=weighted)) == []
|
||||
|
||||
# Two distinct span sets share the base and extra-spacing profiles for each slack pair.
|
||||
slack_pairs = 12
|
||||
assert schedule_calls.call_count == 2 * slack_pairs
|
||||
base_profile_calls = sum(len(call.args) == 8 for call in profile_calls.call_args_list)
|
||||
assert base_profile_calls <= 2 * len(column_positions) * slack_pairs
|
||||
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue