Analysis to implementation
PART 1:
f(ch) = (x0 + x1) − (x2 + x3) + (x4 + x5 ) − (x6 + x7)
This problem is a maximisation problem.
In this scenario we initially have a population of four chromosomes as shown below:
- ch1 = (6, 5, 4, 1, 3, 5, 3, 2)
- ch2 = (8, 7, 1, 2, 6, 6, 0, 1)
- ch3 = (2, 3, 9, 2, 1, 2, 8, 5)
- ch4 = (4, 1, 8, 5, 2, 0, 9, 4)
// fitness calculations
Ch1 = f(ch) = ( 6 + 5 ) - (4 + 1 ) + ( 3 + 5 ) - ( 3 + 2 ) = 9
Ch2 = f(ch) = ( 8 + 7 ) - (1 + 2 ) + (6 + 6 ) - (0 + 1 ) = 23
Ch3 = f(ch) = ( 2 + 3 ) - (9 + 2 ) + (1 + 2 ) - (8 + 5 ) = -16
Ch4 = f(ch) = ( 4 + 1 ) - (8 + 5 ) + (2 + 0 ) - (9 + 4 ) = -19
Sort:
- Ch2 ( 23 )
- Ch1 ( 9 )
- Ch3 ( - 16 )
- Ch4 ( - 19 )
1 )
- child1 = ( 6, 5, 4, 1 | 6, 6, 0, 1 )
- child2 = ( 8, 7, 1, 2 | 3, 5, 3, 2 )
2 )
Ch1 = (6, 5, 4, 1, 3, 5, 3, 2)
- child1 = ( 6, 5, 9, 2, 1, 2, 3, 2 )
Ch3 = ( 2, 3, 9, 2, 1, 2, 8, 5)
- child2 = ( 2, 3, 4, 1, 3, 5, 8, 5 )
3 )
Ch1 = (8, 7, 1, 2, 6, 6, 0, 1)
- child1 = (8, 7, 9, 2, 6, 6, 0, 5)
Ch3 = (2, 3, 9, 2, 1, 2, 8, 5)
- child2 = (2, 3, 1, 2, 1, 2, 8, 1)
PART 3, Fitnesses of newly generated offspring:
- child1 = ( 6, 5, 4, 1 , 6, 6, 0, 1 ) = (6 + 5 ) - (4 + 1 ) + ( 6 + 6 ) - ( 0 + 1 ) = 17
- child2 = (8, 7, 1, 2 , 3, 5, 3, 2) = (8 + 7 ) - (1 + 2 ) + ( 3+ 5 ) - ( 3 + 2 ) = 15
- child3 = ( 6, 5, 9, 2, 1, 2, 3, 2 ) = (6 + 5 ) - (9 + 2 ) + ( 1 + 2 ) - ( 3 + 2 ) = -2
- child4 = (2, 3, 4, 1, 3, 5, 8, 5) = (2 + 3 ) - (4 + 1 ) + ( 3 + 5 ) - ( 8 + 5 ) = -5
- child5 = (8, 7, 9, 2, 6, 6, 0, 5) = (8 + 7 ) - (9 + 2 ) + ( 6 + 6 ) - ( 0 + 5 ) = 11
- child6= (2, 3, 1, 2, 1, 2, 8, 1) = (2 + 3 ) - (1 + 2 ) + ( 1 + 2 ) - ( 8 + 1 ) = -4
PART 4:
(9 + 9) − (0 + 0) + (9 + 9 ) − (0 + 0) = 36
[ 9, 9, 0, 0, 9, 9, 0, 0 ]
PART 5
- ch1 = (6, 5, 4, 1, 3, 5, 3, 2)
- ch2 = (8, 7, 1, 2, 6, 6, 0, 1)
- ch3 = (2, 3, 9, 2, 1, 2, 8, 5)
- ch4 = (4, 1, 8, 5, 2, 0, 9, 4)
- ch5 = (9, 9, 0, 0, 9, 9, 0, 0)
Comments
Post a Comment