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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
//! Optimisation algorithms //! //! use crate::constraints; pub mod fbs; pub mod panoc; pub mod problem; pub mod solver_status; /// Solver status /// /// This structure contais information about the solver status. Instances of /// `SolverStatus` are returned by optimizers. /// pub struct SolverStatus { /// whether the algorithm has converged converged: bool, /// number of iterations for convergence num_iter: usize, /// norm of the fixed-point residual (FPR) fpr_norm: f64, /// cost value at the candidate solution cost_value: f64, } /// 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]) -> SolverStatus; } /// 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 `true` only if the iterations should continue fn step(&mut self, &mut [f64]) -> bool; fn init(&mut self, &mut [f64]); } /// Definition of an optimisation problem /// /// The definition of an optimisation problem involves: /// - the gradient of the cost function /// - the cost function /// - the set of constraints, which is described by implementations of /// [Constraint](../../panoc_rs/constraints/trait.Constraint.html) pub struct Problem<GradientType, ConstraintType, CostType> where GradientType: Fn(&[f64], &mut [f64]) -> i32, CostType: Fn(&[f64], &mut f64) -> i32, ConstraintType: constraints::Constraint, { /// constraints constraints: ConstraintType, /// gradient of the cost gradf: GradientType, /// cost function cost: CostType, }