Exemplo n.º 1
0
 private void RandomizeGenome()
 {
     _genome.Clear();
     for (int i = 0; i < 100; i++)
     {
         _genome.Add(EvolutionHelper.randDouble(100));
     }
 }
Exemplo n.º 2
0
 private void GenrateCityMatrix()
 {
     cityMatrix.Clear();
     for (int i = 0; i < _size; i++)
     {
         cityMatrix.Add(new City(EvolutionHelper.randDouble(1000), EvolutionHelper.randDouble(1000)));
     }
 }
Exemplo n.º 3
0
        public void Mutate()
        {
            int randNumCitiesToFlip = EvolutionHelper.rand(100);

            for (int i = 0; i < randNumCitiesToFlip; i++)
            {
                int randIndex = EvolutionHelper.rand(100);
                _genome[randIndex] = EvolutionHelper.randDouble(100);
            }
        }
Exemplo n.º 4
0
 private void Mutate()
 {
     foreach (Solution s in solutionList)
     {
         if (EvolutionHelper.chance(EvolutionHelper.probabilityOfSolutionMutation))
         {
             s.Mutate();
         }
     }
 }
Exemplo n.º 5
0
        void Shuffle()
        {
            int n = solutionList.Count();

            while (n > 1)
            {
                n--;
                int      k     = EvolutionHelper.rand(n + 1);
                Solution value = solutionList[k];
                solutionList[k] = solutionList[n];
                solutionList[n] = value;
            }
        }
Exemplo n.º 6
0
        private void Mate(int start)
        {
            int cross1 = EvolutionHelper.rand(100);
            int cross2 = cross1;

            while (cross1 == cross2)
            {
                cross1 = EvolutionHelper.rand(100);
            }
            if (cross1 > cross2)
            {
                SwapInt(ref cross1, ref cross2);
            }

            Solution parent1 = solutionList[start];
            Solution parent2 = solutionList[start + 1];

            List <double> child1Tour = new List <double>();
            List <double> child2Tour = new List <double>();

            for (int i = 0; i < 100; i++)
            {
                if ((i < cross1) || (i > cross2)) // two point crossover
                //if (EvolutionHelper.randDouble(1) < .6) // uniform crossover
                {
                    child1Tour.Add(parent1.Genome[i]);
                    child2Tour.Add(parent2.Genome[i]);
                }
                else
                {
                    child1Tour.Add(parent2.Genome[i]);
                    child2Tour.Add(parent1.Genome[i]);
                }
            }

            solutionList[start + 2].Genome = child1Tour;
            solutionList[start + 3].Genome = child2Tour;

            _problem.EvaluateSolution(solutionList[start + 2]);
            _problem.EvaluateSolution(solutionList[start + 3]);
        }