use std::marker::PhantomData;
use burn::tensor::{backend::Backend, Int, Tensor};
use rand::Rng;
use crate::strategy::{Strategy, StrategyMetrics};
#[derive(Debug, Clone)]
pub struct AcoPermConfig {
pub pop_size: usize,
pub n_nodes: usize,
pub rho: f32,
pub alpha: f32,
pub beta: f32,
}
impl AcoPermConfig {
#[must_use]
pub fn default_for(pop_size: usize, n_nodes: usize) -> Self {
Self {
pop_size,
n_nodes,
rho: 0.5,
alpha: 1.0,
beta: 2.0,
}
}
}
#[derive(Debug, Clone)]
pub struct AcoPermState<B: Backend> {
_backend: PhantomData<fn() -> B>,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct AntColonyPermutation<B: Backend> {
_backend: PhantomData<fn() -> B>,
}
impl<B: Backend> AntColonyPermutation<B> {
#[must_use]
pub fn new() -> Self {
Self {
_backend: PhantomData,
}
}
}
impl<B: Backend> Strategy<B> for AntColonyPermutation<B> {
type Params = AcoPermConfig;
type State = AcoPermState<B>;
type Genome = Tensor<B, 2, Int>;
fn init(
&self,
_params: &AcoPermConfig,
_rng: &mut dyn Rng,
_device: &B::Device,
) -> AcoPermState<B> {
todo!(
"permutation ACO is not yet implemented; \
use AntColonyReal for continuous problems in the meantime"
)
}
fn ask(
&self,
_params: &AcoPermConfig,
_state: &AcoPermState<B>,
_rng: &mut dyn Rng,
_device: &B::Device,
) -> (Self::Genome, AcoPermState<B>) {
todo!("permutation ACO is not yet implemented")
}
fn tell(
&self,
_params: &AcoPermConfig,
_population: Self::Genome,
_fitness: Tensor<B, 1>,
_state: AcoPermState<B>,
_rng: &mut dyn Rng,
) -> (AcoPermState<B>, StrategyMetrics) {
todo!("permutation ACO is not yet implemented")
}
fn best(&self, _state: &AcoPermState<B>) -> Option<(Self::Genome, f32)> {
None
}
}
#[cfg(test)]
mod tests {
use super::*;
use burn::backend::NdArray;
type TestBackend = NdArray;
#[test]
fn stub_is_constructible() {
let _strategy = AntColonyPermutation::<TestBackend>::new();
let _params = AcoPermConfig::default_for(32, 20);
}
#[test]
#[should_panic(expected = "permutation ACO is not yet implemented")]
fn init_panics_with_clear_message() {
use rand::SeedableRng;
let strategy = AntColonyPermutation::<TestBackend>::new();
let params = AcoPermConfig::default_for(4, 5);
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
let _ = strategy.init(¶ms, &mut rng, &Default::default());
}
}