pub trait Solver<'model> {
// Required methods
fn new(model: &'model Model) -> Self
where Self: Sized;
fn solve(&mut self) -> Result<Solution, SolveError>;
fn get_objective_value(&self) -> f64;
fn get_solution(&self) -> Vec<f64>;
}Expand description
Trait for optimization solvers.
Any struct implementing this trait can solve a Model and produce a Solution.
This trait provides a consistent interface across different solver implementations,
such as simplex, interior point, branch-and-bound, or lexicographic solvers.
let mut model = Model::new();
// ... build model variables, constraints, objective ...
let mut solver = DummySolver::new(&model);
let result: Result<_, SolveError> = solver.solve();
match result {
Ok(solution) => println!("Optimal solution: {}", solution.objective_value.unwrap_or(0.0)),
Err(e) => println!("Solver error: {}", e),
}Generic over:
S: solver state type
Required Methods§
Sourcefn new(model: &'model Model) -> Selfwhere
Self: Sized,
fn new(model: &'model Model) -> Selfwhere
Self: Sized,
Create a new solver for the given model.
Sourcefn solve(&mut self) -> Result<Solution, SolveError>
fn solve(&mut self) -> Result<Solution, SolveError>
Solve the model.
Sourcefn get_objective_value(&self) -> f64
fn get_objective_value(&self) -> f64
Get the current objective value (if available).
Sourcefn get_solution(&self) -> Vec<f64>
fn get_solution(&self) -> Vec<f64>
Return the current solution vector.