#![warn(missing_docs)]
#![warn(missing_doc_code_examples)]
#![warn(clippy::all)]
pub mod multi;
pub use multi::*;
pub mod single;
pub use single::*;
pub trait SingleObjective {
const MINIMUM: f64;
fn f(x: Vec<f64>) -> f64;
fn minimizer(n: usize) -> Vec<f64>;
fn check_minimizer(d: usize) {
assert!(Self::f(Self::minimizer(d)) - Self::MINIMUM < f64::EPSILON)
}
}
pub trait MultiObjective {
const NF: usize;
fn f(x: Vec<f64>) -> Vec<f64>;
}
pub trait Bounded {
const BOUNDS: (f64, f64);
fn in_bounds(x: Vec<f64>) -> bool {
let mut in_bounds = true;
for element in x {
if (element < Self::BOUNDS.0) || (element > Self::BOUNDS.1) {
in_bounds = false;
break;
}
}
in_bounds
}
}
pub trait UnBounded {
const BOUNDS: (f64, f64) = (f64::INFINITY, f64::INFINITY);
fn in_bounds(_x: Vec<f64>) -> bool {
true
}
}
pub trait Constrained {
const CONSTRAINED: bool = true;
const NH: usize;
const NG: usize;
fn equality_constraints(x: Vec<f64>) -> Vec<f64>;
fn inequality_constraints(x: Vec<f64>) -> Vec<f64>;
fn h(x: Vec<f64>) -> Vec<f64> {
Self::equality_constraints(x)
}
fn g(x: Vec<f64>) -> Vec<f64> {
Self::inequality_constraints(x)
}
}
pub trait UnConstrained {
const CONSTRAINED: bool = false;
}
pub trait NDimensional {
const D: usize = usize::MAX;
const LOW_D: usize = 2;
const HIGH_D: usize = 137;
}
pub trait FixedDimensional {
const D: usize;
fn check_input(x: Vec<f64>){
if x.len() != Self::D {
panic!("A vector with size {} was used with a function of dimensionality {}.", x.len(), Self::D);
}
}
}