Ejemplo n.º 1
0
        public Chromosome(Genotype genotype)
        {
            Genotype = genotype;

            _genes = new Gene[Genotype.GeneCount];

            for (int i = 0; i < Genotype.GeneCount; i++)
            {
                _genes[i] = Gene.RandomGene(Genotype.GeneLength);
            }
        }
Ejemplo n.º 2
0
        public void Mutate()
        {
            int locus1 = _random.Next(0, Genotype.GeneCount);
            int locus2 = _random.Next(0, Genotype.GeneCount);

            Gene gene1 = _genes[locus1];
            Gene gene2 = _genes[locus2];

            switch (Genotype.MutationType)
            {
            case MutationType.Random:
                _genes[locus1] = Gene.RandomGene(Genotype.GeneLength);
                _genes[locus1].SetMutation();
                break;

            case MutationType.Swap:
                _genes[locus1] = gene2;
                _genes[locus2] = gene1;

                _genes[locus1].SetMutation();
                _genes[locus2].SetMutation();
                break;
            }
        }