diff --git a/inire/router/_perimeter.py b/inire/router/_perimeter.py index 5189d4a..a470329 100644 --- a/inire/router/_perimeter.py +++ b/inire/router/_perimeter.py @@ -66,7 +66,7 @@ def residual_dogleg_candidates(problem: RoutingProblem, search: SearchOptions) - lanes.update((floor(bottom), ceil(top))) lanes = {y for y in lanes if floor_y + half_width <= y <= ceiling_y - half_width} ordered_lanes = sorted(lanes, key=lambda y: (abs(y - start_y) + abs(y - end_y), y)) - minimum, maximum = max(0.0, search.min_straight_length), search.max_straight_length + minimum = search.min_straight_length remaining = 16384 for radius in sorted({int(r) for r in search.bend_radii if isfinite(r) and r > 0 and r == int(r)}): first, last = ceil(start_x + radius + minimum), floor(end_x - radius - minimum) @@ -89,14 +89,14 @@ def residual_dogleg_candidates(problem: RoutingProblem, search: SearchOptions) - if not remaining: return remaining -= 1 - if not 2 * radius + minimum <= b - a <= 2 * radius + maximum: + if b - a < 2 * radius + minimum: continue if not straight_clear(a + radius, y, b - radius, y): continue points = tuple(physical(x, h) for x, h in ((start_x, start_y), (a, start_y), (a, y), (b, y), (b, end_y), (end_x, end_y))) seed, end = compile_waypoints(points, net.start, radius) if end == net.target and all( - not isinstance(move, StraightSeed) or minimum <= move.length <= maximum for move in seed.segments + not isinstance(move, StraightSeed) or minimum <= move.length for move in seed.segments ): yield seed diff --git a/inire/tests/test_routing_benchmarks.py b/inire/tests/test_routing_benchmarks.py index 8a8f9b6..a9cea6d 100644 --- a/inire/tests/test_routing_benchmarks.py +++ b/inire/tests/test_routing_benchmarks.py @@ -149,6 +149,26 @@ def test_stress_residual_dogleg_completes_layout_before_wider_search() -> None: assert iterations == list(range(observed.metrics.route_iterations)) +def test_residual_dogleg_seeds_can_use_straights_longer_than_the_lattice_scan() -> None: + case = next(case for case in STRESS_BENCHMARK_CASES if case.name == "stress-retry-straight-decoy") + options = replace( + case.options, + search=replace(case.options.search, node_limit=25, max_straight_length=180), + congestion=replace(case.options.congestion, max_iterations=1, warm_start_enabled=False), + refinement=replace(case.options.refinement, enabled=False), + topology=TopologyOptions(mode="automatic"), + ) + + run = route(case.problem, options=options) + + assert run.automatic.selected_planner == "residual-dogleg" + assert all(run.results_by_net[net.net_id].is_valid for net in case.problem.nets) + assert any( + isinstance(move, StraightSeed) and move.length > options.search.max_straight_length + for move in run.results_by_net["trunk"].as_seed().segments + ) + + @pytest.mark.parametrize(("iterations", "probe_limit"), [(1, 1), (3, 2)]) def test_automatic_probe_caps_iterations_and_preserves_callback_order(monkeypatch, iterations, probe_limit) -> None: (case,) = CASE_GROUPS["pic-splitter-tree-1x8-ew"]