Esempio n. 1
0
    /// <summary>
    /// Runs the mutation alogorithm through a genome with the given parameters.
    /// </summary>
    private void MutateGenome(Genome g, float topologyMutationChancePerGenome, float weightMutationChancePerGenome, bool multipleMutationsPerGenomeAllowed, float reducationFactor, MutationInformation info)
    {
        // If the genome has no connections, it can only mutate topology
        if (g.EnabledConnections.Count() == 0)
        {
            topologyMutationChancePerGenome += weightMutationChancePerGenome;
            weightMutationChancePerGenome    = 0;
        }

        double rng = Random.NextDouble();

        int numMutations = 0;

        while (rng <= ((topologyMutationChancePerGenome + weightMutationChancePerGenome) * (Math.Pow(1 - reducationFactor, numMutations))))
        {
            if (rng <= topologyMutationChancePerGenome)
            {
                TopologyMutatedGenomes.Add(g);
                TopologyMutator.MutateTopology(g, info, NewNodeMutations, NewConnectionMutations);
            }
            else
            {
                WeightMutatedGenomes.Add(g);
                WeightMutator.MutateWeight(g, info);
            }
            numMutations++;
            rng = multipleMutationsPerGenomeAllowed ? Random.NextDouble() : 1; // Allows for multiple mutations per genome
        }
    }
Esempio n. 2
0
 private void MutateWeight(GenomeVisualizer gv, Genome g)
 {
     if (g != null)
     {
         WeightMutator.MutateWeight(g, null);
         gv.VisualizeGenome(g, false, true);
     }
 }