Route the blocking link after packing short links
This commit is contained in:
parent
d64c70c68f
commit
9e97945174
4 changed files with 67 additions and 5 deletions
|
|
@ -56,6 +56,14 @@ def components_overlap(
|
||||||
normal, lateral = (port.x, port.y) if axis == 0 else (port.y, port.x)
|
normal, lateral = (port.x, port.y) if axis == 0 else (port.y, port.x)
|
||||||
half_width = min(width_a, width_b) / 2
|
half_width = min(width_a, width_b) / 2
|
||||||
lo, hi = lateral - half_width, lateral + half_width
|
lo, hi = lateral - half_width, lateral + half_width
|
||||||
|
# An intersection contained in the shared face cannot count as overlap.
|
||||||
|
if (
|
||||||
|
max(bounds_a[axis], bounds_b[axis]) >= normal - TOLERANCE_LINEAR
|
||||||
|
and min(bounds_a[axis + 2], bounds_b[axis + 2]) <= normal + TOLERANCE_LINEAR
|
||||||
|
and max(bounds_a[1 - axis], bounds_b[1 - axis]) >= lo - TOLERANCE_LINEAR
|
||||||
|
and min(bounds_a[3 - axis], bounds_b[3 - axis]) <= hi + TOLERANCE_LINEAR
|
||||||
|
):
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
at_join = False
|
at_join = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -271,11 +271,16 @@ class _AutomaticRun:
|
||||||
if not trials or len(_best_trial(trials).valid_costs) < len(problem.nets):
|
if not trials or len(_best_trial(trials).valid_costs) < len(problem.nets):
|
||||||
planner = "local-sbend"
|
planner = "local-sbend"
|
||||||
with self._time("plan", planner=planner):
|
with self._time("plan", planner=planner):
|
||||||
shifts = short_shift_seed_set(problem, options.search, self._selection_cost)
|
shifts = short_shift_seed_set(problem, options.search, self._selection_cost, defer_blocker=not self.problem.initial_paths)
|
||||||
if shifts is not None:
|
if shifts is not None:
|
||||||
trial = verify(replace(problem, initial_paths=shifts), planner)
|
trial = verify(replace(problem, initial_paths=shifts), planner)
|
||||||
complete = len(trial.valid_costs) == len(problem.nets)
|
complete = len(trial.valid_costs) == len(problem.nets)
|
||||||
trials.append(trial if complete else replace(trial, selection="incomplete-layout"))
|
trials.append(trial if complete else replace(trial, selection="incomplete-layout"))
|
||||||
|
if len(shifts) == len(problem.nets) - 1:
|
||||||
|
detour = self._residual_constructive_trial(options, trial, limit_per_pass=16)
|
||||||
|
if detour is not None:
|
||||||
|
trials.append(detour)
|
||||||
|
return trials, tuple(rejections)
|
||||||
if not complete:
|
if not complete:
|
||||||
rejections.append("Local S-bend layout failed full verification")
|
rejections.append("Local S-bend layout failed full verification")
|
||||||
return trials, tuple(rejections)
|
return trials, tuple(rejections)
|
||||||
|
|
@ -459,7 +464,17 @@ class _AutomaticRun:
|
||||||
planner = "residual-dogleg"
|
planner = "residual-dogleg"
|
||||||
candidates = residual_dogleg_candidates(residual, options.search, limit_per_pass=limit_per_pass)
|
candidates = residual_dogleg_candidates(residual, options.search, limit_per_pass=limit_per_pass)
|
||||||
with self._time("plan", planner=planner, policy=planner):
|
with self._time("plan", planner=planner, policy=planner):
|
||||||
|
world = None
|
||||||
for seed in candidates:
|
for seed in candidates:
|
||||||
|
path = materialize_path_seed(
|
||||||
|
seed, start=net.start, net_width=net.width, search=options.search, clearance=residual.clearance, bounds=residual.bounds,
|
||||||
|
)
|
||||||
|
if not path or path[-1].end_port != net.target:
|
||||||
|
continue
|
||||||
|
if world is None:
|
||||||
|
world = RoutingWorld.from_problem(residual, board=self.board)
|
||||||
|
if not world.verify_path_report(net.net_id, path).is_valid:
|
||||||
|
continue
|
||||||
candidate = replace(problem, initial_paths={**seeds, net.net_id: seed})
|
candidate = replace(problem, initial_paths={**seeds, net.net_id: seed})
|
||||||
trial = self._verify(candidate, planner, policy=planner)
|
trial = self._verify(candidate, planner, policy=planner)
|
||||||
if len(trial.valid_costs) == len(problem.nets):
|
if len(trial.valid_costs) == len(problem.nets):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from itertools import islice
|
from itertools import combinations, islice
|
||||||
from math import ceil, floor, isfinite
|
from math import ceil, floor, isfinite
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|
@ -197,7 +197,9 @@ def _shift_seeds(forward: int, offset: int, search: SearchOptions) -> Iterator[P
|
||||||
yield _path(lead, SBendSeed(offset, radius), spare - lead)
|
yield _path(lead, SBendSeed(offset, radius), spare - lead)
|
||||||
|
|
||||||
|
|
||||||
def short_shift_seed_set(problem: RoutingProblem, search: SearchOptions, score: Scorer) -> dict[str, PathSeed] | None:
|
def short_shift_seed_set(
|
||||||
|
problem: RoutingProblem, search: SearchOptions, score: Scorer, *, defer_blocker: bool = False,
|
||||||
|
) -> dict[str, PathSeed] | None:
|
||||||
"""Fit links between fixed ports across both axes of a layout."""
|
"""Fit links between fixed ports across both axes of a layout."""
|
||||||
if problem.initial_paths or len(problem.nets) < 3 or len({net.start.r % 180 for net in problem.nets}) < 2:
|
if problem.initial_paths or len(problem.nets) < 3 or len({net.start.r % 180 for net in problem.nets}) < 2:
|
||||||
return None
|
return None
|
||||||
|
|
@ -222,4 +224,21 @@ def short_shift_seed_set(problem: RoutingProblem, search: SearchOptions, score:
|
||||||
return None
|
return None
|
||||||
ranked.sort(key=lambda choice: choice[0])
|
ranked.sort(key=lambda choice: choice[0])
|
||||||
candidates[net.net_id] = [(seed, footprint) for _, seed, footprint in ranked]
|
candidates[net.net_id] = [(seed, footprint) for _, seed, footprint in ranked]
|
||||||
return _pack_routes(candidates, problem.clearance)
|
packed = _pack_routes(candidates, problem.clearance)
|
||||||
|
if packed is not None or not defer_blocker or not search.bend_radii:
|
||||||
|
return packed
|
||||||
|
|
||||||
|
# When all conflicts between forced choices share one net, try packing
|
||||||
|
# the other links so the caller can detour the blocker around them.
|
||||||
|
forced = [(net_id, choices[0][1]) for net_id, choices in candidates.items() if len(choices) == 1]
|
||||||
|
blockers: set[str] | None = None
|
||||||
|
for (net_id, a), (peer_id, b) in combinations(forced, 2):
|
||||||
|
if _violates_net_clearance(a, b, problem.clearance):
|
||||||
|
pair = {net_id, peer_id}
|
||||||
|
blockers = pair if blockers is None else blockers & pair
|
||||||
|
if not blockers:
|
||||||
|
return None
|
||||||
|
if blockers and len(blockers) == 1:
|
||||||
|
candidates.pop(blockers.pop())
|
||||||
|
return _pack_routes(candidates, problem.clearance)
|
||||||
|
return None
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from inire import (
|
||||||
SBendSeed, SearchOptions, StraightSeed, TopologyOptions, route,
|
SBendSeed, SearchOptions, StraightSeed, TopologyOptions, route,
|
||||||
)
|
)
|
||||||
from inire.constants import TOLERANCE_LINEAR
|
from inire.constants import TOLERANCE_LINEAR
|
||||||
|
from inire.router import _automatic
|
||||||
from inire.router._automatic import _AutomaticRun
|
from inire.router._automatic import _AutomaticRun
|
||||||
from inire.router._capacity import port_conflicts
|
from inire.router._capacity import port_conflicts
|
||||||
from inire.router._routing_policy import _disconnected_nets
|
from inire.router._routing_policy import _disconnected_nets
|
||||||
|
|
@ -102,7 +103,13 @@ def test_residual_perimeter_completes_a_return_with_straight_peers(name) -> None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.routing_corpus
|
@pytest.mark.routing_corpus
|
||||||
def test_final_dogleg_can_reuse_incumbents_from_seed_fallback() -> None:
|
def test_final_dogleg_can_reuse_incumbents_from_seed_fallback(monkeypatch) -> None:
|
||||||
|
short_shift_seed_set = _automatic.short_shift_seed_set
|
||||||
|
|
||||||
|
def full_shift_set(problem, search, score, **_kwargs):
|
||||||
|
return short_shift_seed_set(problem, search, score)
|
||||||
|
|
||||||
|
monkeypatch.setattr(_automatic, "short_shift_seed_set", full_shift_set)
|
||||||
(case,) = CASE_GROUPS["retry-holdout-reversed-bank"]
|
(case,) = CASE_GROUPS["retry-holdout-reversed-bank"]
|
||||||
options = automatic_options(profile_options(case, "corpus-regression"), "corpus-regression")
|
options = automatic_options(profile_options(case, "corpus-regression"), "corpus-regression")
|
||||||
|
|
||||||
|
|
@ -115,6 +122,19 @@ def test_final_dogleg_can_reuse_incumbents_from_seed_fallback() -> None:
|
||||||
assert set(run.automatic.verified_net_ids) == {net.net_id for net in case.problem.nets}
|
assert set(run.automatic.verified_net_ids) == {net.net_id for net in case.problem.nets}
|
||||||
|
|
||||||
|
|
||||||
|
def test_local_shift_plan_can_leave_one_conflicting_net_for_a_detour() -> None:
|
||||||
|
(case,) = CASE_GROUPS["stress-crossings-shared-outside-detour"]
|
||||||
|
options = automatic_options(profile_options(case, "corpus-regression"), "corpus-regression")
|
||||||
|
|
||||||
|
run = route(case.problem, options=options)
|
||||||
|
|
||||||
|
assert run.automatic.selected_planner == "residual-dogleg"
|
||||||
|
assert run.metrics.nodes_expanded == 0
|
||||||
|
assert all(result.is_valid for result in run.results_by_net.values())
|
||||||
|
[partial] = [stage for stage in run.automatic.stages if stage.planner == "local-sbend" and stage.operation == "verify"]
|
||||||
|
assert set(partial.valid_net_ids) == {net.net_id for net in case.problem.nets if net.net_id != "outside_lower"}
|
||||||
|
|
||||||
|
|
||||||
def test_expanded_corpus_uses_physical_dimensions_and_has_reference_coverage() -> None:
|
def test_expanded_corpus_uses_physical_dimensions_and_has_reference_coverage() -> None:
|
||||||
corpus_names = {case.name for case in CORPUS_CASES}
|
corpus_names = {case.name for case in CORPUS_CASES}
|
||||||
assert len(corpus_names) == len(CORPUS_CASES)
|
assert len(corpus_names) == len(CORPUS_CASES)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue