Validate direct benchmark inputs and preserve fallback headings
This commit is contained in:
parent
495bf8d307
commit
f247cff54a
1 changed files with 57 additions and 20 deletions
|
|
@ -35,7 +35,7 @@ from inire.tests.routing_corpus import (
|
|||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from inire import CapacityLimit, RoutingProblem, RoutingTiming, TopologyReport
|
||||
from inire import CapacityLimit, RoutingProblem, RoutingRunResult, RoutingTiming, TopologyReport, _IterationCallback
|
||||
from inire.router._routing_policy import RouteCall, Trial
|
||||
from inire.tests.routing_benchmark_case import BenchmarkCase
|
||||
|
||||
|
|
@ -118,6 +118,19 @@ def _measure(case: BenchmarkCase, options: RoutingOptions, strategy: str) -> Run
|
|||
attempt_options: list[RoutingOptions] = []
|
||||
run_route = partial(_route, run_router=partial(_dispatch_route, attempt_callback=attempt_options.append))
|
||||
run_worker = partial(route_once, attempt_callback=attempt_options.append)
|
||||
|
||||
def measure_direct(problem: RoutingProblem, policy: str) -> tuple[RoutingRunResult, list[Trial]]:
|
||||
trials: list[Trial] = []
|
||||
|
||||
def run_direct(
|
||||
prepared_problem: RoutingProblem, worker_options: RoutingOptions, _iteration_callback: _IterationCallback | None,
|
||||
) -> RoutingRunResult:
|
||||
trials.extend(_direct_trials(prepared_problem, board, worker_options, policy, run_route=run_worker))
|
||||
return _best_trial(trials).run
|
||||
|
||||
run = _route(problem, options=options, run_router=run_direct)
|
||||
return run, trials
|
||||
|
||||
started = perf_counter()
|
||||
bundle_rejection = None
|
||||
bundle_duration = None
|
||||
|
|
@ -159,23 +172,22 @@ def _measure(case: BenchmarkCase, options: RoutingOptions, strategy: str) -> Run
|
|||
except ValueError as exc:
|
||||
bundle_rejection = str(exc)
|
||||
bundle_duration = perf_counter() - started
|
||||
trials = _direct_trials(case.fixed_headings_problem(), board, options, "direct-probe-near-port", run_route=run_worker)
|
||||
run, trials = measure_direct(case.fixed_headings_problem(), "direct-probe-near-port")
|
||||
else:
|
||||
bundle_duration = perf_counter() - started
|
||||
stage = RoutingStage("bundle", (), run.metrics.nodes_expanded, options.search.node_limit, kind="bundle")
|
||||
trials = [_trial(run, stage)]
|
||||
elif strategy in DIRECT_POLICIES:
|
||||
problem = case.fixed_headings_problem()
|
||||
trials = _direct_trials(problem, board, options, strategy, run_route=run_worker)
|
||||
run, trials = measure_direct(case.fixed_headings_problem(), strategy)
|
||||
elif strategy in ORDER_POLICIES:
|
||||
problem = case.fixed_headings_problem()
|
||||
trials = _order_trials(problem, options, strategy, run_route=run_route)
|
||||
run = _best_trial(trials).run
|
||||
else:
|
||||
run = run_route(case.fixed_headings_problem(), options=options)
|
||||
trials = [_trial(run, RoutingStage(strategy, (), run.metrics.nodes_expanded, options.search.node_limit))]
|
||||
best = _best_trial(trials)
|
||||
duration = perf_counter() - started
|
||||
run = best.run
|
||||
return RunSample(
|
||||
duration_s=duration,
|
||||
net_outcomes={net_id: result.outcome for net_id, result in run.results_by_net.items()},
|
||||
|
|
|
|||
Loading…
Reference in a new issue