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