use std::marker::PhantomData; use nalgebra::{allocator::Allocator, DefaultAllocator, Dim, OVector, U1}; use rand::{prelude::SliceRandom, RngCore}; use eoa_lib::initializer::Initializer; use crate::tsp::NodePermutation; pub struct TSPRandomInitializer where D: Dim, DefaultAllocator: Allocator, { _phantom: PhantomData } impl TSPRandomInitializer where D: Dim, DefaultAllocator: Allocator, { pub fn new() -> Self { Self { _phantom: PhantomData } } } impl Initializer> for TSPRandomInitializer where D: Dim, DefaultAllocator: Allocator, DefaultAllocator: Allocator, { fn initialize_single(&self, size: D, rng: &mut dyn RngCore) -> NodePermutation { let len = size.value(); let mut indices = OVector::::from_iterator_generic(size, U1, 0..len); indices.as_mut_slice().shuffle(rng); NodePermutation { permutation: indices } } }