Check actual terminal faces in search and seed replay
Keep nominal terminal checks for standard geometry. Defer to materialized geometry when a custom outline can reach a terminal and report blocked terminals consistently in iteration callbacks.
This commit is contained in:
parent
23d0a140c1
commit
8a97c1e64b
3 changed files with 73 additions and 5 deletions
|
|
@ -91,6 +91,8 @@ A custom S-bend outline uses local coordinates. Its input face is centered at `(
|
|||
|
||||
When migrating a half-arc template, supply the complete outline through `sbend_outlines` and keep `bend_physical_geometry` for custom 90-degree bends. Both terminal faces of each custom polygon must be centered on their ports and match the routed width. A custom 90-degree template is shared across nets, so it can only be used by nets whose width matches its faces. Replay an `SBendSeed` with the same outlines and bend settings to recover its physical geometry.
|
||||
|
||||
When a net can use a custom outline, search checks the geometry of each candidate move at its terminals. Seed replay verifies the materialized faces.
|
||||
|
||||
Circular bends approximate the outer edge within a sagitta of 0.01 layout units. The router also sizes the subdivision for the outer edge of a clearance-expanded circular proxy. A generated circular arc that needs more than 250,000 subdivisions is rejected before sampling. Use coarser layout units if the required radii exceed this limit.
|
||||
|
||||
### ObjectiveWeights
|
||||
|
|
|
|||
|
|
@ -335,8 +335,20 @@ class PathFinder:
|
|||
self._materialize_problem_initial_paths(state)
|
||||
if congestion.max_iterations:
|
||||
world = self.context.cost_evaluator.collision_engine
|
||||
search = self.context.options.search
|
||||
_, physical_bend = resolve_bend_geometry(search)
|
||||
custom_bend_radius = max(search.bend_radii, default=0.0) if physical_bend != "arc" else 0.0
|
||||
initial_paths = state.initial_paths or {}
|
||||
for net_id, net in net_specs.items():
|
||||
# Custom moves can have faces offset from the nominal port plane.
|
||||
if search.node_limit and (custom_bend_radius >= net.width / 2 or search.has_applicable_sbend_outline((net.width,))):
|
||||
continue
|
||||
path = initial_paths.get(net_id)
|
||||
materialized_ports = (path[0].start_port, path[-1].end_port) if path else ()
|
||||
for name, port in (("start", net.start), ("target", net.target)):
|
||||
# Verification checks the physical faces of a materialized seed.
|
||||
if port in materialized_ports:
|
||||
continue
|
||||
issue = world.terminal_issue(port, net.width)
|
||||
if issue is not None:
|
||||
state.terminal_errors[net_id] = f"{name} port {port.as_tuple()} {issue}"
|
||||
|
|
@ -893,6 +905,7 @@ class PathFinder:
|
|||
self.context.cost_evaluator.collision_engine.remove_path(net_id)
|
||||
guidance_seed_present = False
|
||||
|
||||
terminal_error = state.terminal_errors.get(net_id)
|
||||
initial_path = state.initial_paths.get(net_id) if state.initial_paths else None
|
||||
initial_arrives = bool(initial_path and initial_path[-1].end_port == net.target)
|
||||
seed_intrinsic_ok = (
|
||||
|
|
@ -904,7 +917,7 @@ class PathFinder:
|
|||
).report.intrinsic_collision_count
|
||||
)
|
||||
) if iteration == 0 else False
|
||||
if net_id in state.terminal_errors:
|
||||
if terminal_error:
|
||||
path: Sequence[ComponentResult] | None = initial_path
|
||||
elif iteration == 0 and initial_path is not None and (seed_intrinsic_ok or search.node_limit <= 0):
|
||||
self.metrics.total_warm_start_paths_used += 1
|
||||
|
|
@ -971,12 +984,11 @@ class PathFinder:
|
|||
if not path:
|
||||
if can_reserve(incumbent_fallback):
|
||||
return self._restore_incumbent_fallback(net_id, incumbent_fallback, guidance_seed_present)
|
||||
return RoutingResult(net_id=net_id, path=(), reached_target=False), guidance_seed_present
|
||||
return RoutingResult(net_id=net_id, path=(), report=RoutingReport(terminal_error=terminal_error)), guidance_seed_present
|
||||
|
||||
reached_target = path[-1].end_port == net.target
|
||||
if not reached_target and can_reserve(incumbent_fallback):
|
||||
return self._restore_incumbent_fallback(net_id, incumbent_fallback, guidance_seed_present)
|
||||
report = None
|
||||
if reached_target:
|
||||
self.metrics.total_nets_reached_target += 1
|
||||
report = self.context.cost_evaluator.collision_engine.verify_path_details(net_id, path, include_invalid_dynamic=False).report
|
||||
|
|
@ -984,13 +996,15 @@ class PathFinder:
|
|||
self._install_path(net_id, path)
|
||||
if report.self_collision_count > 0:
|
||||
state.needs_self_collision_check.add(net_id)
|
||||
else:
|
||||
report = RoutingReport(terminal_error=terminal_error)
|
||||
|
||||
return (
|
||||
RoutingResult(
|
||||
net_id=net_id,
|
||||
path=tuple(path),
|
||||
reached_target=reached_target,
|
||||
report=RoutingReport() if report is None else report,
|
||||
report=report,
|
||||
),
|
||||
guidance_seed_present,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ from inire import (
|
|||
TopologyOptions,
|
||||
route,
|
||||
)
|
||||
from inire.geometry.components import SBend, Straight
|
||||
from inire.geometry.components import Bend90, SBend, Straight
|
||||
from inire.geometry.collision import RoutingWorld
|
||||
from inire.results import RoutingReport, RoutingResult
|
||||
from inire.router._astar_types import AStarContext
|
||||
|
|
@ -371,6 +371,58 @@ def test_custom_sbend_matches_float_width_in_search_and_replay(width, expected_p
|
|||
assert active.locked_geometry == replay.locked_geometry
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mode", ["off", "automatic"])
|
||||
@pytest.mark.parametrize("terminal", ["start", "target"])
|
||||
def test_search_and_seed_replay_check_materialized_sbend_faces(mode, terminal) -> None:
|
||||
clearance = 0.1
|
||||
# The nominal face fails clearance. The supplied outline is within the face tolerance.
|
||||
if terminal == "start":
|
||||
face_x, offset = 0, 0.8e-6
|
||||
keepout = box(0, 7, 10 - clearance + 0.4e-6, 13)
|
||||
else:
|
||||
face_x, offset = 80, -0.8e-6
|
||||
keepout = box(90 + clearance - 0.4e-6, 47, 100, 53)
|
||||
polygon = Polygon([(x + offset if x == face_x else x, y) for x, y in _sbend_strip(40).exterior.coords])
|
||||
outline = SBendOutline(40, 50, 2, polygon)
|
||||
net = NetSpec("shift", Port(10, 10, 0), Port(90, 50, 0), width=2)
|
||||
problem = RoutingProblem(
|
||||
(0, 0, 100, 100), (net,), (keepout,), initial_paths={net.net_id: PathSeed((SBendSeed(40, 50),))}, clearance=clearance,
|
||||
)
|
||||
options = RoutingOptions(
|
||||
search=SearchOptions(node_limit=0, bend_radii=(), sbend_radii=(50,), sbend_outlines=(outline,)),
|
||||
topology=TopologyOptions(mode=mode),
|
||||
)
|
||||
callbacks = []
|
||||
|
||||
run = route(problem, options=options, iteration_callback=lambda _, results: callbacks.append(results[net.net_id]))
|
||||
result = run.results_by_net[net.net_id]
|
||||
|
||||
assert result.locked_geometry[0].distance(keepout) > clearance
|
||||
assert result.is_valid
|
||||
assert result.report.terminal_error is None
|
||||
assert len(callbacks) == 1
|
||||
assert callbacks[0].report == result.report
|
||||
active_options = replace(options, search=replace(options.search, node_limit=30))
|
||||
active = route(replace(problem, initial_paths={}), options=active_options).results_by_net[net.net_id]
|
||||
assert active.is_valid
|
||||
assert active.as_seed() == result.as_seed()
|
||||
assert active.locked_geometry == result.locked_geometry
|
||||
|
||||
|
||||
def test_search_checks_materialized_quarter_turn_face() -> None:
|
||||
bend = Bend90.generate(Port(0, 0, 0), 20, 2, "CCW")
|
||||
polygon = Polygon([(0.8e-6 if x == 0 else x, y - 20) for x, y in bend.physical_geometry[0].exterior.coords])
|
||||
net = NetSpec("corner", Port(10, 10, 0), Port(30, 30, 90))
|
||||
keepout = box(0, 7, 9.9000004, 13)
|
||||
problem = RoutingProblem((0, 0, 50, 50), (net,), (keepout,), clearance=0.1)
|
||||
options = RoutingOptions(search=SearchOptions(node_limit=30, bend_radii=(20,), sbend_radii=(), bend_physical_geometry=polygon))
|
||||
|
||||
result = route(problem, options=options).results_by_net[net.net_id]
|
||||
|
||||
assert result.is_valid
|
||||
assert result.as_seed() == PathSeed((Bend90Seed(20, "CCW"),))
|
||||
|
||||
|
||||
def test_custom_sbend_outline_rejects_duplicate_and_ambiguous_widths() -> None:
|
||||
outline = SBendOutline(40, 50, 0.3, _sbend_strip(40, half_width=0.15))
|
||||
with pytest.raises(ValueError, match="Duplicate S-bend outline"):
|
||||
|
|
|
|||
Loading…
Reference in a new issue