use crate::island::topology::MigrationTopology;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MigrationPolicy {
#[default]
BestReplaceWorst,
RandomReplaceWorst,
TournamentMigrant,
RandomReplaceRandom,
}
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IslandConfiguration {
pub num_islands: usize,
pub migration_interval: usize,
pub migration_count: usize,
pub topology: MigrationTopology,
pub migration_policy: MigrationPolicy,
}
impl Default for IslandConfiguration {
fn default() -> Self {
IslandConfiguration {
num_islands: 4,
migration_interval: 10,
migration_count: 1,
topology: MigrationTopology::Ring,
migration_policy: MigrationPolicy::BestReplaceWorst,
}
}
}
impl IslandConfiguration {
pub fn new() -> Self {
Self::default()
}
pub fn with_num_islands(mut self, num_islands: usize) -> Self {
self.num_islands = num_islands;
self
}
pub fn with_migration_interval(mut self, interval: usize) -> Self {
self.migration_interval = interval;
self
}
pub fn with_migration_count(mut self, count: usize) -> Self {
self.migration_count = count;
self
}
pub fn with_topology(mut self, topology: MigrationTopology) -> Self {
self.topology = topology;
self
}
pub fn with_migration_policy(mut self, policy: MigrationPolicy) -> Self {
self.migration_policy = policy;
self
}
}