#[derive(Debug, Clone)]
pub struct Particle {
pub position: Vec<f64>,
pub velocity: Vec<f64>,
pub best_position: Vec<f64>,
pub best_value: f64,
}
impl Particle {
pub fn new(position: Vec<f64>, velocity: Vec<f64>, value: f64) -> Self {
Self {
best_position: position.clone(),
best_value: value,
position,
velocity,
}
}
}
#[derive(Debug, Clone)]
pub struct Swarm {
pub particles: Vec<Particle>,
}
impl Swarm {
pub fn new(particles: Vec<Particle>) -> Self {
Self { particles }
}
pub fn len(&self) -> usize {
self.particles.len()
}
pub fn is_empty(&self) -> bool {
self.particles.is_empty()
}
}