Skip to main content

solverforge_solver/
problem_spec.rs

1//! `ProblemSpec` trait for parameterizing `run_solver` over problem types.
2
3use std::sync::atomic::AtomicBool;
4use std::time::Duration;
5
6use solverforge_config::SolverConfig;
7use solverforge_core::domain::PlanningSolution;
8use solverforge_core::score::{ParseableScore, Score};
9use solverforge_scoring::{ConstraintSet, ScoreDirector};
10
11use crate::run::AnyTermination;
12use crate::solver::SolveResult;
13
14/// Parameterizes `run_solver` over basic-variable and list-variable problems.
15///
16/// Implementors supply problem-specific trivial-case detection, logging,
17/// default time limit, and the actual construction + local search execution.
18pub trait ProblemSpec<S, C>
19where
20    S: PlanningSolution,
21    S::Score: Score + ParseableScore,
22    C: ConstraintSet<S, S::Score>,
23{
24    /// Returns `true` if the problem is trivially empty and solving can be skipped.
25    fn is_trivial(&self, solution: &S) -> bool;
26
27    /// Default solver time limit in seconds (used when config has no termination).
28    fn default_time_limit_secs(&self) -> u64;
29
30    /// Logs the problem scale (entity count, value count, etc.).
31    fn log_scale(&self, solution: &S);
32
33    /// Builds the construction + local search phases and runs the solver.
34    fn build_and_solve(
35        self,
36        director: ScoreDirector<S, C>,
37        config: &SolverConfig,
38        time_limit: Duration,
39        termination: AnyTermination<S, ScoreDirector<S, C>>,
40        terminate: Option<&AtomicBool>,
41        callback: impl Fn(&S) + Send + Sync,
42    ) -> SolveResult<S>;
43}