pub struct TernaryPopulation {
pub agents: Vec<TernaryAgent>,
pub strategy_len: usize,
}Expand description
A population of ternary agents.
Fields§
§agents: Vec<TernaryAgent>§strategy_len: usizeStrategy vector length (constant across the population).
Implementations§
Source§impl TernaryPopulation
impl TernaryPopulation
Sourcepub fn new(agents: Vec<TernaryAgent>) -> Option<Self>
pub fn new(agents: Vec<TernaryAgent>) -> Option<Self>
Create a new population from a list of agents.
Returns None if agents have mismatched strategy lengths or the list is empty.
Sourcepub fn random(n: usize, strategy_len: usize) -> Self
pub fn random(n: usize, strategy_len: usize) -> Self
Create a random population of n agents, each with strategy_len ternary values.
Sourcepub fn random_seeded(n: usize, strategy_len: usize, seed: u64) -> Self
pub fn random_seeded(n: usize, strategy_len: usize, seed: u64) -> Self
Create a random population with a given seed for reproducibility.
Sourcepub fn sort_by_fitness(&mut self)
pub fn sort_by_fitness(&mut self)
Sort agents by fitness descending (natural selection = sort).
Sourcepub fn best(&self) -> &TernaryAgent
pub fn best(&self) -> &TernaryAgent
Get the best agent.
Sourcepub fn avg_fitness(&self) -> f64
pub fn avg_fitness(&self) -> f64
Get the average fitness.
Sourcepub fn worst(&self) -> &TernaryAgent
pub fn worst(&self) -> &TernaryAgent
Get the worst agent.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TernaryPopulation
impl RefUnwindSafe for TernaryPopulation
impl Send for TernaryPopulation
impl Sync for TernaryPopulation
impl Unpin for TernaryPopulation
impl UnsafeUnpin for TernaryPopulation
impl UnwindSafe for TernaryPopulation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more