Пример #1
0
        public static Individual[] Combine(Individual mum, Individual dad)
        {
            Individual babyA;
            Individual babyB;

            Genom genomA;
            Genom genomB;

            genomA = new Genom(mum.Genom);
            genomB = new Genom(dad.Genom);

            if (mum != dad)
            {
                int genDistance = r.Next(mum.Genom.Gens.Count);

                for (int genIndex = genDistance; genIndex < mum.Genom.Gens.Count; genIndex++)
                {
                    double genA = genomA.Gens[genIndex];

                    genomA.Gens[genIndex] = genomB.Gens[genIndex];
                    genomB.Gens[genIndex] = genA;
                }
            }

            babyA = new Individual(genomA);
            babyB = new Individual(genomB);

            return(new Individual[] { babyA, babyB });
        }
Пример #2
0
        public static Genom Mutate(Genom genom, double rate, double strength)
        {
            Genom mutatedGenom = new Genom(genom);

            for (int genIndex = 0; genIndex < mutatedGenom.Gens.Count; genIndex++)
            {
                if (r.NextDouble() < rate)
                {
                    mutatedGenom.Gens [genIndex] += (r.NextDouble() - r.NextDouble()) * strength;
                }
            }

            return(mutatedGenom);
        }
Пример #3
0
 public Individual(Genom genom)
 {
     Fitness = 0;
     Genom   = genom;
 }
Пример #4
0
 public Individual(int genomSize)
 {
     Fitness = 0;
     Genom   = new Genom(genomSize, 3);
 }
Пример #5
0
 public Genom(Genom g)
 {
     Gens = new List <double>(g.Gens);
 }