~ruther/ctu-fee-eoa

038f5f6ceb88eac60cdbd3b6cbda7ed975cc8073 — Rutherther a month ago fa9a5af
refactor: use swap_rows in SwapPerturbaiton instead of swapping by indices
1 files changed, 9 insertions(+), 10 deletions(-)

M codes/tsp_hw01/src/tsp.rs
M codes/tsp_hw01/src/tsp.rs => codes/tsp_hw01/src/tsp.rs +9 -10
@@ 229,6 229,12 @@ pub struct SwapPerturbation<D> {
    _phantom: PhantomData<D>
}

impl<D> SwapPerturbation<D> {
    pub fn new() -> Self {
        Self { _phantom: PhantomData }
    }
}

impl<D> PerturbationOperator for SwapPerturbation<D>
where
    D: Dim,


@@ 238,15 244,8 @@ where
    type Chromosome = NodePermutation<D>;

    fn perturb(&self, chromosome: &mut Self::Chromosome, rng: &mut dyn RngCore) {
        let first = rng.random_range(0..=chromosome.permutation.len());
        let second = rng.random_range(0..=chromosome.permutation.len());

        (
            chromosome.permutation[first],
            chromosome.permutation[second]
        ) = (
            chromosome.permutation[second],
            chromosome.permutation[first]
        );
        let first = rng.random_range(0..chromosome.permutation.len());
        let second = rng.random_range(0..chromosome.permutation.len());
        chromosome.permutation.swap_rows(first, second);
    }
}