Complete feasible stress layouts with verified routing fallbacks
This commit is contained in:
parent
d9f0e78330
commit
a2dfb73c33
1 changed files with 1022 additions and 76 deletions
|
|
@ -19,6 +19,86 @@ if TYPE_CHECKING:
|
|||
from inire.router._waypoints import XY
|
||||
|
||||
|
||||
def residual_dogleg_candidates(problem: RoutingProblem, search: SearchOptions) -> Iterator[PathSeed]:
|
||||
"""Try four-turn routes through interior gaps with the incumbent geometry locked."""
|
||||
if len(problem.nets) != 1 or problem.initial_paths:
|
||||
return
|
||||
(net,) = problem.nets
|
||||
if net.start.r != net.target.r:
|
||||
return
|
||||
forward, lateral = ((1, 0), (0, 1), (-1, 0), (0, -1))[int(net.start.r) // 90]
|
||||
|
||||
def project(x: float, y: float) -> tuple[float, float]:
|
||||
return forward * x + lateral * y, forward * y - lateral * x
|
||||
|
||||
def physical(x: int, y: int) -> XY:
|
||||
return forward * x - lateral * y, lateral * x + forward * y
|
||||
|
||||
def extent(bounds: tuple[float, float, float, float]) -> tuple[float, float, float, float]:
|
||||
x0, y0, x1, y1 = bounds
|
||||
a, b = project(x0, y0), project(x1, y1)
|
||||
return min(a[0], b[0]), min(a[1], b[1]), max(a[0], b[0]), max(a[1], b[1])
|
||||
|
||||
start_x, start_y = map(int, project(net.start.x, net.start.y))
|
||||
end_x, end_y = map(int, project(net.target.x, net.target.y))
|
||||
if end_x <= start_x:
|
||||
return
|
||||
half_width = net.width / 2
|
||||
pad = problem.clearance + half_width
|
||||
_, floor_y, _, ceiling_y = extent(problem.bounds)
|
||||
obstacles = []
|
||||
for shape in problem.static_obstacles:
|
||||
if shape.is_empty:
|
||||
continue
|
||||
a, b, c, d = extent(shape.bounds)
|
||||
if c + pad >= start_x and a - pad <= end_x:
|
||||
obstacles.append((a - pad, b - pad, c + pad, d + pad))
|
||||
|
||||
def straight_clear(a: int, b: int, c: int, d: int) -> bool:
|
||||
left, right = sorted((a, c))
|
||||
bottom, top = sorted((b, d))
|
||||
return all(right <= x0 or left >= x1 or top <= y0 or bottom >= y1 for x0, y0, x1, y1 in obstacles)
|
||||
|
||||
lanes = {ceil(floor_y + half_width), floor(ceiling_y - half_width)}
|
||||
for _, bottom, _, top in obstacles:
|
||||
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
|
||||
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)
|
||||
if last - first < 2 * radius:
|
||||
continue
|
||||
pivots = {first, last}
|
||||
for left, _, right, _ in obstacles:
|
||||
pivots.update((floor(left - radius), ceil(right + radius)))
|
||||
pivots = sorted(x for x in pivots if first <= x <= last)
|
||||
entrances = [x for x in pivots if straight_clear(start_x, start_y, x - radius, start_y)]
|
||||
exits = [x for x in reversed(pivots) if straight_clear(x + radius, end_y, end_x, end_y)]
|
||||
for y in ordered_lanes:
|
||||
rises = [sorted((port_y, y)) for port_y in (start_y, end_y)]
|
||||
if any(high - low < 2 * radius + minimum for low, high in rises):
|
||||
continue
|
||||
lower, upper = rises
|
||||
departures = [x for x in entrances if straight_clear(x, lower[0] + radius, x, lower[1] - radius)]
|
||||
arrivals = [x for x in exits if straight_clear(x, upper[0] + radius, x, upper[1] - radius)]
|
||||
for a, b in product(departures, arrivals):
|
||||
if not remaining:
|
||||
return
|
||||
remaining -= 1
|
||||
if not 2 * radius + minimum <= b - a <= 2 * radius + maximum:
|
||||
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
|
||||
):
|
||||
yield seed
|
||||
|
||||
|
||||
def bundle_turnaround_candidates(
|
||||
problem: RoutingProblem,
|
||||
proposal: RoutingProblem,
|
||||
|
|
|
|||
Loading…
Reference in a new issue