private void CreateNewIndividuals(int pivot) { int halfPopulation = POPULATION_SIZE / 2; for (int i = 0; i < halfPopulation; i += 2) { int randomNumber = random.Next(MAX_PROBABILITY); if (HYBRIDIZATION_PROBABILITY > randomNumber) { CreateNewPairIndividuals(pivot, individuals.ElementAt(i), individuals.ElementAt(i + 1)); } #region Recount cost for changed permutation individuals.ElementAt(i).Fitnes = CostCounter.CountCost(individuals.ElementAt(i).Permutation); individuals.ElementAt(i + 1).Fitnes = CostCounter.CountCost(individuals.ElementAt(i + 1).Permutation); #endregion Recount cost for changed permutation } }
private void DoMutation() { for (int i = 0; i < POPULATION_SIZE; i++) { Individual tmp = individuals.ElementAt(i); for (int j = 0; j < Dimension; j++) { int randomNumber = random.Next(MAX_PROBABILITY); if (MUTATION_PROBABILITY > randomNumber) { int randomIndex = random.Next(Dimension); while (j == randomIndex) { randomIndex = random.Next(Dimension); } //MUTATE Permutator.Swap(tmp.Permutation, j, randomIndex); tmp.Fitnes = CostCounter.CountCost(tmp.Permutation); } } } }