extern crate num;
pub mod genetic;
pub mod particleswarm;
pub mod tools;
pub trait Optimizer<T> {
fn find_min(&mut self) -> Option<(T, f64)>;
}
pub trait AlgorithmState<T> {
fn get_best_solution(&self) -> Option<(T, f64)>;
fn get_iteration(&self) -> usize;
}
pub trait AgentsState<T>: AlgorithmState<T> {
type Agent: Agent<T>;
fn get_agents(&self) -> Vec<&Self::Agent>;
}
pub trait Agent<T> {
fn get_parameter(&self) -> &T;
fn get_goal(&self) -> f64;
}
pub trait Goal<T> {
fn get(&self, x: &T) -> f64;
}
pub struct GoalFromFunction<T> {
function: fn(&T) -> f64,
}
impl<T> GoalFromFunction<T> {
pub fn new(function: fn(&T) -> f64) -> Self {
Self { function }
}
}
impl<T> Goal<T> for GoalFromFunction<T> {
fn get(&self, x: &T) -> f64 {
(self.function)(x)
}
}