Enforce net clearance when packing route candidates

This commit is contained in:
Jan Petykiewicz 2026-11-30 09:25:27 -08:00
commit 26b12e33a2
3 changed files with 22 additions and 6 deletions

View file

@ -12,8 +12,7 @@ from typing import TYPE_CHECKING
import shapely import shapely
from shapely.geometry import box from shapely.geometry import box
from inire.constants import TOLERANCE_LINEAR from inire.geometry.collision import RoutingWorld, _violates_net_clearance
from inire.geometry.collision import RoutingWorld
from inire.model import FixedRoute, resolve_bend_geometry from inire.model import FixedRoute, resolve_bend_geometry
from inire.results import AutomaticRoutingReport, RoutingStage, RoutingTiming, _planner_for_mode from inire.results import AutomaticRoutingReport, RoutingStage, RoutingTiming, _planner_for_mode
from inire.router._bundle import ordered_bundle_terminal_headings, plan_ordered_bundle from inire.router._bundle import ordered_bundle_terminal_headings, plan_ordered_bundle
@ -335,7 +334,7 @@ class _AutomaticRun:
pairs = chain(pairs, reserved_pairs) pairs = chain(pairs, reserved_pairs)
for (first_seed, first_shape), (second_seed, second_shape) in pairs: for (first_seed, first_shape), (second_seed, second_shape) in pairs:
if first_shape.distance(second_shape) < problem.clearance - TOLERANCE_LINEAR: if _violates_net_clearance(first_shape, second_shape, problem.clearance):
continue continue
plan = replace(problem, initial_paths={first.net_id: first_seed, second.net_id: second_seed}) plan = replace(problem, initial_paths={first.net_id: first_seed, second.net_id: second_seed})
trial = self._verify(plan, "paired-perimeter") trial = self._verify(plan, "paired-perimeter")

View file

@ -9,8 +9,7 @@ from typing import TYPE_CHECKING
from shapely import union_all from shapely import union_all
from shapely.geometry import box from shapely.geometry import box
from inire.constants import TOLERANCE_LINEAR from inire.geometry.collision import RoutingWorld, _violates_net_clearance
from inire.geometry.collision import RoutingWorld
from inire.geometry.primitives import port_local_coordinates from inire.geometry.primitives import port_local_coordinates
from inire.geometry.sbend import exact_sbend_spans, sbend_grid_span from inire.geometry.sbend import exact_sbend_spans, sbend_grid_span
from inire.model import resolve_bend_geometry from inire.model import resolve_bend_geometry
@ -119,7 +118,7 @@ def _pack_routes(
if remaining <= 0: if remaining <= 0:
return None return None
remaining -= 1 remaining -= 1
if any(footprint.distance(other) < clearance - TOLERANCE_LINEAR for _, other in chosen.values()): if any(_violates_net_clearance(footprint, other, clearance) for _, other in chosen.values()):
continue continue
chosen[net_id] = (seed, footprint) chosen[net_id] = (seed, footprint)
index += 1 index += 1

View file

@ -19,3 +19,21 @@ def test_local_sbend_planner_uses_the_snapped_span() -> None:
assert run.metrics.nodes_expanded == 0 assert run.metrics.nodes_expanded == 0
for net in (east, north): for net in (east, north):
assert run.results_by_net[net.net_id].as_seed().segments == (SBendSeed(5, 10),) assert run.results_by_net[net.net_id].as_seed().segments == (SBendSeed(5, 10),)
def test_local_sbend_packing_skips_intersecting_candidates_at_zero_clearance() -> None:
east = NetSpec("east", Port(10, 10, 0), Port(50, 18, 0))
north = NetSpec("north", Port(26, 12, 90), Port(18, 42, 90))
line = NetSpec("line", Port(10, 65, 0), Port(55, 65, 0))
problem = RoutingProblem((0, 0, 100, 100), (east, north, line), clearance=0)
options = RoutingOptions(
search=SearchOptions(node_limit=1, min_straight_length=0, bend_radii=(), sbend_radii=(10,), sbend_offsets=(8,)),
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
refinement=RefinementOptions(enabled=False),
)
run = route(problem, options=options)
assert all(result.is_valid for result in run.results_by_net.values())
assert run.automatic.selected_planner == "local-sbend"
assert run.metrics.nodes_expanded == 0