diff --git a/inire/geometry/collision.py b/inire/geometry/collision.py index 0c28636..b888ca5 100644 --- a/inire/geometry/collision.py +++ b/inire/geometry/collision.py @@ -216,7 +216,7 @@ class RoutingWorld: return "face enters a keepout" return None - def add_path( + def add_path_geometry( self, net_id: str, geometry: Sequence[Polygon], @@ -225,7 +225,8 @@ class RoutingWorld: *, physical_geometry: Sequence[tuple[int, Polygon]] | None = None, ) -> None: - self._dynamic_paths.add_path( + """Add prepared path polygons and their component indexes.""" + self._dynamic_paths.add_path_geometry( net_id, geometry, dilated_geometry=dilated_geometry, @@ -233,7 +234,8 @@ class RoutingWorld: physical_geometry=physical_geometry, ) - def install_path(self, net_id: str, path: Sequence[ComponentResult]) -> None: + def add_route(self, net_id: str, path: Sequence[ComponentResult]) -> None: + """Validate and index the polygons of a route's components.""" if any(not component.physical_checks[0] for component in path): return proxies: list[Polygon] = [] @@ -243,7 +245,7 @@ class RoutingWorld: proxies.extend(component.collision_geometry) dilated_proxies.extend(component.dilated_collision_geometry) physical_geometry.extend((component_index, polygon) for polygon in component.physical_geometry) - self.add_path(net_id, proxies, dilated_proxies, physical_geometry=physical_geometry) + self.add_path_geometry(net_id, proxies, dilated_proxies, physical_geometry=physical_geometry) def remove_path(self, net_id: str) -> None: self._dynamic_paths.remove_path(net_id) diff --git a/inire/geometry/dynamic_path_index.py b/inire/geometry/dynamic_path_index.py index 2faee6b..52618de 100644 --- a/inire/geometry/dynamic_path_index.py +++ b/inire/geometry/dynamic_path_index.py @@ -135,7 +135,7 @@ class DynamicPathIndex: if other_net_id != net_id: yield other_net_id, obj_id - def add_path( + def add_path_geometry( self, net_id: str, geometry: Sequence[Polygon], diff --git a/inire/router/_router.py b/inire/router/_router.py index 3915af9..4a993b5 100644 --- a/inire/router/_router.py +++ b/inire/router/_router.py @@ -64,7 +64,7 @@ class _RoutingState: initial_paths: dict[str, tuple[ComponentResult, ...]] | None accumulated_expanded_nodes: list[tuple[int, int, int]] best_results: dict[str, RoutingResult] - best_is_installed: bool + best_is_indexed: bool best_review: _IterationReview | None last_conflict_edge_count: int repeated_conflict_count: int @@ -154,11 +154,11 @@ class PathFinder: guidance_seed_present: bool, ) -> tuple[RoutingResult, bool]: self.metrics.total_late_phase_capped_fallbacks += 1 - self._install_path(net_id, result.path) + self._add_route(net_id, result.path) return result, guidance_seed_present - def _install_path(self, net_id: str, path: Sequence[ComponentResult]) -> None: - self.context.cost_evaluator.collision_engine.install_path(net_id, path) + def _add_route(self, net_id: str, path: Sequence[ComponentResult]) -> None: + self.context.cost_evaluator.collision_engine.add_route(net_id, path) @contextmanager def _temporary_path_reservations(self) -> Iterator[Callable[[str, Sequence[ComponentResult]], None]]: @@ -325,7 +325,7 @@ class PathFinder: initial_paths=None, accumulated_expanded_nodes=[], best_results={}, - best_is_installed=False, + best_is_indexed=False, best_review=None, last_conflict_edge_count=0, repeated_conflict_count=0, @@ -371,7 +371,7 @@ class PathFinder: continue report = world.verify_path_report(net_id, path) if report.is_valid: - self._install_path(net_id, path) + self._add_route(net_id, path) state.results[net_id] = RoutingResult(net_id, path, reached_target=True, report=report) return state @@ -412,7 +412,7 @@ class PathFinder: initial_paths[net_id] = path state.initial_paths = initial_paths or None - def _replace_installed_paths( + def _replace_indexed_routes( 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 @@ -421,7 +421,7 @@ class PathFinder: for net_id in ordered_net_ids: result = results.get(net_id) if can_reserve(result): - self._install_path(net_id, result.path) + self._add_route(net_id, result.path) def _review_restored_best(self, state: _RoutingState) -> _IterationReview: diagnostics = self.context.options.diagnostics @@ -460,7 +460,7 @@ class PathFinder: if not state.best_results: return state.results = dict(state.best_results) - self._replace_installed_paths(state, state.results) + self._replace_indexed_routes(state, state.results) def _capture_conflict_trace_entry( self, @@ -550,7 +550,7 @@ class PathFinder: yield scratch_metrics finally: if path: - self._install_path(net_id, path) + self._add_route(net_id, path) finally: context.metrics, world.metrics = context_metrics, world_metrics if danger_map is not None: @@ -818,7 +818,7 @@ class PathFinder: 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) + self._replace_indexed_routes(state, candidate_results, net_ids=changed_net_ids) candidate_results, _, candidate_review = self._analyze_results( state.ordered_net_ids, candidate_results, @@ -835,7 +835,7 @@ class PathFinder: state.results = candidate_results return True, candidate_review - self._replace_installed_paths(state, incumbent_results, net_ids=changed_net_ids) + self._replace_indexed_routes(state, incumbent_results, net_ids=changed_net_ids) return False, incumbent_review def _run_pair_local_target( @@ -993,7 +993,7 @@ class PathFinder: 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 if not report.intrinsic_collision_count: - self._install_path(net_id, path) + self._add_route(net_id, path) if report.self_collision_count > 0: state.needs_self_collision_check.add(net_id) else: @@ -1129,7 +1129,7 @@ class PathFinder: if review is None: return True improved = self._update_best_iteration(state, review) - state.best_is_installed = improved + state.best_is_indexed = improved if state.timed_out: return True if not any( @@ -1175,7 +1175,7 @@ class PathFinder: self.metrics.total_refine_path_calls += 1 self.context.cost_evaluator.collision_engine.remove_path(net_id) refined_path = self.refiner.refine_path(net_id, net.start, net.width, result.path) - self._install_path(net_id, refined_path) + self._add_route(net_id, refined_path) # Defer full verification until _verify_results() so we do not # verify the same refined path twice in one route_all() call. state.results[net_id] = RoutingResult( @@ -1253,7 +1253,7 @@ class PathFinder: timed_out = self._run_iterations(state, iteration_callback) self.accumulated_expanded_nodes = list(state.accumulated_expanded_nodes) # A partial iteration can leave the index out of sync with the saved results. - best_is_live = not timed_out and state.best_is_installed + best_is_live = not timed_out and state.best_is_indexed if not best_is_live: self._restore_best_iteration(state) diff --git a/inire/router/_routing_policy.py b/inire/router/_routing_policy.py index 2d47f9c..a234a7b 100644 --- a/inire/router/_routing_policy.py +++ b/inire/router/_routing_policy.py @@ -99,7 +99,7 @@ def _direct_paths( report = world.verify_path_report(net.net_id, path) if report.is_valid: paths[net.net_id] = RoutingResult(net.net_id, path, reached_target=True, report=report, effective_net=net) - world.install_path(net.net_id, path) + world.add_route(net.net_id, path) for net in ordered: if net.net_id in problem.initial_paths: continue @@ -110,7 +110,7 @@ def _direct_paths( report = world.verify_path_report(net.net_id, (component,)) if report.is_valid: paths[net.net_id] = RoutingResult(net.net_id, (component,), reached_target=True, report=report, effective_net=net) - world.install_path(net.net_id, (component,)) + world.add_route(net.net_id, (component,)) return paths diff --git a/inire/tests/test_api.py b/inire/tests/test_api.py index b1e6f1d..baed2f5 100644 --- a/inire/tests/test_api.py +++ b/inire/tests/test_api.py @@ -1880,12 +1880,12 @@ def test_route_net_once_skips_search_for_capped_incumbent_fallback(monkeypatch: def fail_route_astar(*_args, **_kwargs): raise AssertionError("route_astar should not run for capped incumbent fallback") - def record_install(self, net_id, path): + def record_added_route(self, net_id, path): _ = self installed.append((net_id, tuple(path))) monkeypatch.setattr(router_module, "route_astar", fail_route_astar) - monkeypatch.setattr(PathFinder, "_install_path", record_install) + monkeypatch.setattr(PathFinder, "_add_route", record_added_route) result, guidance_seed_present = pathfinder._route_net_once( state, @@ -2014,7 +2014,7 @@ def test_rejected_pair_keeps_original_index_for_reverse_attempt(monkeypatch: pyt state = finder._prepare_state() for net in problem.nets: path = (Straight.generate(net.start, 80, net.width, dilation=1.0),) - finder._install_path(net.net_id, path) + finder._add_route(net.net_id, path) 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) @@ -2072,7 +2072,7 @@ def test_route_all_restores_best_iteration_snapshot_on_timeout(monkeypatch: pyte total_dynamic_collisions=0, ), ) - state.best_is_installed = True + state.best_is_indexed = True state.results = {"netA": worse_result} return True diff --git a/inire/tests/test_clearance_precision.py b/inire/tests/test_clearance_precision.py index 2829d8c..619daff 100644 --- a/inire/tests/test_clearance_precision.py +++ b/inire/tests/test_clearance_precision.py @@ -45,7 +45,7 @@ def test_clearance_thresholds(): # Net 1: Centerline at y=0 p1 = Port(0, 0, 0) res1 = Straight.generate(p1, 50.0, width=2.0, dilation=1.0) - ce.add_path("net1", res1.collision_geometry, dilated_geometry=res1.dilated_collision_geometry) + ce.add_path_geometry("net1", res1.collision_geometry, dilated_geometry=res1.dilated_collision_geometry) # Net 2: Parallel to Net 1 # 1. Beyond minimum spacing: y=5. Gap = 5 - 2 = 3 > 2. OK. diff --git a/inire/tests/test_collision.py b/inire/tests/test_collision.py index 9e7e1a3..5d4e2c2 100644 --- a/inire/tests/test_collision.py +++ b/inire/tests/test_collision.py @@ -35,7 +35,7 @@ def test_verify_path_rejects_invalid_polygon_before_clearance_checks() -> None: self_intersecting = Polygon([(0, -1), (10, 1), (0, 1), (10, -1)]) component = replace(straight, physical_geometry=(self_intersecting,)) - world.install_path("invalid", (component,)) + world.add_route("invalid", (component,)) report = world.verify_path_report("invalid", (component,)) assert not world.has_dynamic_paths() @@ -205,7 +205,7 @@ def test_verify_path_report_preserves_long_net_id() -> None: geoms = [poly for component in path for poly in component.collision_geometry] dilated = [poly for component in path for poly in component.dilated_collision_geometry] - engine.add_path(net_id, geoms, dilated_geometry=dilated) + engine.add_path_geometry(net_id, geoms, dilated_geometry=dilated) report = engine.verify_path_report(net_id, path) assert report.dynamic_collision_count == 0 @@ -221,12 +221,12 @@ def test_verify_path_report_distinguishes_long_net_ids_with_shared_prefix() -> N path_a = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] path_b = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] - engine.add_path( + engine.add_path_geometry( net_a, [poly for component in path_a for poly in component.collision_geometry], dilated_geometry=[poly for component in path_a for poly in component.dilated_collision_geometry], ) - engine.add_path( + engine.add_path_geometry( net_b, [poly for component in path_b for poly in component.collision_geometry], dilated_geometry=[poly for component in path_b for poly in component.dilated_collision_geometry], @@ -245,12 +245,12 @@ def test_verify_path_report_uses_physical_bounds_before_exact_checks() -> None: path_b = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] path_far = [Straight.generate(Port(100, 100, 0), 20.0, width=2.0, dilation=1.0)] - engine.add_path( + engine.add_path_geometry( "netB", [poly for component in path_b for poly in component.collision_geometry], dilated_geometry=[poly for component in path_b for poly in component.dilated_collision_geometry], ) - engine.add_path( + engine.add_path_geometry( "netFar", [poly for component in path_far for poly in component.collision_geometry], dilated_geometry=[poly for component in path_far for poly in component.dilated_collision_geometry], @@ -268,7 +268,7 @@ def test_verify_path_report_uses_physical_distance_between_routes(clearance, val engine = RoutingWorld(clearance=clearance) existing = Straight.generate(Port(0, 0, 0), 10, width=2, dilation=clearance / 2) query = Straight.generate(Port(12, 2, 90), 10, width=2, dilation=clearance / 2) - engine.install_path("existing", (existing,)) + engine.add_route("existing", (existing,)) # The physical corners are one unit apart on each axis. assert engine.verify_path_report("query", (query,)).is_valid is valid @@ -284,7 +284,7 @@ def test_verify_path_clearance_threshold_survives_translation(y, gap, valid) -> tested = Straight.generate(Port(0, y, 0), 20, width) peer = Straight.generate(Port(0, y + 1, 0), 20, width) - engine.install_path("peer", (peer,)) + engine.add_route("peer", (peer,)) assert engine.verify_path_report("query", (tested,)).is_valid is valid engine.remove_path("peer") engine.add_static_obstacle(peer.physical_geometry[0]) @@ -321,7 +321,7 @@ def test_verify_path_details_returns_conflicting_net_ids() -> None: path_a = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] path_b = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] - engine.add_path( + engine.add_path_geometry( "netB", [poly for component in path_b for poly in component.collision_geometry], dilated_geometry=[poly for component in path_b for poly in component.dilated_collision_geometry], @@ -343,7 +343,7 @@ def test_verify_path_details_reports_component_conflicts() -> None: Straight.generate(Port(10, 0, 0), 10.0, width=2.0, dilation=1.0), ] - engine.install_path("netB", path_b) + engine.add_route("netB", path_b) detail = engine.verify_path_details("netA", path_a, capture_component_conflicts=True) @@ -379,7 +379,7 @@ def test_verify_path_details_deduplicates_component_conflicts() -> None: dilated_physical_geometry=[box(5, 0, 17, 10)], ) - engine.add_path( + engine.add_path_geometry( "netB", blocker_component.collision_geometry, dilated_geometry=blocker_component.dilated_collision_geometry, @@ -398,7 +398,7 @@ def test_remove_path_clears_dynamic_path() -> None: geoms = [poly for component in path for poly in component.collision_geometry] dilated = [poly for component in path for poly in component.dilated_collision_geometry] - engine.add_path("netA", geoms, dilated_geometry=dilated) + engine.add_path_geometry("netA", geoms, dilated_geometry=dilated) assert {net_id for net_id, _ in engine._dynamic_paths.geometries.values()} == {"netA"} engine.remove_path("netA") @@ -412,12 +412,12 @@ def test_dynamic_grid_updates_incrementally_on_add_and_remove() -> None: path_a = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] path_b = [Straight.generate(Port(0, 4, 0), 20.0, width=2.0, dilation=1.0)] - engine.add_path( + engine.add_path_geometry( "netA", [poly for component in path_a for poly in component.collision_geometry], dilated_geometry=[poly for component in path_a for poly in component.dilated_collision_geometry], ) - engine.add_path( + engine.add_path_geometry( "netB", [poly for component in path_b for poly in component.collision_geometry], dilated_geometry=[poly for component in path_b for poly in component.dilated_collision_geometry], @@ -443,7 +443,7 @@ def test_large_dynamic_spans_use_tree_for_congestion(large_install) -> None: engine = RoutingWorld(clearance=2) installed = Straight.generate(Port(0, 0, 0), 100_000 if large_install else 20, width=2, dilation=1) query = Straight.generate(Port(10, -10, 90), 20 if large_install else 100_000, width=2, dilation=1) - engine.install_path("peer", (installed,)) + engine.add_route("peer", (installed,)) index = engine._dynamic_paths assert bool(index.grid_net_obj_ids) is (not large_install) @@ -466,12 +466,12 @@ def test_dynamic_net_envelopes_update_incrementally_on_add_and_remove() -> None: path_a = [Straight.generate(Port(0, 0, 0), 20.0, width=2.0, dilation=1.0)] path_b = [Straight.generate(Port(0, 40, 0), 10.0, width=2.0, dilation=1.0)] - engine.add_path( + engine.add_path_geometry( "netA", [poly for component in path_a for poly in component.collision_geometry], dilated_geometry=[poly for component in path_a for poly in component.dilated_collision_geometry], ) - engine.add_path( + engine.add_path_geometry( "netB", [poly for component in path_b for poly in component.collision_geometry], dilated_geometry=[poly for component in path_b for poly in component.dilated_collision_geometry], @@ -500,7 +500,7 @@ def test_congestion_query_uses_per_polygon_bounds() -> None: engine.metrics = AStarMetrics() blocker = Straight.generate(Port(40, 4, 90), 2.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(blocker.collision_geometry), dilated_geometry=list(blocker.dilated_collision_geometry), @@ -531,7 +531,7 @@ def test_congestion_touching_geometries_do_not_count_as_overlap() -> None: existing = Straight.generate(Port(0, 0, 0), 10.0, width=2.0, dilation=1.0) touching = Straight.generate(Port(12, 0, 0), 10.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(existing.collision_geometry), dilated_geometry=list(existing.dilated_collision_geometry), @@ -545,7 +545,7 @@ def test_congestion_exact_checks_only_touch_relevant_move_polygons() -> None: engine.metrics = AStarMetrics() blocker = Straight.generate(Port(0, 0, 0), 10.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(blocker.collision_geometry), dilated_geometry=list(blocker.dilated_collision_geometry), @@ -576,7 +576,7 @@ def test_congestion_grid_span_cache_reuses_broad_phase_candidates() -> None: cache: dict[tuple[str, int, int, int, int], dict[str, tuple[int, ...]]] = {} blocker = Straight.generate(Port(15, 0, 0), 20.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(blocker.collision_geometry), dilated_geometry=list(blocker.dilated_collision_geometry), @@ -614,7 +614,7 @@ def test_has_possible_move_congestion_uses_presence_cache_and_skips_empty_spans( presence_cache: dict[tuple[str, int, int, int, int], bool] = {} blocker = Straight.generate(Port(10, 0, 0), 20.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(blocker.collision_geometry), dilated_geometry=list(blocker.dilated_collision_geometry), @@ -639,7 +639,7 @@ def test_has_candidate_move_congestion_uses_candidate_precheck_cache() -> None: grid_net_cache: dict[tuple[str, int, int, int, int], tuple[str, ...]] = {} blocker = Straight.generate(Port(10, 0, 0), 20.0, width=2.0, dilation=1.0) - engine.add_path( + engine.add_path_geometry( "netB", list(blocker.collision_geometry), dilated_geometry=list(blocker.dilated_collision_geometry), diff --git a/inire/tests/test_pathfinder.py b/inire/tests/test_pathfinder.py index 05e9851..dc2e721 100644 --- a/inire/tests/test_pathfinder.py +++ b/inire/tests/test_pathfinder.py @@ -119,7 +119,7 @@ def test_frontier_replay_restores_installed_path_and_metrics(monkeypatch: pytest for net_id, net in state.net_specs.items(): path = (Straight.generate(net.start, 80, net.width, dilation=world.clearance / 2),) state.results[net_id] = RoutingResult(net_id, path, reached_target=True) - finder._install_path(net_id, path) + finder._add_route(net_id, path) original_metrics = finder.metrics original_snapshot = original_metrics.snapshot()