use super::params::OptimParams;
use super::{ObjectiveData, OptimProgressCallback, PenaltyMode};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AlgorithmType {
Global,
Local,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ConstraintCapabilities {
pub nonlinear_ineq: bool,
pub nonlinear_eq: bool,
pub linear: bool,
pub iteration_callback: bool,
pub fallback_penalty_mode: PenaltyMode,
}
pub trait FilterOptimizer: Send + Sync {
fn name(&self) -> &'static str;
fn library(&self) -> &'static str;
fn algorithm_type(&self) -> AlgorithmType;
fn capabilities(&self) -> ConstraintCapabilities;
fn optimize(
&self,
x: &mut [f64],
lower: &[f64],
upper: &[f64],
objective: ObjectiveData,
params: &OptimParams,
callback: Option<OptimProgressCallback>,
) -> Result<(String, f64), (String, f64)>;
}
pub enum ConstraintInstallation {
Native(Vec<NativeConstraint>),
Penalty,
}
pub type ConstraintFn = Box<dyn Fn(&[f64]) -> f64 + Send + Sync>;
pub struct NativeConstraint {
pub label: &'static str,
pub fun: ConstraintFn,
pub tol: f64,
}
pub fn resolve(name: &str) -> Option<Box<dyn FilterOptimizer>> {
super::registry::resolve(name)
}
pub fn all_algorithms() -> Vec<Box<dyn FilterOptimizer>> {
super::registry::all_algorithms()
}