Keep partial routes diagnostic and recover width-specific corridors

This commit is contained in:
Jan Petykiewicz 2026-11-27 22:52:06 -08:00
commit b3580a9c07

View file

@ -360,8 +360,13 @@ class RoutingWorld:
bounds: tuple[float, float, float, float],
net_id: str,
) -> bool:
gx_min, gy_min, gx_max, gy_max = grid_cell_span(bounds, self.grid_cell_size)
cells = self._dynamic_paths.grid_net_obj_ids
span = grid_cell_span(bounds, self.grid_cell_size)
dynamic_paths = self._dynamic_paths
if dynamic_paths.uses_tree_for_span(span):
span_bounds = _span_to_bounds(*span, self.grid_cell_size)
return next(dynamic_paths.tree_candidates(net_id, span_bounds), None) is not None
gx_min, gy_min, gx_max, gy_max = span
cells = dynamic_paths.grid_net_obj_ids
if gx_min == gx_max and gy_min == gy_max:
members = cells.get((gx_min, gy_min))
@ -453,8 +458,8 @@ class RoutingWorld:
net_id: str,
broad_phase_cache: dict[tuple[str, int, int, int, int], dict[str, tuple[int, ...]]] | None,
) -> dict[str, tuple[int, ...]]:
gx_min, gy_min, gx_max, gy_max = grid_cell_span(bounds, self.grid_cell_size)
cache_key = (net_id, gx_min, gy_min, gx_max, gy_max)
span = grid_cell_span(bounds, self.grid_cell_size)
cache_key = (net_id, *span)
if broad_phase_cache is not None and cache_key in broad_phase_cache:
if self.metrics is not None:
self.metrics.total_congestion_grid_span_cache_hits += 1
@ -465,12 +470,18 @@ class RoutingWorld:
dynamic_paths = self._dynamic_paths
candidates_by_net: dict[str, set[int]] = {}
for gx in range(gx_min, gx_max + 1):
for gy in range(gy_min, gy_max + 1):
for other_net_id, obj_ids in dynamic_paths.grid_net_obj_ids.get((gx, gy), {}).items():
if other_net_id == net_id:
continue
candidates_by_net.setdefault(other_net_id, set()).update(obj_ids)
if dynamic_paths.uses_tree_for_span(span):
span_bounds = _span_to_bounds(*span, self.grid_cell_size)
for other_net_id, obj_id in dynamic_paths.tree_candidates(net_id, span_bounds):
candidates_by_net.setdefault(other_net_id, set()).add(obj_id)
else:
gx_min, gy_min, gx_max, gy_max = span
for gx in range(gx_min, gx_max + 1):
for gy in range(gy_min, gy_max + 1):
for other_net_id, obj_ids in dynamic_paths.grid_net_obj_ids.get((gx, gy), {}).items():
if other_net_id == net_id:
continue
candidates_by_net.setdefault(other_net_id, set()).update(obj_ids)
frozen = {
other_net_id: tuple(sorted(obj_ids))
@ -486,8 +497,8 @@ class RoutingWorld:
net_id: str,
grid_net_cache: dict[tuple[str, int, int, int, int], tuple[str, ...]] | None,
) -> tuple[str, ...]:
gx_min, gy_min, gx_max, gy_max = grid_cell_span(bounds, self.grid_cell_size)
cache_key = (net_id, gx_min, gy_min, gx_max, gy_max)
span = grid_cell_span(bounds, self.grid_cell_size)
cache_key = (net_id, *span)
if grid_net_cache is not None and cache_key in grid_net_cache:
if self.metrics is not None:
self.metrics.total_congestion_grid_net_cache_hits += 1
@ -497,12 +508,17 @@ class RoutingWorld:
self.metrics.total_congestion_grid_net_cache_misses += 1
dynamic_paths = self._dynamic_paths
candidate_net_ids: set[str] = set()
for gx in range(gx_min, gx_max + 1):
for gy in range(gy_min, gy_max + 1):
for other_net_id in dynamic_paths.grid_net_obj_ids.get((gx, gy), {}):
if other_net_id != net_id:
candidate_net_ids.add(other_net_id)
if dynamic_paths.uses_tree_for_span(span):
span_bounds = _span_to_bounds(*span, self.grid_cell_size)
candidate_net_ids = {other_net_id for other_net_id, _ in dynamic_paths.tree_candidates(net_id, span_bounds)}
else:
gx_min, gy_min, gx_max, gy_max = span
candidate_net_ids = set()
for gx in range(gx_min, gx_max + 1):
for gy in range(gy_min, gy_max + 1):
for other_net_id in dynamic_paths.grid_net_obj_ids.get((gx, gy), {}):
if other_net_id != net_id:
candidate_net_ids.add(other_net_id)
frozen = tuple(sorted(candidate_net_ids))
if grid_net_cache is not None: