Share worker setup, residual preparation, and scenario capture

This commit is contained in:
Jan Petykiewicz 2026-11-27 00:38:00 -08:00
commit 0c059cc7d6

View file

@ -6,6 +6,7 @@ from typing import TYPE_CHECKING
from shapely.geometry import box
from inire.geometry.collision import RoutingWorld
from inire.geometry.components import path_within_board
from inire.results import RoutingRunResult
from inire.router._astar_types import AStarContext
from inire.router._router import PathFinder
@ -46,15 +47,11 @@ def build_routing_stack(problem: RoutingProblem, options: RoutingOptions) -> Rou
danger_map = DangerMap(bounds=problem.bounds)
danger_map.precompute(list(problem.static_obstacles))
objective = options.objective
evaluator = CostEvaluator(
evaluator = CostEvaluator.from_objective(
world,
danger_map,
unit_length_cost=objective.unit_length_cost,
options.objective,
greedy_h_weight=options.search.greedy_h_weight,
bend_penalty=objective.bend_penalty,
sbend_penalty=objective.sbend_penalty,
danger_weight=objective.danger_weight,
)
context = AStarContext(evaluator, problem, options)
finder = PathFinder(context)
@ -84,9 +81,13 @@ def route_once(
if options.topology.mode == "bundle":
board = box(*problem.bounds)
for result in results.values():
if not result.is_valid or any(not board.covers(shape) for shape in result.locked_geometry):
if not result.is_valid or not path_within_board(result.path, board):
raise ValueError(f"Bundle schedule failed geometric verification for {result.net_id}")
return collect_worker_result(finder, results)
def collect_worker_result(finder: PathFinder, results: dict[str, RoutingResult]) -> RoutingRunResult:
return RoutingRunResult(
results_by_net=results,
metrics=finder.metrics.snapshot(),