Heuristics: Genetic Algorithm 2

Aus Operations-Research-Wiki
Wechseln zu: Navigation, Suche

Introduction

Genetic Algorithm are good at taking large, potentially huge search spaces and navigating them, looking for optimal combinations of things, solutions you might otherwise find in a lifetime (Salvatore Mangano, Computer Design, May 1995)

The solution that you get from a genetic algorithm is the result of the iteratively application of different stochastic operators.


For understanding GA and how they work, we have to introduce some new vacabulary:

individual =a strucuture, that represents a solution, consisting of genes

chromosome =equal to individual

gene =a bit of the binary representation of a solution

population =quantity of individuals, that became considered by an GA

parents =two chosen individuals of a population

crossing =combination of two genes from two chromosomes

mutation =modification of a chromosome

fitness =qualtity of a solution

generation =one iteration in the duration of the optimation

genotype =coded solution of a problem

phenotype =decoded solution of a problem


Basically the strucure of Genetic Algorithm is always the same presented below

  1. produce an initial population of indivuals
  2. evaluate the fitness of all individuals
  3. WHILE termination condition not met DO
    1. select fitter individuals for reproduction
    2. recombine between individuals
    3. mutate individuals
    4. evaluate the fitness of the modified individuals
    5. generate a new population
  4. END WHILE

Examples

We want to visit 6 cities and every city just once.

The distances between the cities are given in the following tableau.

We want to minimize the distance.


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): \begin{array}{|c||c|c|c|c|c|c|} \hline & 1 & 2 & 3 & 4 & 5 & 6\\ \hline \hline 1 & - & 4 & 2 & 10 & 8 & 7\\ \hline 2 & & - & 5 & 7 & 9 & 2\\ \hline 3 & & & - & 3 & 5 & 9\\ \hline 4 & & & & - & 1 & 5\\ \hline 5 & & & & & - & 4\\ \hline 6 & & & & & & -\\ \hline \end{array}


We have an initial parents generation given by the following three route alternatives:


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (1) \ \ 3-4-1-5-2-6


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (2) \ \ 2-6-3-1-4-5


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (3) \ \ 1-5-2-3-6-4


The reproduction rate of the parents´pool is 1/3. The reproduction rate of the children´s pool is 2/3.

The recombination takes place in the following (chosen randomly) order:

(1)->(2), (1)->(3), (3)->(2)

The algorithm stops after the second generation.


a) Partially-Matched Crossover (PMX)


The length of the sequence is given by 2.


(1)->(2)


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (1) \ \ 3-4-1-\color{red}5\color{black}-\color{red}2\color{black}-6


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (2) \ \ 2-6-3-\color{green}1\color{black}-\color{green}4\color{black}-5


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (4) \ \ \color{green}4\color{black}-6-3-\color{red}5\color{black}-\color{red}2\color{black}-\color{green}1


The first recombination process [(1)->(2)] starts at gene 4 (randomly chosed). This means we cut out gene 4 and 5 of parent 1 (red marked).

So 5 becomes the 4th gene and 2 the 5h element of the child (red marked).

Now we have to take gene 4 and 5 of parent 2 (green marked).

The green marked 1 of parent 2 has to be placed under 5 of parent 2, because the green marked 1 of parent 2 stands below the 5 of parent 1.

The green marked 4 of parent 2 has to be placed under 2 of parent 2, because the green marked 4 of parent 2 stands below the 2 of parent 1.

At the end we have to fill up gene 2 and 3 of the child with gene 2 and 3 of parent 2 to get an new individual without a number twice.


(1)->(3)


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (1) \ \ \color{red}3\color{black}-\color{red}4\color{black}-1-5-2-6


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (3) \ \ \color{green}1\color{black}-\color{green}5\color{black}-2-3-6-4


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (5) \ \ \color{red}3\color{black}-\color{red}4\color{black}-2-\color{green}1\color{black}-6-\color{green}5


The second recombination process [(1)->(3)] starts at gene 1 (randomly chosed). This means we cut out gene 1 and 2 of parent 1.


(3)->(2)

Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (3) \ \ 1-\color{red}5\color{black}-\color{red}2\color{black}-3-6-4


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (2) \ \ 2-\color{green}6\color{black}-\color{green}3\color{black}-1-4-5


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): (6) \ \ \color{green}3\color{black}-\color{red}5\color{black}-\color{red}2\color{black}-1-4-\color{green}6


The third recombination process [(3)->(2)] starts at gene 2. This means we cut out gene 2 and 3 of parent 3.


Now we have to calculate the fitness of the parents and children.


Parent (1) :

Parent (2) :

Parent (3) :

Child (4)  :

Child (5)  :

Child (6)  :


The reproduction rate of the parents´ pool is 1/3. So we pick out parent 2, because we want to minimize the distance.

The reproduction rate of the childrens´ pool is 2/3. So we pick out Child 4 and 5.

So the second generation consists of parent 2 and child 4 and 5.


The Maxone problem:

We want to maximize the number of ones in a string of L binary bits.

This may seem to trivial, cause we know already the answer, but however, we can think of it as maximazing the number of correct answers, each encoded by 1, to difficult questions:

Suppose l=10, n=6

Cause everey individual is encoded as a string of l binary bit, we can write for one

1=0000000001 (10 bits)


To get the initial population, we toss a fair coin 60 times:


Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): \color{red}\sum_{i=1}^{6}f(s_i)=34


while f(s) is the fitness function


The new population after performing selection (suppose we apply a random generator and get this selection).



You can determine the probability for a crossover, for instance 0,6.

Thus we only perform a crossover for the pairs and


Crossover-points: 2 and 5


Before crossover:


After crossover:


Before applying random mutation:

For each bit, that we are to copy to the new population, we allow a small probability of error, for instance 0,1.



After applying mutation (random) with updated fitness-values:

Fehler beim Parsen (http://mathoid.testme.wmflabs.org Serverantwort ist ungültiges JSON.): \sum_{i=1}^{6}f(s_i''')=37



Improvement of 9 percent (fitness from 34 to 37)

You could repeat the algorithm, until a stopping criterion is met.

References

Nobal Niraula, Genetic Algorithm: http://de.slideshare.net/kancho/genetic-algorithm-by-example (download: 24.06.13)

Alfred Hermes, Heuristik: Genetischer Algorithmus am Beispiel des 0/1-Rucksackproblems: http://learntech.rwth-aachen.de/lehre/ss05/fdi/folien/VS11HTML/GenAlg.pdf (download: 24.06.13)