Share the return candidate budget across lanes
This commit is contained in:
parent
2b9d7886fd
commit
393c01704a
2 changed files with 32 additions and 8 deletions
|
|
@ -245,6 +245,9 @@ def _return_detours(
|
||||||
high = max(start.y, target.y) + 2 * radius
|
high = max(start.y, target.y) + 2 * radius
|
||||||
bottom = min(low, min((floor(bottom - margin) for _, bottom, _, _ in obstacles), default=low))
|
bottom = min(low, min((floor(bottom - margin) for _, bottom, _, _ in obstacles), default=low))
|
||||||
top = max(high, max((ceil(top + margin) for _, _, _, top in obstacles), default=high))
|
top = max(high, max((ceil(top + margin) for _, _, _, top in obstacles), default=high))
|
||||||
|
lanes = tuple(y for y in dict.fromkeys((bottom, top, low, high)) if ymin + half_width <= y <= ymax - half_width)
|
||||||
|
if not lanes:
|
||||||
|
return
|
||||||
left_edge = ceil(xmin + half_width)
|
left_edge = ceil(xmin + half_width)
|
||||||
right_edge = floor(xmax - half_width)
|
right_edge = floor(xmax - half_width)
|
||||||
pivots = {left_edge, right_edge, start.x + radius + 1, target.x - radius - 1}
|
pivots = {left_edge, right_edge, start.x + radius + 1, target.x - radius - 1}
|
||||||
|
|
@ -252,14 +255,12 @@ def _return_detours(
|
||||||
pivots.update((floor(left - margin), ceil(right + margin)))
|
pivots.update((floor(left - margin), ceil(right + margin)))
|
||||||
departures = sorted(x for x in pivots if start.x + radius <= x <= right_edge)
|
departures = sorted(x for x in pivots if start.x + radius <= x <= right_edge)
|
||||||
arrivals = sorted((x for x in pivots if left_edge <= x <= target.x - radius), reverse=True)
|
arrivals = sorted((x for x in pivots if left_edge <= x <= target.x - radius), reverse=True)
|
||||||
for y in dict.fromkeys((bottom, top, low, high)):
|
# Try each lane for a pivot pair before spending the budget on more pivots.
|
||||||
if not ymin + half_width <= y <= ymax - half_width:
|
for first, last, y in product(departures, arrivals, lanes):
|
||||||
continue
|
points = ((start.x, start.y), (first, start.y), (first, y), (last, y), (last, target.y), (target.x, target.y))
|
||||||
for first, last in product(departures, arrivals):
|
seed, end = compile_waypoints(points, start, radius)
|
||||||
points = ((start.x, start.y), (first, start.y), (first, y), (last, y), (last, target.y), (target.x, target.y))
|
if end == target:
|
||||||
seed, end = compile_waypoints(points, start, radius)
|
yield seed
|
||||||
if end == target:
|
|
||||||
yield seed
|
|
||||||
|
|
||||||
|
|
||||||
def perimeter_detour_candidates(problem: RoutingProblem, search: SearchOptions) -> Iterator[tuple[NetSpec, PathSeed]]:
|
def perimeter_detour_candidates(problem: RoutingProblem, search: SearchOptions) -> Iterator[tuple[NetSpec, PathSeed]]:
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,29 @@ def test_return_detours_try_inner_lanes_when_keepouts_reach_board_edges() -> Non
|
||||||
assert run.results_by_net[net.net_id].is_valid
|
assert run.results_by_net[net.net_id].is_valid
|
||||||
|
|
||||||
|
|
||||||
|
def test_return_detours_try_both_sides_within_the_candidate_budget(monkeypatch) -> None:
|
||||||
|
net = NetSpec("return", Port(130, 60, 0), Port(40, 60, 0))
|
||||||
|
obstacles = (box(135, 42, 199, 48), *(box(x, 100, x + 1, 104) for x in (*range(10, 29, 3), *range(142, 181, 4))))
|
||||||
|
problem = RoutingProblem((0, 0, 200, 130), (net,), obstacles, clearance=0)
|
||||||
|
original_detours = _automatic.perimeter_detour_candidates
|
||||||
|
generated = 0
|
||||||
|
|
||||||
|
def detours(candidate_problem, search):
|
||||||
|
nonlocal generated
|
||||||
|
for candidate in original_detours(candidate_problem, search):
|
||||||
|
generated += 1
|
||||||
|
yield candidate
|
||||||
|
|
||||||
|
monkeypatch.setattr(_automatic, "perimeter_detour_candidates", detours)
|
||||||
|
run = route(problem, options=OPTIONS)
|
||||||
|
|
||||||
|
result = run.results_by_net[net.net_id]
|
||||||
|
assert run.automatic.selected_planner == "perimeter"
|
||||||
|
assert result.is_valid
|
||||||
|
assert next(move.direction for move in result.as_seed().segments if isinstance(move, Bend90Seed)) == "CCW"
|
||||||
|
assert 0 < generated <= 32
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(("forward", "needs_short_straight"), [(43, True), (60, False)])
|
@pytest.mark.parametrize(("forward", "needs_short_straight"), [(43, True), (60, False)])
|
||||||
def test_residual_doglegs_prefer_the_lattice_minimum_but_can_relax_it(forward, needs_short_straight) -> None:
|
def test_residual_doglegs_prefer_the_lattice_minimum_but_can_relax_it(forward, needs_short_straight) -> None:
|
||||||
trunk = NetSpec("trunk", Port(20, 50, 0), Port(20 + forward, 50, 0))
|
trunk = NetSpec("trunk", Port(20, 50, 0), Port(20 + forward, 50, 0))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue