extern crate num;
pub mod genetic;
pub mod particleswarm;
pub mod tools;
type GoalValue = f64;
type Solution<T> = (T, GoalValue);
pub trait Optimizer<T> {
fn find_min(&mut self) -> Option<Solution<T>>;
}
pub trait IterativeOptimizer<T> {
fn next_iterations(&mut self) -> Option<Solution<T>>;
}
pub trait AlgorithmState<T> {
fn get_best_solution(&self) -> Option<Solution<T>>;
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) -> GoalValue;
}
pub trait Goal<T> {
fn get(&mut self, x: &T) -> GoalValue;
}
pub struct GoalFromFunction<T> {
function: fn(&T) -> GoalValue,
}
impl<T> GoalFromFunction<T> {
pub fn new(function: fn(&T) -> GoalValue) -> Self {
Self { function }
}
}
impl<T> Goal<T> for GoalFromFunction<T> {
fn get(&mut self, x: &T) -> GoalValue {
(self.function)(x)
}
}