solver/numeric/solver.rs
1use super::result::GridSolution;
2use crate::core::grid::Grid;
3use crate::models::control::ControlProblem;
4
5/// Common interface for all numerical HJB solvers.
6///
7/// Provides a unified API for solving the HJB equation using different
8/// numerical methods:
9/// - **Policy Iteration**: finite difference grid method.
10/// - **BSDE**: regression-based Monte Carlo approach for high-dimensional
11/// problems.
12///
13/// The trait is generic over the [`ControlProblem`] being solved and returns
14/// the problem's associated control type in the [`GridSolution`].
15pub trait Solver {
16 /// Solve the HJB equation and return the solution at a query state.
17 ///
18 /// # Arguments
19 /// * `grid` - the discretization grid (irrelevant for grid-free methods
20 /// such as BSDE).
21 /// * `problem` - the stochastic optimal control problem defining the
22 /// dynamics and objective.
23 /// * `time_steps` - number of time steps for the backward induction or
24 /// simulation.
25 /// * `query_state` - the state vector at which to evaluate the solution.
26 fn solve<const N: usize, C: ControlProblem<N> + Sync>(
27 &self,
28 grid: Option<&Grid<N>>,
29 problem: &C,
30 time_steps: usize,
31 query_state: &[f64; N],
32 ) -> GridSolution<N, C::Control>;
33}