Keep unrelated paths installed during pair repair
This commit is contained in:
parent
e9ed72d0dc
commit
0319274163
2 changed files with 17 additions and 13 deletions
|
|
@ -356,10 +356,13 @@ class PathFinder:
|
|||
)
|
||||
return initial_paths
|
||||
|
||||
def _replace_installed_paths(self, state: _RoutingState, results: dict[str, RoutingResult]) -> None:
|
||||
for net_id in state.ordered_net_ids:
|
||||
def _replace_installed_paths(
|
||||
self, state: _RoutingState, results: dict[str, RoutingResult], *, net_ids: Sequence[str] | None = None
|
||||
) -> None:
|
||||
ordered_net_ids = state.ordered_net_ids if net_ids is None else net_ids
|
||||
for net_id in ordered_net_ids:
|
||||
self.context.cost_evaluator.collision_engine.remove_path(net_id)
|
||||
for net_id in state.ordered_net_ids:
|
||||
for net_id in ordered_net_ids:
|
||||
result = results.get(net_id)
|
||||
if result and result.path and (result.reached_target or not state.corridors):
|
||||
self._install_path(net_id, result.path)
|
||||
|
|
@ -758,11 +761,13 @@ class PathFinder:
|
|||
def _apply_pair_local_candidate(
|
||||
self,
|
||||
state: _RoutingState,
|
||||
candidate_results: dict[str, RoutingResult],
|
||||
incumbent_results: dict[str, RoutingResult],
|
||||
replacements: dict[str, RoutingResult],
|
||||
incumbent_review: _IterationReview,
|
||||
) -> tuple[bool, _IterationReview]:
|
||||
self._replace_installed_paths(state, candidate_results)
|
||||
incumbent_results = state.results
|
||||
candidate_results = {**incumbent_results, **replacements}
|
||||
changed_net_ids = [net_id for net_id in state.ordered_net_ids if net_id in replacements]
|
||||
self._replace_installed_paths(state, candidate_results, net_ids=changed_net_ids)
|
||||
candidate_results, _, candidate_review = self._analyze_results(
|
||||
state.ordered_net_ids,
|
||||
candidate_results,
|
||||
|
|
@ -779,7 +784,7 @@ class PathFinder:
|
|||
state.results = candidate_results
|
||||
return True, candidate_review
|
||||
|
||||
self._replace_installed_paths(state, incumbent_results)
|
||||
self._replace_installed_paths(state, incumbent_results, net_ids=changed_net_ids)
|
||||
return False, incumbent_review
|
||||
|
||||
def _run_pair_local_target(
|
||||
|
|
@ -807,8 +812,7 @@ class PathFinder:
|
|||
self.metrics.total_pair_local_search_nodes_expanded += nodes_expanded
|
||||
accepted, next_review = self._apply_pair_local_candidate(
|
||||
state,
|
||||
{**incumbent_results, **replacements},
|
||||
incumbent_results,
|
||||
replacements,
|
||||
review,
|
||||
)
|
||||
if accepted:
|
||||
|
|
|
|||
|
|
@ -816,7 +816,7 @@ def test_pair_repair_limits_disjoint_targets_in_routing_order(monkeypatch: pytes
|
|||
def test_rejected_pair_keeps_original_index_for_reverse_attempt(monkeypatch: pytest.MonkeyPatch, candidate_reaches_live_check: bool) -> None:
|
||||
problem = RoutingProblem(
|
||||
bounds=(0, 0, 100, 100),
|
||||
nets=(NetSpec("a", Port(10, 20, 0), Port(90, 20, 0)), NetSpec("b", Port(10, 40, 0), Port(90, 40, 0))),
|
||||
nets=tuple(NetSpec(net_id, Port(10, y, 0), Port(90, y, 0)) for net_id, y in (("a", 20), ("b", 40), ("c", 60))),
|
||||
)
|
||||
options = RoutingOptions(congestion=CongestionOptions(warm_start_enabled=False), topology=TopologyOptions(mode="off"))
|
||||
world = RoutingWorld(clearance=problem.clearance)
|
||||
|
|
@ -828,14 +828,14 @@ def test_rejected_pair_keeps_original_index_for_reverse_attempt(monkeypatch: pyt
|
|||
state.results[net.net_id] = RoutingResult(net.net_id, path, reached_target=True, report=world.verify_path_report(net.net_id, path))
|
||||
initial_bounds = sorted(world.iter_dynamic_path_bounds(problem.bounds))
|
||||
incumbent = dict(state.results)
|
||||
review = _IterationReview(set(), set(), {"a", "b"}, 0)
|
||||
review = _IterationReview(set(), set(), set(incumbent), 0)
|
||||
attempted = []
|
||||
|
||||
def search(_context, _ordered, _results, pair_order, **_kwargs):
|
||||
attempted.append(pair_order)
|
||||
assert sorted(world.iter_dynamic_path_bounds(problem.bounds)) == initial_bounds
|
||||
if candidate_reaches_live_check and pair_order == ("a", "b"):
|
||||
return {"a": RoutingResult("a", incumbent["b"].path, reached_target=True)}, 0
|
||||
return {"a": RoutingResult("a", incumbent["b"].path, reached_target=True), "b": incumbent["b"]}, 0
|
||||
return None
|
||||
|
||||
monkeypatch.setattr(router_module, "search_pair_candidate", search)
|
||||
|
|
@ -846,7 +846,7 @@ def test_rejected_pair_keeps_original_index_for_reverse_attempt(monkeypatch: pyt
|
|||
assert sorted(world.iter_dynamic_path_bounds(problem.bounds)) == initial_bounds
|
||||
assert all(world.verify_path_report(net_id, result.path) == result.report for net_id, result in incumbent.items())
|
||||
metrics = finder.metrics.snapshot()
|
||||
assert metrics.dynamic_path_objects_added == 2 + 4 * candidate_reaches_live_check
|
||||
assert metrics.dynamic_path_objects_added == 3 + 4 * candidate_reaches_live_check
|
||||
assert metrics.dynamic_path_objects_removed == 4 * candidate_reaches_live_check
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue