diff --git a/inire/router/cost.py b/inire/router/cost.py index c76017b..7724882 100644 --- a/inire/router/cost.py +++ b/inire/router/cost.py @@ -277,7 +277,7 @@ def proximity_map(problem: RoutingProblem, proximity_range: float) -> DangerMap: ) -def build_native_cost_evaluator(problem: RoutingProblem, objective: ObjectiveWeights, *, proximity_range: float = 10.0) -> CostEvaluator: +def build_native_cost_evaluator(problem: RoutingProblem, objective: ObjectiveWeights, *, proximity_range: float) -> CostEvaluator: """Score candidate paths using the original layout's obstacles and objective.""" danger = None if objective.danger_weight and problem._blocking_polygons: diff --git a/inire/tests/routing_corpus.py b/inire/tests/routing_corpus.py index 6ad0aad..49949b9 100644 --- a/inire/tests/routing_corpus.py +++ b/inire/tests/routing_corpus.py @@ -139,7 +139,7 @@ def native_verified_costs( results: dict[str, RoutingResult], verified_net_ids: Iterable[str], ) -> dict[str, float]: - scorer = build_native_cost_evaluator(case.problem, options.objective) + scorer = build_native_cost_evaluator(case.problem, options.objective, proximity_range=options.search.proximity_range) costs = {} for net_id in verified_net_ids: path = results[net_id].path diff --git a/inire/tests/test_routing_benchmarks.py b/inire/tests/test_routing_benchmarks.py index 1f9e09d..8ebf000 100644 --- a/inire/tests/test_routing_benchmarks.py +++ b/inire/tests/test_routing_benchmarks.py @@ -15,6 +15,7 @@ from inire.router._automatic import _AutomaticRun from inire.router._capacity import port_conflicts from inire.router._routing_policy import _disconnected_nets from inire.router.cost import weighted_path_length +from inire.tests.routing_benchmark_case import BenchmarkCase from inire.tests.routing_benchmarks import ( BENCHMARK_CASES, CROSSING_BENCHMARK_CASES, @@ -158,6 +159,44 @@ def test_benchmark_profile_records_effective_options(tmp_path, monkeypatch) -> N assert options["topology"]["automatic_length_weights"] is None +def test_seed_order_locked_rejects_touching_routes_at_zero_clearance() -> None: + problem = RoutingProblem( + bounds=(0, 0, 100, 40), + nets=(NetSpec("a", Port(10, 10, 0), Port(90, 10, 0)), NetSpec("b", Port(10, 12, 0), Port(90, 12, 0))), + clearance=0, + ) + options = RoutingOptions( + search=SearchOptions(node_limit=60, bend_radii=(), sbend_radii=()), + congestion=CongestionOptions(max_iterations=1), + ) + case = BenchmarkCase("touching-routes", "Two straight routes sharing an edge", problem, options) + + sample = _measure(case, options, "seed-order-locked") + + first, retry = sample.stages + assert first.valid_net_ids == ("a",) + assert retry.incumbent_net_ids == first.valid_net_ids + assert retry.valid_net_ids == first.valid_net_ids + assert sample.valid_costs.keys() == {"a"} + + +def test_benchmark_native_cost_uses_configured_proximity_range() -> None: + problem = RoutingProblem( + bounds=(0, 0, 100, 40), + nets=(NetSpec("a", Port(10, 10, 0), Port(90, 10, 0)),), + static_obstacles=(box(0, 28, 100, 30),), + ) + options = RoutingOptions(search=SearchOptions(node_limit=30, bend_radii=(), sbend_radii=())) + case = BenchmarkCase("proximity-cost", "Straight route near one keepout", problem, options) + + default = _measure(case, options, "off") + wider = _measure(case, replace(options, search=replace(options.search, proximity_range=40)), "off") + + assert default.valid_costs == wider.valid_costs == {"a": 80.0} + assert default.native_valid_costs == {"a": 80.0} + assert wider.native_valid_costs["a"] > default.native_valid_costs["a"] + + def test_connectivity_screen_checks_each_net_width_and_leaves_unknown_ports_for_search() -> None: problem = RoutingProblem( bounds=(0, 0, 400, 160), diff --git a/scripts/compare_topological_routing.py b/scripts/compare_topological_routing.py index 80eb16f..2d6e377 100644 --- a/scripts/compare_topological_routing.py +++ b/scripts/compare_topological_routing.py @@ -17,7 +17,7 @@ import shapely from shapely.geometry import box, mapping from inire import RoutingOptions, RoutingStage, route -from inire.router._routing_policy import _best_trial +from inire.router._routing_policy import LockPlan, _best_trial, _residual_problem from inire.router._routing_policy import _trial as _summarize_trial from inire.tests.direct_routing_policies import DIRECT_POLICIES from inire.tests.direct_routing_policies import direct_trials as _direct_trials @@ -98,13 +98,7 @@ def _order_trials(problem: RoutingProblem, options: RoutingOptions, strategy: st seeds = {net_id: result.as_seed() for net_id, result in incumbents.items()} second_problem = replace(problem, initial_paths={**seeds, **problem.initial_paths}) elif strategy == "seed-order-locked" and incumbents: - locked = tuple(shape for result in incumbents.values() for shape in result.locked_geometry) - second_problem = replace( - problem, - nets=tuple(net for net in problem.nets if net.net_id not in incumbents), - static_obstacles=problem.static_obstacles + locked, - initial_paths={net_id: seed for net_id, seed in problem.initial_paths.items() if net_id not in incumbents}, - ) + second_problem = _residual_problem(problem, LockPlan(incumbents)) else: second_problem = problem