From 07f1c47e26e57fb3928d78324c2219e3033ef608 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 29 Nov 2026 00:37:13 -0800 Subject: [PATCH] Document and test history-sensitive A* successors --- docs/architecture.md | 2 ++ inire/tests/test_astar.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/docs/architecture.md b/docs/architecture.md index b9f4349..79aef02 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -28,6 +28,8 @@ The near-port attempt uses up to 100 nodes per search and two congestion iterati - **Build and admit moves.** Weighted A* searches snapped positions and headings. Rays, visible corners, and corridor waypoints propose straight endpoints. If a ray blocks a launch, a flat-ended trace scan checks for room to move. An aligned target goes directly to admission, which checks the straight's rectangular footprint for clearance. A long lead can use consecutive straights when a single forward scan cannot cover it. Search releases turns away from a distant target when preferred moves run out or the reserved share of the expansion budget begins. Searches with up to 16 expansions consider these turns immediately. Larger searches release them with at least one tenth of the budget left, rounded down with a minimum of one expansion. S-bends can follow each other when the configured moves permit it. Admission also checks cost and state dominance. [Move generation](../inire/router/_astar_moves.py) + The closed set groups states by snapped position and heading. Arrivals with different final straight lengths, seed progress, or occupied path geometry can offer different continuations. This pruning keeps the search bounded in practice and can discard an alternative history. A regression test demonstrates different straight proposals from equal-cost arrivals at one port. + - **Recheck the installed set.** Paths that reach their targets and pass geometry checks against themselves, the board, and keepouts participate in congestion. Partial and geometrically invalid paths remain available for diagnosis. After an iteration the driver verifies the installed paths, since a later route can collide with one completed earlier. It ranks snapshots by completed nets, then by conflicts and dynamic collisions. A narrowed retry includes every net that still fails verification. [`next_reroute_net_ids()`](../inire/router/_congestion_policy.py#L99) - **Repair a small conflict set.** The driver returns to the best iteration and can reuse its verification when those paths are still installed and restored-stage traces are disabled. If the conflicts form separate pairs, the router can try repairing up to two of them. It holds the other paths fixed, tries both routing orders as needed, and checks proposed replacements against the installed layout. For a worked trace, [follow a late conflict](routing-diagnostics.md#follow-a-late-conflict-into-pair-local-repair). diff --git a/inire/tests/test_astar.py b/inire/tests/test_astar.py index 6b9eaa3..0758cb0 100644 --- a/inire/tests/test_astar.py +++ b/inire/tests/test_astar.py @@ -6,6 +6,7 @@ from inire import CongestionOptions, NetSpec, ObjectiveWeights, RefinementOption from inire.geometry.components import Bend90, Straight from inire.geometry.collision import RoutingWorld from inire.geometry.primitives import Port +from inire.router import _astar_moves from inire.router._astar_types import AStarContext, AStarNode, CongestionCaches, SearchRunConfig from inire.router._astar_admission import add_node from inire.router._astar_moves import ( @@ -250,6 +251,30 @@ def test_should_cap_straights_to_bounds_only_for_large_no_warm_runs(basic_evalua assert not _should_cap_straights_to_bounds(small_context) +def test_equal_cost_arrivals_can_propose_different_straights(monkeypatch) -> None: + start, target = Port(5, 20, 0), Port(35, 20, 0) + problem = RoutingProblem((0, 0, 100, 50), (NetSpec("track", start, target),)) + options = _build_options(max_straight_length=50, min_straight_length=2, bend_radii=(), sbend_radii=()) + context = build_routing_stack(problem, options).context + config = SearchRunConfig.from_options(options) + root = AStarNode(start, 0, 0) + direct = Straight.generate(start, 20, 2) + first_short = Straight.generate(start, 15, 2) + second_short = Straight.generate(first_short.end_port, 5, 2) + intermediate = AStarNode(first_short.end_port, 15, 0, parent=root, component_result=first_short) + long_arrival = AStarNode(direct.end_port, 20, 0, parent=root, component_result=direct) + short_arrival = AStarNode(second_short.end_port, 20, 0, parent=intermediate, component_result=second_short) + assert long_arrival.port == short_arrival.port + assert long_arrival.g_cost == short_arrival.g_cost + + proposals = [] + monkeypatch.setattr(_astar_moves, "process_move", lambda *args: proposals.append(args[-2:])) + for node, offers_target in ((long_arrival, True), (short_arrival, False)): + proposals.clear() + _astar_moves.expand_moves(node, target, 2, "track", [], {}, context, context.metrics, CongestionCaches(), config, None) + assert (("straight", (10,)) in proposals) is offers_target + + def test_pair_local_context_clones_live_static_obstacles() -> None: obstacle = Polygon([(20, -20), (40, -20), (40, 20), (20, 20)]) engine = RoutingWorld(clearance=2.0)