optimization_engine/core/mod.rs
1#![deny(missing_docs)]
2//! Optimisation algorithms
3//!
4//!
5
6pub mod fbs;
7pub mod panoc;
8pub mod problem;
9pub mod solver_status;
10
11pub use crate::{constraints, FunctionCallResult, SolverError};
12pub use problem::Problem;
13pub use solver_status::SolverStatus;
14
15/// Exit status of an algorithm (not algorithm specific)
16///
17///
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum ExitStatus {
20 /// The algorithm has converged
21 ///
22 /// All termination criteria are satisfied and the algorithm
23 /// converged within the available time and number of iterations
24 Converged,
25 /// Failed to converge because the maximum number of iterations was reached
26 NotConvergedIterations,
27 /// Failed to converge because the maximum execution time was reached
28 NotConvergedOutOfTime,
29}
30
31/// A general optimizer
32pub trait Optimizer {
33 /// solves a given problem and updates the initial estimate `u` with the solution
34 ///
35 /// Returns the solver status
36 ///
37 fn solve(&mut self, u: &mut [f64]) -> Result<SolverStatus, SolverError>;
38}
39
40/// Engine supporting an algorithm
41///
42/// An engine is responsible for the allocation of memory for an algorithm,
43/// especially memory that is reuasble is multiple instances of the same
44/// algorithm (as in model predictive control).
45///
46/// It defines what the algorithm does at every step (see `step`) and whether
47/// the specified termination criterion is satisfied
48///
49pub trait AlgorithmEngine {
50 /// Take a step of the algorithm and return `Ok(true)` only if the iterations should continue
51 fn step(&mut self, u: &mut [f64]) -> Result<bool, SolverError>;
52
53 /// Initializes the algorithm
54 fn init(&mut self, u: &mut [f64]) -> FunctionCallResult;
55}