Vous êtes sur la page 1sur 10

GA Demystified

Workshop on Soft and Evolutionary Computing Indian Institute of Space Science and Technology 19-21 December 2011

Genetic Algorithm

Compute the maximum value of the function y=Sin(x)

Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 1 : Initialization (Population Size : 10) 1
0 1
.. 1

2
0 1
.. 0

3
1 0
.. 0

4
1 1
.. 1

5
0 1
.. 1

6
1 1
.. 0

7
0 1
.. 1

8
1 0
.. 0

10

11

pop_size=10; population=rand(pop_size,8)-0.5; population=hardlim(population);

Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 2 : Function Evaluation 1
0 1
.. 1

2
0 1
.. 0

3
1 0
.. 0

4
1 1
.. 1

5
0 1
.. 1

6
1 1
.. 0

7
0 1
.. 1

8
1 0
.. 0

9
53 222
.. 154

10

11

.. population=hardlim(population); population(:,9)=bin2dec(num2str(population(:,1:8))); ..

Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 2 : Function Evaluation 1
0 1
.. 1

2
0 1
.. 0

3
1 0
.. 0

4
1 1
.. 1

5
0 1
.. 1

6
1 1
.. 0

7
0 1
.. 1

8
1 0
.. 0

9
53 222
.. 154

10
-1.84 2.33
.. 0.65

11
-0.96 0.73
.. 0.61

.. population(:,9)=bin2dec(num2str(population(:,1:8))); population(:,10)=((population(:,9))/255-0.5)*2*pi; population(:,11)=sin(population(:,10)); ..


Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 3 : Selection (Tournament Selection) 1
0 1
.. 1

2
0 1
.. 0

3
1 0
.. 0

4
1 1
.. 1

5
0 1
.. 1

6
1 1
.. 0

7
0 1
.. 1

8
1 0
.. 0

9
53 222
.. 154

10
-1.84 2.33
.. 0.65

11
-0.96 0.73
.. 0.61

.. population(:,11)=sin(population(:,10)); pop1=ceil(rand*pop_size); pop2=ceil(rand*pop_size); ..


Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 3 : Selection (Tournament Selection) 1
0 1
.. 1

2
0 1
.. 0

3
1 0
.. 0

4
1 1
.. 1

5
0 1
.. 1

6
1 1
.. 0

7
0 1
.. 1

8
1 0
.. 0

9
53 222
.. 154

10
-1.84 2.33
.. 0.65

11
-0.96 0.73
.. 0.61

.. pop2=ceil(rand*pop_size); parent1=population(pop1,:); parent2=population(pop2,:); ..


Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 4 : Crossover (Single point) 1
1

2
0

3
0

4
1

5
1

6
0

7
1

8
0

10

11

.. parent2=population(pop2,:); cross_loc=ceil(rand*8); ..

Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 4 : Crossover (Single point) 1
1

2
0

3
0

4
1

5
1

6
1

7
0

8
1

10

11

.. cross_loc=ceil(rand*8); child1=[parent1(1:cross_loc-1) parent2(cross_loc:8)]; child2=[parent2(1:cross_loc-1) parent1(cross_loc:8)]; ..


Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Genetic Algorithm
Step 4 : Crossover (Single point) 1
1

2
0

3
0

4
1

5
1

6
1

7
0

8
1

10

11

.. cross_loc=ceil(rand*8); child1=[parent1(1:cross_loc-1) parent2(cross_loc:8)]; child2=[parent2(1:cross_loc-1) parent1(cross_loc:8)]; ..


Workshop on Soft and Evolutionary Computing, IIST, 19-21 December 2011

Vous aimerez peut-être aussi