mithi/rusty-genes

Swap Population Creation and Challenger Selection in run()

big-c-note opened this issue · 3 comments

https://github.com/mithi/rusty-genes/blob/rusty-genes/citydna/src/simulation.rs

        assert!(skip > 0, "skip must be 1 or larger");

        let mut population = random_population(self.population_size, &self.cities);
        let mut champion = find_fittest(&population);

        for i in 0..self.iterations {

            let challenger = find_fittest(&population);
            population = self.generate_population(population);
            debug_print(debug_level, skip, i + 1, &population, &champion, &challenger, self.number_of_cities);

            if champion.fitness <= challenger.fitness {
                champion = challenger;
            }
        }

        self.fitness = champion.fitness;
        self.dna = champion.dna;

        if debug_level >= 2 { self.print(); }
    }

You may want to swap let challenger = find_fittest(&population); and population = self.generate_population(population);

In that way you are getting the challenger from the newest generated population. As written, in the last iteration, you would be looking at the challenger from the previous iteration.

And, thank you for the helpful example in rust!

mithi commented

cool. sure ill do that. or if you'd like to open a pull request yourself, ill gladly merge it 😀

Of course, PR: #7