Exemplo n.º 1
0
        //cria um indivíduo com os genes definidos
        public Individuo(String genes)
        {
            this.genes = genes;

            Random r = new Random();

            //se for mutar, cria um gene aleatório
            if (r.NextDouble() <= Algoritmo.getTaxaDeMutacao())
            {
                String caracteres   = Algoritmo.getCaracteres();
                String geneNovo     = "";
                int    posAleatoria = r.Next(genes.Length);
                for (int i = 0; i < genes.Length; i++)
                {
                    if (i == posAleatoria)
                    {
                        geneNovo += caracteres[(r.Next(caracteres.Length))];
                    }
                    else
                    {
                        geneNovo += genes[i];
                    }
                }
                this.genes = geneNovo;
            }
            geraAptidao();
        }
Exemplo n.º 2
0
        //gera um indivíduo aleatório
        public Individuo(int numGenes)
        {
            genes = "";
            Random r = new Random();

            String caracteres = Algoritmo.getCaracteres();

            for (int i = 0; i < numGenes; i++)
            {
                genes += caracteres[(r.Next(caracteres.Length))];
            }

            geraAptidao();
        }