Preserve verify-only diagnostics and honor refinement objectives
This commit is contained in:
parent
f9ba5669dd
commit
2611085808
1 changed files with 188 additions and 29 deletions
|
|
@ -147,6 +147,9 @@ class _AutomaticRun:
|
|||
return run
|
||||
|
||||
def _selection_cost(self, result: RoutingResult) -> float:
|
||||
if not self.options.search.node_limit:
|
||||
# Verification-only runs have a single candidate to report.
|
||||
return 0.0
|
||||
if self.length_weights is not None:
|
||||
return weighted_path_length(result.path, self.length_weights)
|
||||
if self.evaluator is None:
|
||||
|
|
@ -581,10 +584,10 @@ class _AutomaticRun:
|
|||
)
|
||||
trials.append(self._trial(run, stage))
|
||||
|
||||
def _refine(self, trials: list[Trial]) -> None:
|
||||
def _refine(self, trials: list[Trial]) -> Trial | None:
|
||||
best = _best_trial(trials)
|
||||
if not self.options.refinement.enabled or not best.valid_costs:
|
||||
return
|
||||
return None
|
||||
has_unresolved_paths = any(result.path and not result.is_valid for result in best.run.results_by_net.values())
|
||||
run, stage = self._seeded_attempt(
|
||||
self._seeded_problem(best, include_unresolved=has_unresolved_paths),
|
||||
|
|
@ -596,9 +599,21 @@ class _AutomaticRun:
|
|||
)
|
||||
# Any carried-over result without a replayed seed has no path to recheck.
|
||||
results = {**best.run.results_by_net, **run.results_by_net}
|
||||
refined = self._trial(replace(run, results_by_net=results), stage)
|
||||
refined = self._trial(replace(run, results_by_net=results), stage).as_replacement_for(best)
|
||||
# Only a whole verified replacement of the incumbent can win.
|
||||
trials.append(refined.as_replacement_for(best))
|
||||
trials.append(refined)
|
||||
objective = self.options.refinement.objective
|
||||
if objective is None:
|
||||
return None
|
||||
if not refined.selectable:
|
||||
return best
|
||||
evaluator = build_native_cost_evaluator(self.problem, objective)
|
||||
|
||||
def cost(trial: Trial) -> float:
|
||||
paths = (trial.run.results_by_net[net_id].path for net_id in trial.valid_costs)
|
||||
return sum(evaluator.path_cost(path[0].start_port, path) for path in paths)
|
||||
|
||||
return refined if cost(refined) < cost(best) else best
|
||||
|
||||
def execute(self) -> RoutingRunResult:
|
||||
started = perf_counter()
|
||||
|
|
@ -609,6 +624,7 @@ class _AutomaticRun:
|
|||
rejections = ()
|
||||
target = len(self.problem.nets)
|
||||
trials: list[Trial] = []
|
||||
refinement_choice = None
|
||||
if not self.problem.nets or options.search.node_limit <= 0 or options.congestion.max_iterations <= 0:
|
||||
self._lattice_fallback(trials, options, "No automatic search requested")
|
||||
elif (
|
||||
|
|
@ -634,8 +650,8 @@ class _AutomaticRun:
|
|||
else:
|
||||
worker = replace(options, refinement=replace(options.refinement, enabled=False))
|
||||
self._lattice_fallback(trials, worker, "Constrained triangulation is unavailable")
|
||||
self._refine(trials)
|
||||
best = _best_trial(trials)
|
||||
refinement_choice = self._refine(trials)
|
||||
best = refinement_choice or _best_trial(trials)
|
||||
metrics = _sum_route_metrics(self.metrics)
|
||||
report = AutomaticRoutingReport(
|
||||
tuple(trial.stage for trial in trials),
|
||||
|
|
|
|||
Loading…
Reference in a new issue