Let's solve this step-by-step.
Problem Summary
We are given a binary string optimization problem with the goal to evolve a binary string of length 6 to maximize the number of 1s.
Initial Population:
- P1 = 101010
- P2 = 111000
- P3 = 000111
- P4 = 110011
Part (a): Fitness Function, Selection via Roulette Wheel
Step 1: Define Fitness Function
Since we want to maximize the number of 1s in the binary string, a suitable fitness function is:
Fitness(x) = Number of '1's in the binary string x
Step 2: Compute Fitness for Each Individual
| Individual | Binary String | Number of 1s | Fitness |
|---|
| P1 | 101010 | 3 | 3 |
| P2 | 111000 | 3 | 3 |
| P3 | 000111 | 3 | 3 |
| P4 | 110011 | 4 | 4 |
Total fitness = 3 + 3 + 3 + 4 = 13
Step 3: Compute Probabilities and Cumulative Probabilities
| Individual | Fitness | Probability = f_i / total_f | Cumulative Probability |
|---|
| P1 | 3 | 3/13 ≈ 0.2308 | 0.2308 |
| P2 | 3 | 3/13 ≈ 0.2308 | 0.4615 |
| P3 | 3 | 3/13 ≈ 0.2308 | 0.6923 |
| P4 | 4 | 4/13 ≈ 0.3077 | 1.0000 |
Step 4: Perform Roulette-Wheel Selection
Generate two random numbers between [0,1):
Let’s say:
- r₁ = 0.28 → falls in range [0.2308, 0.4615] → Select P2
- r₂ = 0.71 → falls in range [0.6923, 1.0000] → Select P4
✅ Selected Parents: P2 = 111000, P4 = 110011
Part (b): One-point Crossover and Mutation
Step 1: One-point Crossover after Position 3
Parent 1 (P2): 111000
Parent 2 (P4): 110011
Crossover point after position 3:
- First 3 bits from parent 1, last 3 from parent 2
- Child 1:
111 + 011 = 111011
- Child 2:
110 + 000 = 110000
✅ Initial Offspring:
Step 2: Apply Bit-Flip Mutation with p = 0.2
Each bit has a 20% chance of being flipped (0 ↔ 1)
Mutate C1 = 111011
Randomly generate 6 numbers between [0,1), one per bit:
Let’s assume:
- Random values: [0.1, 0.9, 0.8, 0.15, 0.25, 0.3]
- Mutation threshold = 0.2
Bits where random value < 0.2 will be flipped:
- Bit 1: 0.1 → flip → 0
- Bit 4: 0.15 → flip → 1
So:
- Original:
1 1 1 0 1 1
- Mutated:
0 1 1 1 1 1
✅ Mutated C1: 011111
Mutate C2 = 110000
Random values: [0.22, 0.05, 0.3, 0.18, 0.9, 0.1]
Threshold = 0.2 → Flip if value < 0.2
Flips at positions:
- Bit 2: 0.05 → flip → 1
- Bit 4: 0.18 → flip → 1
- Bit 6: 0.1 → flip → 1
Original: 1 1 0 0 0 0
Mutated: 1 0 0 1 0 1
✅ Mutated C2: 100101
✅ Final Answer:
(a)
- Fitness function: Count of '1's in each string
- Selected parents via roulette wheel:
- Parent 1: P2 = 111000
- Parent 2: P4 = 110011
(b)
- One-point crossover after position 3 gives:
- C1:
111011, mutated → 011111
- C2:
110000, mutated → 100101
✅ Final offspring:
- Offspring 1:
011111
- Offspring 2:
100101