Пример #1
0
        /// <summary>
        /// Toggles the frozen status of a single gene if possible.
        /// </summary>
        /// <param name="genome">The genome to be mutated.</param>
        /// <param name="rando">A random number generator.</param>
        public static void MutateToggleFreeze(Genome genome, Random rando)
        {
            int  geneId = rando.Next(genome.Size());
            Gene gene   = genome.Genes[geneId];

            gene.Frozen = !gene.Frozen;

            if (!genome.Validate(true))
            {
                gene.Frozen = !gene.Frozen;
            }
        }
Пример #2
0
        /// <summary>
        /// Unfreezes a random frozen gene if possible.
        /// </summary>
        /// <param name="genome">The genome to be mutated.</param>
        /// <param name="rando">A random number generator.</param>
        public static void MutateUnFreeze(Genome genome, Random rando)
        {
            List <Gene> possibilities = genome.Genes.Where(x => x.Frozen).ToList();

            if (possibilities.Count == 0)
            {
                return;
            }

            int  possibleId = rando.Next(possibilities.Count);
            Gene gene       = possibilities[possibleId];

            gene.Frozen = false;

            if (!genome.Validate(true))
            {
                gene.Frozen = !gene.Frozen;
            }
        }