示例#1
0
        public void CalcFitness()
        {
            double totalDist = 0.0;

            for (int i = 0; i < ConfigurationGA.SizeChromosome; i++)
            {
                if (i < ConfigurationGA.SizeChromosome - 1)
                {
                    totalDist += TablePoints.GetDist(GetGene(i), GetGene(i + 1));
                }
                else
                {
                    totalDist += TablePoints.GetDist(GetGene(i), GetGene(0));
                }
            }
            SetFitness(totalDist);
        }
        //Calcular o fitness --- AQUI TAMBÉM ENCONTRA-SE A FUNÇÃO DE AVALIAÇÃO ( DENOMINADA FITNESS )
        public void CalcFitness()
        {
            double totalDist = 0.0;

            for (int i = 0; i < ConfigurationGA.tamCromossomo; i++)
            {
                if (i < (ConfigurationGA.tamCromossomo - 1))
                {
                    //Envia o gene i e o gene i + 1 que será somado dentro da função GetDist, após isso retornamos o valor e somamos a totalDist
                    totalDist += TablePoints.getDist(GetGene(i), GetGene(i + 1));
                }
                else
                {
                    //Conforme o problema do TSP após chegar ao ultimo ponto ele volta para origem
                    totalDist += TablePoints.getDist(GetGene(i), GetGene(0));
                }
            }

            //Altera o fitness
            SetFitness(totalDist);
        }
示例#3
0
        public void PlotarCoordenadas()
        {
            string frase;
            string palavra = "NODE_COORD_SECTION";

            TablePoints.clear();


            for (int i = 0; i < linha.Count; i++)
            {
                if (linha[i].Contains(palavra))
                {
                    frase = linha[i];


                    string[] indicePalavra = frase.Split();
                    Console.WriteLine(indicePalavra[indicePalavra.Length - 1]);

                    for (int x = i + 1; x < linha.Count; x++)
                    {
                        if (linha[x].Contains("EOF"))
                        {
                        }
                        else
                        {
                            frase         = linha[x];
                            indicePalavra = frase.Split();

                            int ponto = Convert.ToInt32(indicePalavra[0]);
                            int cx    = Convert.ToInt32(indicePalavra[1]);
                            int cy    = Convert.ToInt32(indicePalavra[2]);
                            TablePoints.AddPoint(cx, cy);
                        }
                    }
                }
            }
        }