Recover remaining routes with column plans and residual detours

This commit is contained in:
Jan Petykiewicz 2026-11-30 15:24:10 -08:00
commit bcd9ade3ea

View file

@ -17,7 +17,7 @@ from inire.model import FixedRoute, resolve_bend_geometry
from inire.results import AutomaticRoutingReport, RoutingStage, RoutingTiming, _planner_for_mode
from inire.router._bundle import ordered_bundle_terminal_headings, plan_ordered_bundle
from inire.router._capacity import cut_capacity, port_conflicts
from inire.router._columns import column_jog_candidates, column_seed_candidates
from inire.router._columns import column_jog_candidates, column_recovery_candidates, column_recovery_subproblems, column_seed_candidates
from inire.router._compact import compact_port_seed_set, short_shift_seed_set
from inire.router._congestion_policy import ordered_nets
from inire.router._perimeter import (
@ -427,9 +427,9 @@ class _AutomaticRun:
return [replace(trial, selection="requires-layout-check"), self._verify_incumbent(trial)]
trials = [trial]
if len(trial.valid_costs) < target:
dogleg = self._residual_dogleg_trial(options, _best_trial([best, trial]))
if dogleg is not None:
return [trial, dogleg]
construction = self._residual_constructive_trial(options, _best_trial([best, trial]))
if construction is not None:
return [trial, construction]
joint = self._joint_lane_trial(residual, options, locks, trial)
if joint is not None:
trials.append(replace(joint, selection="requires-layout-check"))
@ -444,7 +444,7 @@ class _AutomaticRun:
results = {**trial.run.results_by_net, **verified.run.results_by_net}
return replace(verified.as_replacement_for(trial), run=replace(verified.run, results_by_net=results))
def _residual_dogleg_trial(self, options: RoutingOptions, incumbent: Trial) -> Trial | None:
def _residual_constructive_trial(self, options: RoutingOptions, incumbent: Trial, *, limit_per_pass: int = 8) -> Trial | None:
problem = self.problem
if len(incumbent.valid_costs) != len(problem.nets) - 1:
return None
@ -452,9 +452,14 @@ class _AutomaticRun:
residual = _residual_problem(problem, LockPlan(retained))
(net,) = residual.nets
seeds = {net_id: result.as_seed() for net_id, result in retained.items()}
planner = "residual-dogleg"
if net.start.r == net.target.r == 0 and net.start.x > net.target.x:
planner = "residual-perimeter"
candidates = (seed for _, seed in islice(perimeter_detour_candidates(residual, options.search), 32))
else:
planner = "residual-dogleg"
candidates = residual_dogleg_candidates(residual, options.search, limit_per_pass=limit_per_pass)
with self._time("plan", planner=planner, policy=planner):
for seed in residual_dogleg_candidates(residual, options.search, limit_per_pass=8):
for seed in candidates:
candidate = replace(problem, initial_paths={**seeds, net.net_id: seed})
trial = self._verify(candidate, planner, policy=planner)
if len(trial.valid_costs) == len(problem.nets):
@ -501,6 +506,29 @@ class _AutomaticRun:
return True
return False
def _column_recovery_trial(self, options: RoutingOptions) -> Trial | None:
problem = self.problem
if problem.initial_paths or not options.search.bend_radii or not problem._blocking_polygons:
return None
planner = "column-recovery"
with self._time("plan", planner=planner):
groups = column_recovery_subproblems(problem)
if not groups:
return None
combined = {}
for group in groups:
for seeds in column_recovery_candidates(group, options.search):
trial = self._verify(replace(group, initial_paths=seeds), planner)
if len(trial.valid_costs) == len(group.nets):
if group is problem:
return trial
combined.update(seeds)
break
else:
return None
trial = self._verify(replace(problem, initial_paths=combined), planner)
return trial if len(trial.valid_costs) == len(problem.nets) else None
def _search_trials(self, trials: list[Trial], target: int) -> None:
configured_search = self.options.search
first_limit = min(_INITIAL_NODE_LIMIT, configured_search.node_limit)
@ -552,9 +580,9 @@ class _AutomaticRun:
return True
if try_construction_early and target == len(problem.nets) and target > 2 and not problem.initial_paths:
dogleg = self._residual_dogleg_trial(options, _best_trial(probe))
if dogleg is not None:
trials.append(dogleg)
construction = self._residual_constructive_trial(options, _best_trial(probe))
if construction is not None:
trials.append(construction)
return True
if len(problem.nets) <= 2:
@ -563,6 +591,12 @@ class _AutomaticRun:
if len(_best_trial(trials).valid_costs) >= target:
return True
if target == len(problem.nets) and not options.congestion.shuffle_nets:
recovery = self._column_recovery_trial(options)
if recovery is not None:
trials.append(recovery)
return True
# Every short shift has lateral displacement, so the direct retry cannot lock
# any straight paths. It would run the same guide with the same budget.
if early is None or early.run.metrics.timeout_events:
@ -578,7 +612,13 @@ class _AutomaticRun:
if len(_best_trial(trials).valid_costs) < target:
run = self._run(problem, options=seeded, policy="seed-fallback")
stage = RoutingStage("seed", (), run.metrics.nodes_expanded, options.search.node_limit, policy="seed-fallback")
trials.append(self._trial(run, stage))
candidate = self._trial(run, stage)
trials.append(candidate)
if not problem.initial_paths and len(candidate.valid_costs) == target - 1 and _best_trial(trials) is candidate:
# The seed fallback can leave a better set of incumbents for a final detour.
construction = self._residual_constructive_trial(options, candidate, limit_per_pass=16)
if construction is not None:
trials.append(construction)
def _joint_lane_trial(self, residual: RoutingProblem, options: RoutingOptions, locks: LockPlan, previous: Trial) -> Trial | None:
if len(residual.nets) < 2: