Tutorial Problems GA
Tutorial Problems GA
String
Random numbers
No.
1 0.63 0.51 0.16 0.79 0.11
2 0.88 0.45 0.40 1.00 0.98
3 0.93 0.95 0.59 0.95 0.06
4 0.33 0.11 0.75 0.92 0.05
Mutation
Offspring After Offspring after
String No. x-value 𝐟 𝐱 = 𝐱𝟐
Crossover mutation
1 01100 01001 9 81
2 11001 11001 25 625
3 11011 11010 26 576
4 10000 11001 25 625
Sum 1907
Average 476.75
Maximum 625
No improvement in the solution, so iterate gain.
Solve using GA
𝑓 𝑥 = 𝑥 2
+1
0 < 𝑥 < 27
Problem 2
𝑀𝑎𝑥𝑖𝑚𝑖𝑧𝑒 𝑌 = 800 − 62.83 2𝐷 + 0.91𝐷−0.2
0 < 𝐷 < 6.3
Use GA to solve the above problem.
Solution:
GA works with a set of solutions.
Each solution is represented by a string of binary variables,
corresponding to the chromosomes in genetics.
Selection
Initial Expected Actual Count
D-values (1 Fitness pselect
String population count from
decimal Function 𝒇𝒊
No. randomly 𝒇𝒊 Roulette
accuracy) (Y=f) σ𝒇
generated 𝒇 wheel
1 0.000011 0.3 689.6 0.41 1.73 2
2 010100 2.0 498.9 0.29 1.25 1
3 011110 3.0 377.1 0.22 0.945 1
4 110010 5.0 130.3 0.07 0.33 0
Sum 1695.9 1 4.255 4
Average 423.9 0.25 1.06375 1
Max 689.6 0.41 1.73 2
Selection
p-select
String 1 String 2 String 3 String 4
String 4
7%
String 3
22%
String 1
42%
String 2
29%
Single point Crossover
Mate Crossover New
Mating pool After D-
String (Random Site Population
Reproduction val 𝒀=𝒇 𝒙
No. ly (Randomly after
(Cross site shown) ue
Selected) Selected) crossover
1 0.0000|11 4 4 0.000010 0.2 696
2 000|011 3 3 000100 0.4 681.1
3 010|100 2 3 010011 1.9 511
4 0111|10 1 4 011111 3.1 364.9
Sum 2253.0
Average 563.3
Max 696
Mutation
Taking mutation probability 0.05
String
Random numbers
No.
1 0.33 0.44 0.35 0.08 0.83 0.41
2 0.34 0.97 0.54 0.56 0.30 0.40
3 0.07 0.04 0.29 0.27 0.14 0.55
4 0.57 0.27 0.74 0.30 0.99 0.08
Mutation
Offspring After Offspring after
String No. x-value 𝒀=𝒇 𝒙
Crossover mutation
1 0.000010 0.000010 0.03125
2 000100 000100 4
3 010011 000011 3
4 011111 011111 31
Sum
Average
Maximum
Problem 3
Consider a supply chain of a computer manufacturing industry.
• Demand of each customer zone is satisfied exactly by one production plant
• Each production plant supplies exactly to one customer zone
Customer Customer Customer Customer
zone 1 zone 2 zone 3 zone 4
Plant 1 20 25 17 22
Plant 2 14 9 19 6
Plant 3 13 15 23 30
Plant 4 8 25 12 7
Distance in km matrix (as shown)
Objective function Min. Distance
Problem 3
Selection: expected count (=𝑓ൗ𝑓𝑎𝑣𝑔 ) String No. Iteration 1 Iteration 2
1 0.98 0.47
Crossover procedure
2 0.57 0.55
Before crossover After crossover
3 0.45 0.88
abcd dbca
4 0.93 0.93
ijkl ljki
Selection criteria:
Crossover probability (𝐶𝑝 = 0.8) Iteration 1:
String 2 and String 3 are selected for crossover as
Random number used for crossover their random numbers are less than 𝐶𝑝
as shown in Table Iteration 2:
String 1 and String 2 are selected for crossover as
their random numbers are less than 𝐶𝑝
Customer Customer Customer Customer
Solution: Plant 1
zone 1
20
zone 2
25
zone 3
17
zone 4
22
Plant 2 14 9 19 6
Max. Distance (100-D) Plant 3 13 15 23 30
Plant 4 8 25 12 7
Initial Population
String Details Objective Function Fitness Function Value Expected count
Value (D) (100-D)
1 1-2-3-4 25+19+30+8=82 100-82=18 0.55≈ 0
2 2-4-1-3 6+8+17+15=46 100-46=54 1.66≈ 2
3 3-1-4-2 13+22+25+19=79 100-79=21 0.646≈ 1
4 4-3-2-1 12+15+14+22=63 100-63=37 1.13≈ 1
𝑓𝑡𝑜𝑡𝑎𝑙 = 130 4
𝑓𝑎𝑣𝑔 = 32.5
Solution:
Mating Pool After crossover
String Details Crossover between String 2 String Details
and String 3
1 2-4-1-3 1 2-4-1-3
P1: 2-4-1-3
2 2-4-1-3 P2: 3-1-4-2 2 3-4-1-2
3 3-1-4-2 3 2-1-4-3
4 4-3-2-1 Ch1: 3-4-1-2 4 4-3-2-1
Ch2: 2-1-4-3
Customer Customer Customer Customer
zone 1 zone 2 zone 3 zone 4
Solution: Plant 1 20 25 17 22
Plant 2 14 9 19 6
Plant 3 13 15 23 30
Iteration 2
Plant 4 8 25 12 7
String Details Objective Function Fitness Function Value (100- Expected count
Value (D) D)
1 1-2-3-4 20+9+23+7=59 100-59=41 1.11≈ 1
2 3-1-4-2 13+25+12+6=56 100-56=44 1.23≈ 2
3 1-3-2-4 20+15+19+7=61 100-61=39 1.03≈ 1
4 2-1-4-3 14+25+12+30=81 100-81=19 0.53≈ 0
𝑓𝑡𝑜𝑡𝑎𝑙 = 143
𝑓𝑎𝑣𝑔 = 35.75
Customer Customer Customer Customer
zone 1 zone 2 zone 3 zone 4
Solution: Plant 1 20 25 17 22
Plant 2 14 9 19 6
Plant 3 13 15 23 30
Iteration 3 Plant 4 8 25 12 7
V1 2 4 5 1 3 V4 3 1 5 4 2 V4 5 1 3 4 2
V2 1 3 2 5 4
Example of GA
Parent Offspring
Step 5: Evaluation
V1 2 4 3 5 1 V1 2 4 5 1 3
V2 1 3 5 4 2 V2 1 3 2 5 4
V3 4 3 5 1 2 V3 4 1 5 3 2
V4 3 1 5 4 2 V4 5 1 3 4 2
0.770
0.258
V3=0.258 V2=0.254
In the above table a and b are the number of units of A and B produced, respectively.
This can also be written as: a = 1500-5P1 and b=3800-10P2
Solution