Mark As Completed Discussion

Matting selection

To perform crossover, it is required to first construct the matting pool that will contain the best solutions to take part in the crossover operator. The number of parents will be decided by the mattingPoolSize variable.

PYTHON
1# Following statement will create an empty two dimensional array to store parents
2parents = numpy.empty((mattingPoolSize, population.shape[1]))
3
4# A loop to extract one parent in each iteration
5for p in range(mattingPoolSize):
6        # Finding index of fittest chromosome in the population
7        fittestIndex = numpy.where(fitness == numpy.max(fitness))
8        # Extracting index of fittest chromosome
9        fittestIndex = fittestIndex[0][0]
10        # Copying fittest chromosome into parents array
11        parents[p, :] = population[fittestIndex, :]
12        # Changing fitness of fittest chromosome to avoid reselection of that chromosome 
13        fitness[fittestIndex] = -1