Exemplo n.º 1
0
        public static Genome breed(Genome mum, Genome dad, double mutationPercent)
        {
            Genome child = new Genome();
            child.BlankGenome();

            int coPoint = G.rnd.Next(0, G.genomeLen);

            for (int i = 0; i < coPoint; i++)
            {
                child.dna[i] = mum.GetGene(i);
            }

            for (int i = coPoint; i < G.genomeLen; i++)
            {
                child.dna[i] = dad.GetGene(i);
            }

            if (G.rnd.NextDouble() * 100 < mutationPercent)
                child = child.Mutate(child);

            return child;
        }
Exemplo n.º 2
0
 public void setupPop()
 {
     for (int i=0; i<numInPop; i++)
     {
         pp[i] = new Genome();
         pp[i].RandomGenome();
     }
 }
Exemplo n.º 3
0
        public Genome Mutate(Genome child)
        {
            child.mutant = true;

            int mutstrat = 1;

            if (G.mutStrat == "MutStrat1")
                mutstrat = 1;

            if(G.mutStrat == "MutStrat2")
                mutstrat = 2;

            if (G.mutStrat == "MutStrat3")
                mutstrat = 3;

            if (G.mutStrat == "MutStrat4")
                mutstrat = 4;

            if (G.mutStrat == "MutStrat1&2")
                mutstrat = G.rnd.Next(1, 3);

            if (G.mutStrat == "MutStrat1&3")
            {
                mutstrat = G.rnd.Next(1, 3);
                if (mutstrat == 2)
                    mutstrat = 3;
            }

            if (G.mutStrat == "MutStrat2&3")
                mutstrat = G.rnd.Next(2, 3);

            if (G.mutStrat == "MutStrat1&2&3")
                mutstrat = G.rnd.Next(1, 4);

            if (G.mutStrat == "All")
                mutstrat = G.rnd.Next(1, 5);

            switch(mutstrat)
            {
                case 1:
                    MutStrat1();
                    break;
                case 2:
                    MutStrat2();
                    break;
                case 3:
                    MutStart3();
                    break;
                case 4:
                    MutStrat4();
                    break;
            }

            return child;
        }