private void CreateNewPairIndividuals(int indexTo, Individual firstIndividual, Individual secondIndividual) { for (int i = 0; i < indexTo; i++) { int secondIndividualPermutationElementAtCurrentIndexI = secondIndividual.Permutation.ElementAt(i); int[] hybridizationTmpArray = new int[indexTo]; Array.Copy(firstIndividual.Permutation, hybridizationTmpArray, indexTo); if (WasHere(hybridizationTmpArray, secondIndividualPermutationElementAtCurrentIndexI)) { Permutator.Swap(firstIndividual.Permutation, i, FindThisNumberInArray(firstIndividual.Permutation, secondIndividualPermutationElementAtCurrentIndexI)); Permutator.SwapBeetweenArrays(firstIndividual.Permutation, secondIndividual.Permutation, i); } } }
private void CreateNewRandomPopulation() { #region Create new defualt array {0,1,2,3,4,5, ... , dimension-1} int[] defaultArray = new int[Dimension]; for (int i = 0; i < Dimension; i++) { defaultArray[i] = i; } #endregion Create new defualt array {0,1,2,3,4,5, ... , dimension-1} for (int i = 0; i < POPULATION_SIZE; i++) { individuals.ElementAt(i).Permutation = Permutator.GetRandomPermutation(defaultArray); } }
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); } } } }