Bound implicit exact S-bend offset discovery
This commit is contained in:
parent
653edda512
commit
13b2d8b7de
5 changed files with 52 additions and 4 deletions
|
|
@ -99,6 +99,8 @@ A custom S-bend outline uses local coordinates. Its input face is centered at `(
|
|||
|
||||
Match custom outline faces to their declared ports and width. `SBendOutline` warns about a mismatch at construction. For a custom 90-degree outline used in a result, `route()` warns once per radius and net width. Replay an `SBendSeed` with the same outlines and bend settings.
|
||||
|
||||
Constructive planners that need exact integer S-bend spans check up to 65,536 implicit offsets. When that budget would be exceeded, automatic routing tries other candidates. In explicit bundle mode, supply `sbend_offsets` to check a specific list of offsets.
|
||||
|
||||
Search and replay use placed custom outlines for board containment. When a declared port lies outside the board, proximity scoring samples the nearest point on the placed outline. Final verification checks the placed polygons against the board, keepouts, and other routes.
|
||||
|
||||
For a complete custom S-bend outline, or a custom 90-degree bend with a custom polygon proxy, the radius determines the declared snapped endpoints. Use the supplied polygons to represent the process geometry.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@ from math import ceil, isfinite, isqrt, sqrt
|
|||
|
||||
from inire.constants import TOLERANCE_LINEAR
|
||||
|
||||
_MAX_IMPLICIT_OFFSET_CHECKS = 65_536
|
||||
|
||||
|
||||
class ExactSBendScanLimitError(ValueError):
|
||||
"""Implicit exact-span discovery exceeds the planner's offset budget."""
|
||||
|
||||
|
||||
def sbend_span(offset: float, radius: float) -> float:
|
||||
offset = abs(offset)
|
||||
|
|
@ -29,6 +35,11 @@ def exact_sbend_spans(
|
|||
offset_limit = diameter - (isqrt(remaining - 1) + 1 if remaining > 0 else 1)
|
||||
if max_offset is not None:
|
||||
offset_limit = min(offset_limit, max_offset)
|
||||
if offsets is None and offset_limit > _MAX_IMPLICIT_OFFSET_CHECKS:
|
||||
raise ExactSBendScanLimitError(
|
||||
f"Implicit exact S-bend discovery would check {offset_limit:,} offsets (limit {_MAX_IMPLICIT_OFFSET_CHECKS:,}). "
|
||||
"Configure sbend_offsets to supply an explicit list."
|
||||
)
|
||||
candidates = range(1, offset_limit + 1) if offsets is None else sorted({int(abs(offset)) for offset in offsets})
|
||||
spans = {}
|
||||
for offset in candidates:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ from typing import TYPE_CHECKING
|
|||
from shapely.geometry import LineString
|
||||
|
||||
from inire.geometry.intervals import Gap, open_intervals
|
||||
from inire.geometry.sbend import exact_sbend_spans
|
||||
from inire.geometry.sbend import ExactSBendScanLimitError, exact_sbend_spans
|
||||
from inire.model import resolve_bend_geometry
|
||||
from inire.router._waypoints import compile_waypoints
|
||||
from inire.seeds import PathSeed, SBendSeed, StraightSeed
|
||||
|
|
@ -569,7 +569,10 @@ def column_seed_candidates(
|
|||
radius = int(bend)
|
||||
max_span = max(before - after - 4 for (_, after), (before, _) in pairwise(layout.spans))
|
||||
max_offset = floor(problem.bounds[3]) - ceil(problem.bounds[1])
|
||||
try:
|
||||
spans = exact_sbend_spans(radius, max_span=max_span, max_offset=max_offset, offsets=search.sbend_offsets)
|
||||
except ExactSBendScanLimitError:
|
||||
return
|
||||
if not spans:
|
||||
return
|
||||
allowed_offsets = None if search.sbend_offsets is None else frozenset(search.sbend_offsets)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ from shapely.geometry import box
|
|||
|
||||
from inire.geometry.collision import RoutingWorld, _violates_net_clearance
|
||||
from inire.geometry.primitives import port_local_coordinates
|
||||
from inire.geometry.sbend import exact_sbend_spans, sbend_grid_span
|
||||
from inire.geometry.sbend import ExactSBendScanLimitError, exact_sbend_spans, sbend_grid_span
|
||||
from inire.model import resolve_bend_geometry
|
||||
from inire.results import RoutingResult
|
||||
from inire.router._seed_materialization import materialize_path_seed
|
||||
|
|
@ -80,7 +80,10 @@ def _candidate_jogs(
|
|||
continue
|
||||
# Move the middle of the jog between two independently positioned
|
||||
# turn lanes. The S-bend stays away from the terminal access cutouts.
|
||||
try:
|
||||
spans = exact_sbend_spans(radius, max_span=int(reach), max_offset=max_offset, offsets=search.sbend_offsets)
|
||||
except ExactSBendScanLimitError:
|
||||
continue
|
||||
for offset, span in reversed(tuple(spans.items())):
|
||||
available = reach - span
|
||||
for before in _shift_positions(problem, start.y, direction, radius, span, available):
|
||||
|
|
|
|||
|
|
@ -131,6 +131,35 @@ def test_exact_sbend_spans_filter_by_window_and_configured_offsets() -> None:
|
|||
assert exact_sbend_spans(25, max_span=40, max_offset=10, offsets=(-20, 10, 40, 0)) == {10: 30}
|
||||
|
||||
|
||||
def test_exact_sbend_scan_budget_applies_only_to_implicit_offsets(monkeypatch) -> None:
|
||||
monkeypatch.setattr(sbend, "_MAX_IMPLICIT_OFFSET_CHECKS", 10)
|
||||
|
||||
with pytest.raises(sbend.ExactSBendScanLimitError, match="would check 20 offsets"):
|
||||
exact_sbend_spans(25, max_span=40)
|
||||
|
||||
assert exact_sbend_spans(25, max_span=40, max_offset=10) == {2: 14, 10: 30}
|
||||
assert exact_sbend_spans(25, max_span=40, offsets=(-20,)) == {20: 40}
|
||||
|
||||
|
||||
def test_automatic_routes_wide_tall_boards_without_a_large_implicit_scan(monkeypatch) -> None:
|
||||
def unexpected_scan(_value):
|
||||
raise AssertionError("The implicit offset scan exceeds the work budget")
|
||||
|
||||
monkeypatch.setattr(sbend, "isqrt", unexpected_scan)
|
||||
nets = tuple(NetSpec(str(y), Port(5, y, 0), Port(399_999_990, y, 0)) for y in (30, 60, 90))
|
||||
problem = RoutingProblem((0, 0, 400_000_000, 50_000_000), nets, (box(190_000_000, 0, 190_000_020, 10),), clearance=0)
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(node_limit=1, bend_radii=(), sbend_radii=(100_000_000,)),
|
||||
congestion=CongestionOptions(max_iterations=1, warm_start_enabled=False),
|
||||
refinement=RefinementOptions(enabled=False),
|
||||
)
|
||||
|
||||
run = route(problem, options=options)
|
||||
|
||||
assert all(run.results_by_net[net.net_id].is_valid for net in nets)
|
||||
assert run.metrics.nodes_expanded == 0
|
||||
|
||||
|
||||
def test_wide_column_windows_only_scan_offsets_within_the_board_height(monkeypatch) -> None:
|
||||
square_root = sbend.isqrt
|
||||
scans = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue