5 Unit
5 Unit
Reproduction Competition
Survive Selection
1. The fitness function should be clearly defined. The reader should be able to
clearly understand how the fitness score is calculated.
2. The fitness function should be implemented efficiently. If the fitness function
becomes the bottleneck of the algorithm, then the overall efficiency of the
genetic algorithm will be reduced.
3. The fitness function should quantitatively measure how fit a given solution is
in solving the problem.
4. The fitness function should generate intuitive results. The best/worst
candidates should have best/worst score values.
This week we were challenged to solve The Travelling Salesman Problem using a
genetic algorithm. The exact application involved finding the shortest distance to
fly between eight cities without visiting a city more than once. The table below
shows the distances between each city in kilometers.
Initialization
Upon initialization, each individual creates a permutation featuring an integer
representation of a route between the eight cities with no repetition featured. A
corresponding array with the string equivalent of these indexes is created to
output when a solution is found.
A fitness function calculates the total distance between each city in the
chromosome’s permutation. For example, in the ordering above, the distance
between the cities represented by ‘0’ and ‘4’ is added to an overall sum, then the
distance between the cities represented by ‘4’ and ‘1’ is added, and so on. The
chromosome’s fitness is set to the overall sum of all distances within the
Selection
There are two popular methods to apply when performing selection in genetic
algorithms, roulette wheel selection and tournament selection. Both use
probability to create bias in choosing fitter chromosomes to serve as the parents.
[0.3, 0.25, 0.2, 0.15, 0.1] --> [0, 0.3, 0.55, 0.75, 0.9, 1]
Crossover
As the solution requires that no city to be visited more than once, using a classical
crossover operator may often lead to generating weaker offspring. A conventional
crossover operator may select one half to copy from the first section and the
remaining half to copy from the second. This does not prevent copying duplicate
cities into the offspring chromosome and will result in a penalty for visiting the
same city more than once. However, using the order 1 approach helps to preserve
the non-repeating feature of the parent chromosomes. To create the first child,
copy part of the first parent’s chromosome to the child’s chromosome. Then
choose valid non-repeating numbers from the second parent in the order that
they appear to the empty values in the child’s chromosome. To create the
chromosome for the second child, repeat this process inversely by copying part of
the second parent’s chromosome and using valid values from the first parent for
the remaining values.
Mutation
Modalities
Genetic algorithms have two modalities, steady-state and generational. Steady-
state utilizes an elitist selection process in which the best n chromosomes are of
the population are carried over to the next generation. By keeping the best-ranked
chromosome, this implementation does not risk losing it’s best solution so
far .Generational does not utilize this approach and instead only carries over any
offspring produced in the crossover phase.
Comparison
The four variations are noted in the results as:
Each variation was tested 50 times and the minimum, maximum, and average
number of generations needed to reach the solution was recorded. The same
mutation rate of 0.15 and population size of 25 was used for each implementation.
However, the stochastic aspect of the mutation threshold and selection process
removes consistency from the performance of GA. Another fifty tests may yield
entirely different results for each variation that may be more expected or entirely
contradict what would be logically assumed. However, if these results do
accurately describe the behavior of the variations, the steady-state approach and
tournament selection method may benefit in more creative applications, where
exploration and a slow convergence may demonstrate an auditory or artistic
process. Overall, considering the total size of the search space mentioned in the
introduction, the genetic algorithm serves well in finding a solution in a relatively
small number of generations.