use std::fmt::{Debug, Formatter, Result as FmtResult};
#[derive(Clone)]
pub struct Candidate<S: Clone + Send + Sync + 'static> {
pub solution: S,
pub fitness: f64,
}
impl<S: Clone + Send + Sync + 'static> Candidate<S> {
pub fn new(solution: S, fitness: f64) -> Candidate<S> {
Candidate {
solution: solution,
fitness: fitness,
}
}
}
impl<S: Clone + Send + Sync + 'static> Debug for Candidate<S>
where S: Debug
{
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "[{}] {:?}", self.fitness, self.solution)
}
}
pub struct WorkingCandidate<S: Clone + Send + Sync + 'static> {
pub candidate: Candidate<S>,
retries: i32,
}
impl<S: Clone + Send + Sync + 'static> WorkingCandidate<S> {
pub fn new(candidate: Candidate<S>, retries: usize) -> WorkingCandidate<S> {
WorkingCandidate {
candidate: candidate,
retries: retries as i32,
}
}
pub fn expired(&self) -> bool {
self.retries <= 0
}
pub fn deplete(&mut self) {
self.retries -= 1;
}
}