public Chromosome[] reproduce(Chromosome[] intermediate)
        {
            Rand = new Random();
            Crossover crossover = new Crossover();
            Mutation mutator = new Mutation();

            foreach (Chromosome c in intermediate)
            {
                int value = Rand.Next(0, 10);
                if (0.1 * value < crossoverRate)
                {
                    crossover.evolve(c, null);
                }
            }

            foreach (Chromosome c in intermediate)
            {
                int value = Rand.Next(0, 10);
                if (0.1 * value < mutationRate)
                {
                    mutator.mutate(c);
                }
            }

            return intermediate;
        }
        private string generateCipherText(Chromosome c)
        {
            char[] ciphertext = new char[340];

            foreach (char allele in c.Alleles)
            {
                int i = 0;
                foreach (int letter in Cipher.Cipher[i])
                {
                    ciphertext[letter-1] = allele;
                }
                i++;
            }
            return ciphertext.ToString();
        }
        public Fitness(Chromosome[] population, Z340 cipher)
        {
            Population = population;
            Cipher = cipher;

            Search = new ngram[10];
            Search[0] = new ngram("th", 2);
            Search[1] = new ngram("he", 1);
            Search[2] = new ngram("in", 1);
            Search[3] = new ngram("er", 1);
            Search[4] = new ngram("an", 1);
            Search[5] = new ngram("ed", 1);
            Search[6] = new ngram("the", 5);
            Search[7] = new ngram("ing", 5);
            Search[8] = new ngram("and", 5);
            Search[9] = new ngram("eee", -5);
        }
        public Chromosome[] GeneratePopulation()
        {
            Population = new Chromosome[popSize];
            char[] values = new char[ChromosomeLength];;
            R = new Random();

            for(int i = 0; i<popSize; i++)
            {
                values = new char[ChromosomeLength];

                for (int j = 0; j < ChromosomeLength; j++)
                {
                    values[j] = GenerateValue();
                }

                Population[i] = new Chromosome(values);
            }

            return Population;
        }
 public Chromosome mutate(Chromosome c)
 {
     return new Chromosome(null);
 }
 public Selection(Chromosome[] Population )
 {
     population = Population;
 }
 public Chromosome evolve(Chromosome alpha, Chromosome beta)
 {
     return new Chromosome(null);
 }
Esempio n. 8
0
 public Chromosome evolve(Chromosome alpha, Chromosome beta)
 {
     return(new Chromosome(null));
 }