โœจ 4 - Crossover ๊ต์ฐจ

Crossover is the process of forming new individuals from existing individuals while maintaining traits.
๊ต์ฐจ(Crossover)๋Š” ๊ธฐ์กด ๊ฐœ์ฒด๋“ค๋กœ๋ถ€ํ„ฐ ํŠน์„ฑ์„ ์œ ์ง€ํ•œ ์ฑ„ ์ƒˆ๋กœ์šด ๊ฐœ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค.

The main purpose of crossing is the exchange of experience.
๊ต์ฐจ์˜ ์ฃผ์š” ๋ชฉ์ ์€ ๊ฒฝํ—˜์˜ ๊ตํ™˜์ž…๋‹ˆ๋‹ค.

This approach greatly speeds up finding an acceptable solution.
์ด ๋ฐฉ์‹์€ ์ˆ˜์šฉ ๊ฐ€๋Šฅํ•œ ํ•ด๋ฅผ ๋” ๋น ๋ฅด๊ฒŒ ์ฐพ๋Š” ๋ฐ ํฌ๊ฒŒ ๊ธฐ์—ฌํ•ฉ๋‹ˆ๋‹ค.

Crossover is the next logical action that occurs after selection.
๊ต์ฐจ๋Š” ์„ ํƒ ์ดํ›„์— ์ผ์–ด๋‚˜๋Š” ๋‹ค์Œ ๋‹จ๊ณ„์˜ ๋…ผ๋ฆฌ์  ์ ˆ์ฐจ์ž…๋‹ˆ๋‹ค.


๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
traitํŠน์„ฑ
exchange๊ตํ™˜
experience๊ฒฝํ—˜
acceptable์ˆ˜์šฉ
solutionํ•ด
logical๋…ผ๋ฆฌ
occur๋ฐœ์ƒ

โœจ 4 - Structure ๊ตฌ์กฐ

In this chapter, we will look at the following crossover methods:
์ด ์žฅ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ต์ฐจ ๋ฐฉ๋ฒ•๋“ค์„ ์‚ดํŽด๋ณผ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

One-point crossover
์›ํฌ์ธํŠธ ๊ต์ฐจ

N-point crossover
Nํฌ์ธํŠธ ๊ต์ฐจ

Uniform crossover
๊ท ์ผ ๊ต์ฐจ

Linear combination crossover
์„ ํ˜• ๊ฒฐํ•ฉ ๊ต์ฐจ

Blend crossover
๋ธ”๋ Œ๋“œ ๊ต์ฐจ

Order crossover
์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ

Fitness driven crossover
์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ


โœจ 4 - Objectives ํ•™์Šต ๋ชฉํ‘œ

Understand what crossover is
๊ต์ฐจ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ์ดํ•ดํ•ฉ๋‹ˆ๋‹ค.

Introduce main crossover methods
์ฃผ์š” ๊ต์ฐจ ๋ฐฉ๋ฒ•๋“ค์„ ์†Œ๊ฐœํ•ฉ๋‹ˆ๋‹ค.

Get visualization and implementation of each method
๊ฐ ๋ฐฉ๋ฒ•์˜ ์‹œ๊ฐํ™”์™€ ๊ตฌํ˜„์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.


โœจ 4.1 One-point crossover ๋‹จ์ผ ์ง€์  ๊ต์ฐจ

In one-point crossover, a point in a gene sequence is randomly selected by dividing the gene sequence into two parts.
๋‹จ์ผ ์ง€์  ๊ต์ฐจ๋Š” ์œ ์ „์ž ์„œ์—ด์—์„œ ํ•œ ์ง€์ ์„ ๋ฌด์ž‘์œ„๋กœ ์„ ํƒํ•ด, ์ด๋ฅผ ๋‘ ๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

New individuals are created by crossing these two parts.
์ด ๋‘ ๋ถ€๋ถ„์„ ์„œ๋กœ ๊ตํ™˜ํ•˜์—ฌ ์ƒˆ๋กœ์šด ๊ฐœ์ฒด๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

One-point crossover can be applied to ordered gene and binary bin sets.
๋‹จ์ผ ์ง€์  ๊ต์ฐจ๋Š” ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์œ ์ „์ž๋‚˜ ์ด์ง„ ์ง‘ํ•ฉ์—๋„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

If the gene sequence consists of one element, then a simple exchange of genes between the parents happens, and each of the children is a clone of one of the parents.
์œ ์ „์ž ์„œ์—ด์ด ํ•˜๋‚˜์˜ ์š”์†Œ๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค๋ฉด ๋ถ€๋ชจ ๊ฐ„์˜ ๋‹จ์ˆœํ•œ ์œ ์ „์ž ๊ตํ™˜์ด ์ผ์–ด๋‚˜๋ฉฐ, ์ž์‹์€ ๋ถ€๋ชจ ์ค‘ ํ•œ ์ชฝ์˜ ๋ณต์ œ๋ณธ์ด ๋ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

If the gene sequence consists of two elements, then the genes are exchanged in a crisscross way.
์œ ์ „์ž ์„œ์—ด์ด ๋‘ ๊ฐœ์˜ ์š”์†Œ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค๋ฉด, ์œ ์ „์ž๋Š” ์—‡๊ฐˆ๋ฆฌ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตํ™˜๋ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Here we will show an implementation of one-point crossover to an ordered gene set.
์—ฌ๊ธฐ์„œ๋Š” ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์œ ์ „์ž ์ง‘ํ•ฉ์— ๋‹จ์ผ ์ง€์  ๊ต์ฐจ๋ฅผ ์ ์šฉํ•œ ๊ตฌํ˜„์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.


Import part

import copy
import random

One-point crossover

def crossover_one_point(p1, p2):
    point = random.randint(1, len(p1) - 1)
    c1, c2 = copy.deepcopy(p1), copy.deepcopy(p2)
    c1[point:], c2[point:] = p2[point:], p1[point:]
    return [c1, c2]

Example

random.seed(2)
p1 = [random.randint(0, 9) for _ in range(5)]
p2 = [random.randint(0, 9) for _ in range(5)]
 
offspring = crossover_one_point(p1, p2)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [1, 1, 0, 4, 3]  
Parent 2: [3, 3, 2, 1, 8]  
Child 1:  [1, 1, 2, 1, 8]  
Child 2:  [3, 3, 0, 4, 3]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
one-point๋‹จ์ผ
randomly๋ฌด์ž‘์œ„๋กœ
divide๋‚˜๋ˆ„๋‹ค
exchange๊ตํ™˜
clone๋ณต์ œ๋ณธ
element์š”์†Œ
crisscross์—‡๊ฐˆ๋ฆผ
implementation๊ตฌํ˜„
ordered์ˆœ์„œ๊ฐ€ ์žˆ๋Š”

โœจ 4.2 N-point crossover ๋‹ค์ค‘ ์ง€์  ๊ต์ฐจ

N-point crossover is a logical continuation of one-point crossover,
๋‹ค์ค‘ ์ง€์  ๊ต์ฐจ๋Š” ๋‹จ์ผ ์ง€์  ๊ต์ฐจ์˜ ๋…ผ๋ฆฌ์ ์ธ ์—ฐ์žฅ์„ ์ž…๋‹ˆ๋‹ค.

but instead of choosing only one point in a gene sequence, N points are selected,
ํ•˜๋‚˜์˜ ์ง€์ ์„ ์„ ํƒํ•˜๋Š” ๋Œ€์‹ , ์œ ์ „์ž ์„œ์—ด์—์„œ N๊ฐœ์˜ ์ง€์ ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

and genes are being exchanged in a crisscross way.
๊ทธ๋ฆฌ๊ณ  ์œ ์ „์ž๋Š” ์—‡๊ฐˆ๋ฆฌ๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตํ™˜๋ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Letโ€™s see an implementation of N-point crossover that is applied to an ordered gene set. ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์œ ์ „์ž ์ง‘ํ•ฉ์— ๋‹ค์ค‘ ์ง€์  ๊ต์ฐจ๋ฅผ ์ ์šฉํ•œ ๊ตฌํ˜„์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


Import part

import copy
import random

N-point crossover

def crossover_n_point(p1, p2, n):
    ps = random.sample(range(1, len(p1) - 1), n)
    ps.append(0)
    ps.append(len(p1))
    ps = sorted(ps)
    c1, c2 = copy.deepcopy(p1), copy.deepcopy(p2)
    for i in range(0, n + 1):
        if i % 2 == 0:
            continue
        c1[ps[i]:ps[i + 1]] = p2[ps[i]:ps[i + 1]]
        c2[ps[i]:ps[i + 1]] = p1[ps[i]:ps[i + 1]]
    return [c1, c2]

Example

random.seed(3)
p1 = [random.randint(0, 9) for _ in range(6)]
p2 = [random.randint(10, 19) for _ in range(6)]
offspring = crossover_n_point(p1, p2, 3)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [3, 8, 9, 3, 8, 5]  
Parent 2: [11, 13, 11, 11, 13, 13]  
Child 1:  [3, 13, 11, 3, 13, 5]  
Child 2:  [11, 8, 9, 11, 8, 13]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
continuation์—ฐ์žฅ์„ , ํ™•์žฅ
crisscross์—‡๊ฐˆ๋ฆผ

โœจ 4.3 Uniform crossover ๊ท ๋“ฑ ๊ต์ฐจ

Uniform crossover randomly selects some points in the parentโ€™s gene chain, and swaps the genes at these points.
๊ท ๋“ฑ ๊ต์ฐจ๋Š” ๋ถ€๋ชจ์˜ ์œ ์ „์ž ์„œ์—ด์—์„œ ๋ช‡๋ช‡ ์ง€์ ์„ ๋ฌด์ž‘์œ„๋กœ ์„ ํƒํ•˜๊ณ , ํ•ด๋‹น ์ง€์ ์˜ ์œ ์ „์ž๋ฅผ ์„œ๋กœ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image


Import part

import copy
import random

Uniform crossover

def crossover_uniform(p1, p2, prop):
    c1 = copy.deepcopy(p1)
    c2 = copy.deepcopy(p2)
    for i in range(len(p1)):
        if random.random() < prop:
            c1[i], c2[i] = p2[i], p1[i]
    return [c1, c2]

Example

random.seed(3)
p1 = [random.randint(0, 9) for _ in range(6)]
p2 = [random.randint(10, 19) for _ in range(6)]
offspring = crossover_uniform(p1, p2, 0.5)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [3, 8, 9, 3, 8, 5]  
Parent 2: [19, 17, 11, 12, 15, 17]  
Child 1:  [3, 17, 9, 12, 8, 17]  
Child 2:  [19, 8, 11, 3, 15, 5]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
uniform๋™์ผํ•œ, ๊ท ๋“ฑํ•œ
chain์‚ฌ์Šฌ
swap๊ตํ™˜
point์ง€์ 
probabilityํ™•๋ฅ 

โœจ 4.4 Linear combination crossover ์„ ํ˜• ๊ฒฐํ•ฉ ๊ต์ฐจ

Linear combination crossover is the example of a crossover without any randomness.
์„ ํ˜• ๊ฒฐํ•ฉ ๊ต์ฐจ๋Š” ๋ฌด์ž‘์œ„์„ฑ์ด ์—†๋Š” ๊ต์ฐจ ๋ฐฉ์‹์˜ ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค.

Child genes is a simple linear combination of parent genes:
์ž์‹์˜ ์œ ์ „์ž๋Š” ๋ถ€๋ชจ ์œ ์ „์ž์˜ ๋‹จ์ˆœํ•œ ์„ ํ˜• ๊ฒฐํ•ฉ์œผ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค:

(xโ‚ + ฮฑโ€ฏ|xโ‚‚ย โˆ’ย xโ‚|,ย xโ‚‚ย โˆ’ย ฮฑโ€ฏ|xโ‚‚ย โˆ’ย xโ‚|), where ฮฑ is the parameter of linear combination in range [0, 1].
(xโ‚ + ฮฑโ€ฏ|xโ‚‚ย โˆ’ย xโ‚|,ย xโ‚‚ย โˆ’ย ฮฑโ€ฏ|xโ‚‚ย โˆ’ย xโ‚|), ์—ฌ๊ธฐ์„œ ฮฑ๋Š” [0, 1] ๋ฒ”์œ„์˜ ์„ ํ˜• ๊ฒฐํ•ฉ ๊ณ„์ˆ˜์ž…๋‹ˆ๋‹ค.

NOTE : If ฮฑ equals 0 or 1, then children are the same as parents.
์ฐธ๊ณ  : ฮฑ๊ฐ€ 0 ๋˜๋Š” 1์ด๋ฉด ์ž์‹์€ ๋ถ€๋ชจ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

If ฮฑ equals 0.5, then we have twins in offspring (both children are the same).
ฮฑ๊ฐ€ 0.5์ด๋ฉด ๋‘ ์ž์‹์ด ๋™์ผํ•œ ์Œ๋‘ฅ์ด ๊ฐœ์ฒด๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

If we want only new individuals to be created, then we can restrict ฮฑ to this range (0, 0.5).
ํ•ญ์ƒ ์ƒˆ๋กœ์šด ๊ฐœ์ฒด๋งŒ ์ƒ์„ฑ๋˜๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋ฉด ฮฑ์˜ ๋ฒ”์œ„๋ฅผ (0, 0.5)๋กœ ์ œํ•œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Letโ€™s take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Implementation of linear crossover is just arithmetic operation applied to real gene set.
์„ ํ˜• ๊ฒฐํ•ฉ ๊ต์ฐจ์˜ ๊ตฌํ˜„์€ ์‹ค์ˆ˜ํ˜• ์œ ์ „์ž ์ง‘ํ•ฉ์— ์‚ฐ์ˆ  ์—ฐ์‚ฐ์„ ์ ์šฉํ•˜๋Š” ๊ฒƒ์ผ ๋ฟ์ž…๋‹ˆ๋‹ค.


Import part

import copy
import random

Linear crossover

def crossover_linear(p1, p2, alpha):
    c1 = copy.deepcopy(p1)
    c2 = copy.deepcopy(p2)
    for i in range(len(p1)):
        c1[i] = round(p1[i] + alpha * (p2[i] - p1[i]), 2)
        c2[i] = round(p2[i] - alpha * (p2[i] - p1[i]), 2)
    return [c1, c2]

Example

random.seed(3)
p1 = [round(random.uniform(0, 10), 2) for _ in range(6)]
p2 = [round(random.uniform(0, 10), 2) for _ in range(6)]
offspring = crossover_linear(p1, p2, 0.3)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [4.16, 6.6, 1.62, 8.14, 9.58, 4.64]  
Parent 2: [3.26, 0.2, 1.82, 2.91, 0.91, 7.12]  
Child 1:  [3.89, 4.57, 1.68, 6.51, 6.89, 5.39]  
Child 2:  [3.53, 2.22, 1.76, 4.54, 3.6, 6.37]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
linear์„ ํ˜•์˜
combination๊ฒฐํ•ฉ
randomness๋ฌด์ž‘์œ„์„ฑ
parameter๋งค๊ฐœ๋ณ€์ˆ˜
range๋ฒ”์œ„
equal๊ฐ™๋‹ค
twin์Œ๋‘ฅ์ด
restrict์ œํ•œํ•˜๋‹ค
offspring์ž์†

โœจ 4.5 Blend crossover ํ˜ผํ•ฉ ๊ต์ฐจ

Blend crossover method chooses random genes in the range defined by parent genes.
ํ˜ผํ•ฉ ๊ต์ฐจ๋Š” ๋ถ€๋ชจ ์œ ์ „์ž์— ์˜ํ•ด ์ •์˜๋œ ๋ฒ”์œ„ ๋‚ด์—์„œ ๋ฌด์ž‘์œ„๋กœ ์ž์‹ ์œ ์ „์ž๋ฅผ ์„ ํƒํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

The range for children genes is defined as follows:
์ž์‹ ์œ ์ „์ž์˜ ๋ฒ”์œ„๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜๋ฉ๋‹ˆ๋‹ค:

[xโ‚ย โˆ’ย ฮฑ(xโ‚‚ย โˆ’ย xโ‚),ย xโ‚‚ย +ย ฮฑ(xโ‚‚ย โˆ’ย xโ‚)], where ฮฑ is the parameter that expands the parent genes range.
[xโ‚ย โˆ’ย ฮฑ(xโ‚‚ย โˆ’ย xโ‚),ย xโ‚‚ย +ย ฮฑ(xโ‚‚ย โˆ’ย xโ‚)], ์—ฌ๊ธฐ์„œ ฮฑ๋Š” ๋ถ€๋ชจ ์œ ์ „์ž ๋ฒ”์œ„๋ฅผ ํ™•์žฅํ•˜๋Š” ๊ณ„์ˆ˜์ž…๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Usually, ฮฑ = 0.5.
์ผ๋ฐ˜์ ์œผ๋กœ ฮฑ๋Š” 0.5๋กœ ์„ค์ •๋ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure 4.8:
๊ทธ๋ฆผ 4.8์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Like linear crossover, blend crossover is applied to a real gene set; letโ€™s study an implementation.
์„ ํ˜• ๊ฒฐํ•ฉ ๊ต์ฐจ์ฒ˜๋Ÿผ, ํ˜ผํ•ฉ ๊ต์ฐจ๋„ ์‹ค์ˆ˜ํ˜• ์œ ์ „์ž ์ง‘ํ•ฉ์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค. ๊ตฌํ˜„์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


Import part

import copy
import random

Blend crossover

def crossover_blend(p1, p2, alpha):
    c1 = copy.deepcopy(p1)
    c2 = copy.deepcopy(p2)
    for i in range(len(p1)):
        l = min(c1[i], c2[i]) - alpha * abs(c2[i] - c1[i])
        u = max(c1[i], c2[i]) + alpha * abs(c2[i] - c1[i])
        c1[i] = round(l + random.random() * (u - l), 2)
        c2[i] = round(l + random.random() * (u - l), 2)
    return [c1, c2]

Example

random.seed(3)
p1 = [round(random.uniform(0, 10), 2) for _ in range(6)]
p2 = [round(random.uniform(0, 10), 2) for _ in range(6)]
offspring = crossover_blend(p1, p2, 0.5)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [4.16, 6.6, 1.62, 8.14, 9.58, 4.64]  
Parent 2: [3.26, 0.2, 1.82, 2.91, 0.91, 7.12]  
Child 1:  [3.95, 5.64, 1.72, 7.96, 8.41, 5.6]  
Child 2:  [3.84, 1.55, 1.77, 4.49, 5.29, 6.63]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
blendํ˜ผํ•ฉ
range๋ฒ”์œ„
define์ •์˜ํ•˜๋‹ค
expandํ™•์žฅํ•˜๋‹ค
real์‹ค์ˆ˜
uniform๊ท ์ผํ•œ
random๋ฌด์ž‘์œ„

โœจ 4.6 Order crossover ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ

Order crossover is used for ordered genes; the main principle in this approach is to preserve the order of parent genes.
์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋Š” ์ˆœ์„œ๊ฐ€ ์ค‘์š”ํ•œ ์œ ์ „์ž์— ์‚ฌ์šฉ๋˜๋ฉฐ, ์ด ๋ฐฉ์‹์˜ ํ•ต์‹ฌ ์›๋ฆฌ๋Š” ๋ถ€๋ชจ ์œ ์ „์ž์˜ ์ˆœ์„œ๋ฅผ ์œ ์ง€ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

We will show how this method works with an example:
์ด ๋ฐฉ๋ฒ•์ด ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

Say, we have two individuals with ordered genes:
๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์œ ์ „์ž๋ฅผ ๊ฐ€์ง„ ๋‘ ๊ฐœ์ฒด๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ์‹œ๋‹ค:

Parent 1: (1, 7, 4, 5, 9, 2, 8, 3, 6)
๋ถ€๋ชจ 1: (1, 7, 4, 5, 9, 2, 8, 3, 6)

Parent 2: (3, 1, 5, 4, 9, 8, 6, 2, 7)
๋ถ€๋ชจ 2: (3, 1, 5, 4, 9, 8, 6, 2, 7)

We choose a random range in genes chain and swap it.
์œ ์ „์ž ์„œ์—ด์—์„œ ๋ฌด์ž‘์œ„๋กœ ์ผ์ • ๋ฒ”์œ„๋ฅผ ์„ ํƒํ•˜๊ณ , ํ•ด๋‹น ๊ตฌ๊ฐ„์„ ๊ตํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Now, we will try to find the next number in Parent which wasnโ€™t mentioned in Child 1 yet:
์ด์ œ ๋ถ€๋ชจ์˜ ์œ ์ „์ž ์ค‘ ์ž์‹ 1์— ์•„์ง ํฌํ•จ๋˜์ง€ ์•Š์€ ๋‹ค์Œ ์ˆซ์ž๋ฅผ ์ฐพ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

Parent 1: (1, 7, 4, 5, 9, 2, 8 โ†’ 3, 6) โ€“ the next number is 3.
๋ถ€๋ชจ 1: (1, 7, 4, 5, 9, 2, 8 โ†’ 3, 6) โ€“ ๋‹ค์Œ ์ˆซ์ž๋Š” 3์ž…๋‹ˆ๋‹ค.

Child 1: (X, X, 5, 4, 9, 8, 6, X, X) โ€“ doesnโ€™t contain 3 yet.
์ž์‹ 1: (X, X, 5, 4, 9, 8, 6, X, X) โ€“ ์•„์ง 3์€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

The same happens for Child in Parent 2 โ€“ the next number is 2, but it is already mentioned in Child 2 โ€“ then we take the next one:
Parent 2์—์„œ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ž์‹ 2์— ๋Œ€ํ•ด ๋‹ค์Œ ์ˆซ์ž๊ฐ€ 2์ด์ง€๋งŒ, ์ด๋ฏธ ์ž์‹ 2์— ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ๋‹ค์Œ ์ˆซ์ž๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

Parent 2: (3, 1, 5, 4, 9, 8, 6 โ†’ 2, 7) โ€“ the next number is 2.
๋ถ€๋ชจ 2: (3, 1, 5, 4, 9, 8, 6 โ†’ 2, 7) โ€“ ๋‹ค์Œ ์ˆซ์ž๋Š” 2์ž…๋‹ˆ๋‹ค.

Child 2: (X, X, 4, 5, 9, 2, 8, X, X) โ€“ already contains 2.
์ž์‹ 2: (X, X, 4, 5, 9, 2, 8, X, X) โ€“ ์ด๋ฏธ 2๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Checking the next number:
๋‹ค์Œ ์ˆซ์ž๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

Parent 2: (3, 1, 5, 4, 9, 8, 6, 2 โ†’ 7) โ€“ the next number is 7.
๋ถ€๋ชจ 2: (3, 1, 5, 4, 9, 8, 6, 2 โ†’ 7) โ€“ ๋‹ค์Œ ์ˆซ์ž๋Š” 7์ž…๋‹ˆ๋‹ค.

Child 2: (X, X, 4, 5, 9, 2, 8, X, X) โ€“ doesnโ€™t contain 7 yet.
์ž์‹ 2: (X, X, 4, 5, 9, 2, 8, X, X) โ€“ ์•„์ง 7์€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

Keep going for Child 1; the next Parent 1 number is 6 and this number is mentioned in Child 1 too, so weโ€™re taking the next one:
์ž์‹ 1์— ๋Œ€ํ•ด ๊ณ„์† ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ถ€๋ชจ 1์˜ ์ˆซ์ž๋Š” 6์ธ๋ฐ, ์ž์‹ 1์— ์ด๋ฏธ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ๋‹ค์Œ ์ˆซ์ž๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

Parent 1: (1, 7, 4, 5, 9, 2, 8, 3 โ†’ 6) โ€“ the next number is 6.
๋ถ€๋ชจ 1: (1, 7, 4, 5, 9, 2, 8, 3 โ†’ 6) โ€“ ๋‹ค์Œ ์ˆซ์ž๋Š” 6์ž…๋‹ˆ๋‹ค.

Child 1: (X, X, 5, 4, 9, 8, 6, 3, X) โ€“ already contains 6.
์ž์‹ 1: (X, X, 5, 4, 9, 8, 6, 3, X) โ€“ ์ด๋ฏธ 6์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Checking the next number:
๋‹ค์Œ ์ˆซ์ž๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค:

Parent 1: (โ†’ 1, 7, 4, 5, 9, 2, 8, 3, 6) โ€“ the next number is 1.
๋ถ€๋ชจ 1: (โ†’ 1, 7, 4, 5, 9, 2, 8, 3, 6) โ€“ ๋‹ค์Œ ์ˆซ์ž๋Š” 1์ž…๋‹ˆ๋‹ค.

Child 1: (X, X, 5, 4, 9, 8, 6, 3, X) โ€“ doesnโ€™t contain 1 yet.
์ž์‹ 1: (X, X, 5, 4, 9, 8, 6, 3, X) โ€“ ์•„์ง 1์€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

We hope you have got the principle.
์ด์ œ ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•˜์…จ๊ธฐ๋ฅผ ๋ฐ”๋ž๋‹ˆ๋‹ค.

As a result, we will have the following offspring.
๊ทธ ๊ฒฐ๊ณผ๋กœ ์šฐ๋ฆฌ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ž์‹ ๊ฐœ์ฒด๋“ค์„ ์–ป๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

In very high dimension tasks with a large number of variables, an execution of order crossover can be rather time-consuming;
๋ณ€์ˆ˜๊ฐ€ ๋งŽ์€ ๊ณ ์ฐจ์› ๋ฌธ์ œ์—์„œ๋Š” ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ์˜ ์‹คํ–‰์ด ์ƒ๋‹นํ•œ ์‹œ๊ฐ„์„ ์†Œ๋ชจํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

you have to pay attention to this fact by applying this method.
์ด ๋ฐฉ๋ฒ•์„ ์ ์šฉํ•  ๋•Œ๋Š” ์ด๋Ÿฌํ•œ ์ ์— ์œ ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.


Implementation of order crossover
์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ์˜ ๊ตฌํ˜„์ž…๋‹ˆ๋‹ค.


Import part

import random
from math import nan

Order crossover

def crossover_order(p1, p2):
    zero_shift = min(p1)
    length = len(p1)
    start, end = sorted([random.randrange(length) for _ in range(2)])
    c1, c2 = [nan] * length, [nan] * length
    t1, t2 = [x - zero_shift for x in p1], [x - zero_shift for x in p2]
    spaces1, spaces2 = [True] * length, [True] * length
 
    for i in range(length):
        if i < start or i > end:
            spaces1[t2[i]] = False
            spaces2[t1[i]] = False
 
    j1, j2 = end + 1, end + 1
    for i in range(length):
        if not spaces1[t1[(end + i + 1) % length]]:
            c1[j1 % length] = t1[(end + i + 1) % length]
            j1 += 1
        if not spaces2[t2[(i + end + 1) % length]]:
            c2[j2 % length] = t2[(i + end + 1) % length]
            j2 += 1
 
    for i in range(start, end + 1):
        c1[i], c2[i] = t2[i], t1[i]
 
    return [[x + zero_shift for x in c1], [x + zero_shift for x in c2]]

Example

random.seed(10)
p1 = random.sample(range(1, 10), 9)
p2 = random.sample(range(1, 10), 9)
offspring = crossover_order(p1, p2)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: [7, 4, 6, 1, 9, 3, 2, 5, 8]  
Parent 2: [3, 2, 6, 1, 7, 5, 4, 8, 9]  
Child 1:  [7, 4, 6, 1, 9, 5, 8, 3, 2]  
Child 2:  [3, 2, 6, 1, 7, 3, 9, 4, 8]

๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
order์ˆœ์„œ
preserve์œ ์ง€
mention์–ธ๊ธ‰
containํฌํ•จ
execution์ˆ˜ํ–‰
time-consuming์†Œ๋ชจ์ 
pay attention์œ ์˜
variable๋ณ€์ˆ˜
high dimension๊ณ ์ฐจ์›
space์ž๋ฆฌ

โœจ 4.7 Fitness driven crossover

Fitness driven crossover is an approach that compares the child to the parent and selects the best one.
์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋Š” ์ž์‹๊ณผ ๋ถ€๋ชจ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋” ๋‚˜์€ ๊ฐœ์ฒด๋ฅผ ์„ ํƒํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

The main principle of this approach is that children should be better than their parents or not at all.
์ด ๋ฐฉ์‹์˜ ํ•ต์‹ฌ ์›๋ฆฌ๋Š” ์ž์‹์ด ๋ถ€๋ชจ๋ณด๋‹ค ๋” ๋‚˜์•„์•ผ ํ•˜๋ฉฐ, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์•„์˜ˆ ์„ ํƒ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

In some tasks, the crossing operation is very unpredictable, and carries a high risk of destroying the accumulated positive experience.
์ผ๋ถ€ ๋ฌธ์ œ์—์„œ๋Š” ๊ต์ฐจ ์—ฐ์‚ฐ์ด ๋งค์šฐ ์˜ˆ์ธก ๋ถˆ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์ถ•์ ๋œ ๊ธ์ •์ ์ธ ๊ฒฝํ—˜์„ ๋ง๊ฐ€๋œจ๋ฆด ์œ„ํ—˜์ด ํฝ๋‹ˆ๋‹ค.

Then, as soon as the individuals appear to begin to adapt well to the environment, their genotype can be destroyed after crossing,
์ด๋Ÿฌํ•œ ๊ฒฝ์šฐ, ๊ฐœ์ฒด๊ฐ€ ํ™˜๊ฒฝ์— ์ž˜ ์ ์‘ํ•˜๊ธฐ ์‹œ์ž‘ํ•œ ์ˆœ๊ฐ„ ๊ต์ฐจ๋กœ ์ธํ•ด ์œ ์ „ํ˜•์ด ํŒŒ๊ดด๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

and as a result, their unique genetic adaptation will be destroyed.
๊ทธ ๊ฒฐ๊ณผ, ๊ฐœ์ฒด์˜ ๊ณ ์œ ํ•œ ์œ ์ „์  ์ ์‘๋ ฅ์ด ์‚ฌ๋ผ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Please take a look at the following figure.
๋‹ค์Œ ๊ทธ๋ฆผ์„ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

image

NOTE: You can notice that fitness driven crossover shares the same principle as elite selection which we covered in Chapter 3: Selection โ€“ not to lose valuable individuals.
์ฐธ๊ณ : ์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋Š” 3์žฅ์—์„œ ๋‹ค๋ฃฌ ์—˜๋ฆฌํŠธ ์„ ํƒ๊ณผ ๋™์ผํ•œ ์›๋ฆฌ๋ฅผ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค โ€” ์ค‘์š”ํ•œ ๊ฐœ์ฒด๋ฅผ ์žƒ์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

And a reasonable question could be: Why not always do this? Why donโ€™t we protect the best ones all the time?
์ด๋•Œ ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ์ƒ๊ธฐ๋Š” ์งˆ๋ฌธ์€ ์ด๊ฒƒ์ž…๋‹ˆ๋‹ค: ์™œ ํ•ญ์ƒ ์ด๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š์„๊นŒ? ์™œ ์ตœ์  ๊ฐœ์ฒด๋ฅผ ๋งค๋ฒˆ ๋ณดํ˜ธํ•˜์ง€ ์•Š์„๊นŒ?

Sometimes it makes sense, but evolution is very tricky and unpredictable thing; sometimes it can make one step back and two steps forward.
๋•Œ๋•Œ๋กœ ๊ทธ๋ ‡๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด ํƒ€๋‹นํ•˜์ง€๋งŒ, ์ง„ํ™”๋Š” ๋งค์šฐ ๋ณต์žกํ•˜๊ณ  ์˜ˆ์ธก ๋ถˆ๊ฐ€๋Šฅํ•˜์—ฌ, ๋•Œ๋ก  ํ•œ ๊ฑธ์Œ ๋’ค๋กœ ๊ฐ”๋‹ค๊ฐ€ ๋‘ ๊ฑธ์Œ ์•ž์œผ๋กœ ๋‚˜์•„๊ฐ€๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

Tiny mammals from the Jurassic period lived on the brink of survival, but after millions of years, this species led to the appearance of human.
์ฅ๋ผ๊ธฐ ์‹œ๋Œ€์˜ ์ž‘์€ ํฌ์œ ๋ฅ˜๋Š” ์ƒ์กด์˜ ๋ฒผ๋ž‘ ๋์— ์žˆ์—ˆ์ง€๋งŒ, ์ˆ˜๋ฐฑ๋งŒ ๋…„ ํ›„ ์ธ๋ฅ˜์˜ ํƒ„์ƒ์œผ๋กœ ์ด์–ด์กŒ์Šต๋‹ˆ๋‹ค.

We will get back to this question in further chapters.
์ด ์งˆ๋ฌธ์€ ์ดํ›„ ์žฅ์—์„œ ๋‹ค์‹œ ๋‹ค๋ฃจ๊ฒ ์Šต๋‹ˆ๋‹ค.

Fitness driven crossover can be based on any other crossover method.
์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋Š” ์–ด๋–ค ๊ต์ฐจ ๋ฐฉ์‹ ์œ„์—์„œ๋„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

For example, letโ€™s examine the implementation of fitness driven crossover based on blend crossover.
์˜ˆ๋ฅผ ๋“ค์–ด, ํ˜ผํ•ฉ ๊ต์ฐจ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ ๊ตฌํ˜„์„ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.


Import part

import copy
import random
from math import sin, cos

Individual

def fitness_function(x, y):
    return sin(x) * cos(y)
 
class Individual:
    def __init__(self, x, y) -> None:
        self.gene_set = [x, y]
        self.fitness = fitness_function(x, y)
 
    def __str__(self):
        return f'x: {self.gene_set[0]}, ' \
               f'y: {self.gene_set[1]}, ' \
               f'fitness: {round(self.fitness, 4)}'
 
def generate_random():
    return Individual(round(random.random(), 2),
                      round(random.random(), 2))

Fitness driven blend crossover

def crossover_fitness_driven_blend(ind1, ind2, alpha):
    c1 = copy.deepcopy(ind1.gene_set)
    c2 = copy.deepcopy(ind2.gene_set)
    for i in range(len(c1)):
        l = min(c1[i], c2[i]) - alpha * abs(c2[i] - c1[i])
        u = max(c1[i], c2[i]) + alpha * abs(c2[i] - c1[i])
        c1[i] = round(l + random.random() * (u - l), 2)
        c2[i] = round(l + random.random() * (u - l), 2)
    child1 = Individual(c1[0], c1[1])
    child2 = Individual(c2[0], c2[1]) # ๊ต์žฌ์—๋Š” (c1[0], c1[1])๋กœ ๋‚˜์™€์žˆ๋Š”๋ฐ ์ˆ˜์ •ํ•ด์•ผ ํ•จ
    candidates = [ind1, ind2, child1, child2]
    best = sorted(candidates, key=lambda ind: ind.fitness, reverse=True)
    return best[0:2]

Example

random.seed(3)
p1, p2 = generate_random(), generate_random()
offspring = crossover_fitness_driven_blend(p1, p2, 0.5)
 
print(f'Parent 1: {p1}')
print(f'Parent 2: {p2}')
print(f'Child 1: {offspring[0]}')
print(f'Child 2: {offspring[1]}')

Result

Parent 1: x: 0.24, y: 0.13, fitness: 0.2345  
Parent 2: x: 0.1, y: 0.84, fitness: 0.0672  
Child 1:  x: 0.24, y: 0.13, fitness: 0.2345  
Child 2:  x: 0.23, y: 0.24, fitness: 0.2245

We see that Child 1 is the copy of Parent. ์ž์‹ 1์€ ๋ถ€๋ชจ์˜ ๋ณต์ œ๋ณธ์ž„์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


๐Ÿ”ก ์ฃผ์š” ๋‹จ์–ด

์˜์–ด ๋‹จ์–ดํ•œ๊ธ€ ๋œป
driven๊ธฐ๋ฐ˜
destroyํŒŒ๊ดด
accumulate์ถ•์ 
adaptation์ ์‘
unpredictable์˜ˆ์ธก๋ถˆ๊ฐ€
survival์ƒ์กด
brink์ง์ „
species์ข…
appearance์ถœํ˜„

โœจ 4 - Conclusion ๊ฒฐ๋ก 

Crossover is a very specific evolutionary method.
๊ต์ฐจ๋Š” ๋งค์šฐ ๋…ํŠนํ•œ ์ง„ํ™” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค.

While the selection is an objective factor that is determined by nature and environment,
์„ ํƒ์€ ์ž์—ฐ๊ณผ ํ™˜๊ฒฝ์— ์˜ํ•ด ๊ฒฐ์ •๋˜๋Š” ๊ฐ๊ด€์ ์ธ ์š”์†Œ์ธ ๋ฐ˜๋ฉด,

the crossover mechanisms for each species can be very different.
๊ต์ฐจ ๋ฉ”์ปค๋‹ˆ์ฆ˜์€ ์ข…๋งˆ๋‹ค ๋งค์šฐ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

There are insect species that may not use crossbreeding as such!
์–ด๋–ค ๊ณค์ถฉ ์ข…์€ ๊ต๋ฐฐ ์ž์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค!

So, in genetic algorithms, crossover methods are chosen only as the source of the problem to be solved,
๋”ฐ๋ผ์„œ ์œ ์ „ ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ๋Š” ๋ฌธ์ œ์˜ ์„ฑ๊ฒฉ์— ๋งž๊ฒŒ ๊ต์ฐจ ๋ฐฉ์‹์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

and it is impossible to decide in advance which method is better.
์–ด๋–ค ๋ฐฉ์‹์ด ๋” ๋‚˜์€์ง€๋Š” ์‚ฌ์ „์— ๊ฒฐ์ •ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

An incorrectly chosen crossover method can stop the evolutionary improvement of a population,
์ž˜๋ชป ์„ ํƒ๋œ ๊ต์ฐจ ๋ฐฉ์‹์€ ๊ฐœ์ฒด๊ตฐ์˜ ์ง„ํ™”์  ๋ฐœ์ „์„ ๋ฉˆ์ถ”๊ฒŒ ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ,

and therefore make the search for a solution ineffective.
๊ทธ ๊ฒฐ๊ณผ, ํ•ด๋ฅผ ์ฐพ๋Š” ๊ณผ์ •์ด ๋น„ํšจ์œจ์ ์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

In the next chapter, we will study the last part of evolution called mutation.
๋‹ค์Œ ์žฅ์—์„œ๋Š” ์ง„ํ™”์˜ ๋งˆ์ง€๋ง‰ ๋‹จ๊ณ„์ธ ๋Œ์—ฐ๋ณ€์ด์— ๋Œ€ํ•ด ํ•™์Šตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


โœจ 4 - Points to remember ๊ธฐ์–ตํ•  ์ 

Each crossover method has the principle: Try to change the experience of individuals, but not to make soup of the genes, destroying the whole gene structure.
๋ชจ๋“  ๊ต์ฐจ ๋ฐฉ์‹์€ ํ•˜๋‚˜์˜ ์›์น™์„ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค: ๊ฐœ์ฒด์˜ ๊ฒฝํ—˜์€ ๋ฐ”๊พธ๋˜, ์œ ์ „์ž๋ฅผ ๋’ค์„ž์–ด ์ „์ฒด ๊ตฌ์กฐ๋ฅผ ํŒŒ๊ดดํ•˜์ง€๋Š” ๋ง ๊ฒƒ.

There is no predetermined list of crossover methods.
๊ต์ฐจ ๋ฐฉ์‹์—๋Š” ๋ฏธ๋ฆฌ ์ •ํ•ด์ง„ ๋ชฉ๋ก์ด ์žˆ๋Š” ๊ฒƒ์ด ์•„๋‹™๋‹ˆ๋‹ค.

You can implement your own crossover method for specific task.
๋ฌธ์ œ์˜ ์„ฑ๊ฒฉ์— ๋”ฐ๋ผ ์ž์‹ ๋งŒ์˜ ๊ต์ฐจ ๋ฐฉ๋ฒ•์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


โœจ 4 - Multiple choice questions ๊ฐ๊ด€์‹ ๋ฌธ์ œ

Question 1
We have a population of individuals with genes: where x and y lie in range (-10, 10).
x์™€ y๊ฐ€ (-10, 10) ๋ฒ”์œ„์— ์žˆ๋Š” ์œ ์ „์ž๋ฅผ ๊ฐ€์ง„ ๊ฐœ์ฒด๊ตฐ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

We use blend crossover with ฮฑ = 0 in our genetic algorithm flow (without mutation).
์šฐ๋ฆฌ๋Š” ๋Œ์—ฐ๋ณ€์ด ์—†์ด ฮฑ = 0์ธ ๋ธ”๋ Œ๋“œ ๊ต์ฐจ๋งŒ์„ ์‚ฌ์šฉํ•˜๋Š” ์œ ์ „ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ๋ฆ„์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

What can we say about our population after 50 generations?
50์„ธ๋Œ€๊ฐ€ ์ง€๋‚œ ํ›„ ๊ฐœ์ฒด๊ตฐ์— ๋Œ€ํ•ด ์–ด๋–ค ํ˜„์ƒ์ด ๋‚˜ํƒ€๋‚ ๊นŒ์š”?

  • All individuals will be concentrated near one point because the best solution will be found.
    ๋ชจ๋“  ๊ฐœ์ฒด๊ฐ€ ํ•˜๋‚˜์˜ ์  ๊ทผ์ฒ˜๋กœ ๋ชจ์ผ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ์ตœ์  ํ•ด๊ฐ€ ๋ฐœ๊ฒฌ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

  • All individuals will be uniformly distributed in square (-10,10) ร— (-10,10).
    ๋ชจ๋“  ๊ฐœ์ฒด๊ฐ€ (-10,10) ร— (-10,10) ์‚ฌ๊ฐํ˜• ์˜์—ญ์— ๊ท ๋“ฑํ•˜๊ฒŒ ๋ถ„ํฌ๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

  • โœ… All individuals will be concentrated near one point because blend crossover with ฮฑ = 0 doesnโ€™t expand the range of genes and all children genes will be shrinking.
    โœ… ๋ชจ๋“  ๊ฐœ์ฒด๋Š” ํ•˜๋‚˜์˜ ์  ๊ทผ์ฒ˜์— ์ง‘์ค‘๋  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ฮฑ = 0์ธ ๋ธ”๋ Œ๋“œ ๊ต์ฐจ๋Š” ์œ ์ „์ž ๋ฒ”์œ„๋ฅผ ํ™•์žฅํ•˜์ง€ ์•Š์œผ๋ฉฐ, ๋ชจ๋“  ์ž์‹ ์œ ์ „์ž๊ฐ€ ์ ์  ์ˆ˜๋ ด๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.


Question 2
We have a population of individuals with ordered genes: (1 2,โ€ฆ,9).
์ •๋ ฌ๋œ ์œ ์ „์ž (1, 2, โ€ฆ, 9)๋ฅผ ๊ฐ€์ง„ ๊ฐœ์ฒด๊ตฐ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

Our gene structure is very fragile and there is a high probability that after each crossover, new offspring will be worse than their parents.
์šฐ๋ฆฌ์˜ ์œ ์ „์ž ๊ตฌ์กฐ๋Š” ๋งค์šฐ ๋ฏผ๊ฐํ•ด์„œ, ๊ต์ฐจ ์ดํ›„ ์ž์‹์ด ๋ถ€๋ชจ๋ณด๋‹ค ๋ชปํ•œ ๊ฒฝ์šฐ๊ฐ€ ์ž์ฃผ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

What approach can we use to solve that issue?
์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ์ ‘๊ทผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?

  • Order Crossover
    ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ

  • โœ… Fitness Driven Crossover based on Order Crossover
    โœ… ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํ•œ ์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ : ์ˆœ์„œ ์œ ์ง€ + ์„ฑ๋Šฅ ๋ณด์žฅ์ด๋ผ๋Š” ๋‘ ๊ฐ€์ง€ ์กฐ๊ฑด์„ ๋งŒ์กฑ

  • One Point Crossover
    ๋‹จ์ผ ์ง€์  ๊ต์ฐจ

  • Fitness Driven Crossover based on Uniform Crossover
    ๊ท ๋“ฑ ๊ต์ฐจ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํ•œ ์ ํ•ฉ๋„ ๊ธฐ๋ฐ˜ ๊ต์ฐจ


โœจ 4 - Questions ์งˆ๋ฌธ

1. Why the usage of blend crossover with very high ฮฑ can lead to poor results of genetic algorithm execution?
๋ธ”๋ Œ๋“œ ๊ต์ฐจ์—์„œ ฮฑ ๊ฐ’์ด ๋„ˆ๋ฌด ํด ๊ฒฝ์šฐ, ์™œ ์œ ์ „ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์„ฑ๋Šฅ์ด ๋–จ์–ด์งˆ ์ˆ˜ ์žˆ์„๊นŒ์š”?

โœ”๏ธ ฮฑ๊ฐ€ ๋„ˆ๋ฌด ํฌ๋ฉด ์ž์‹ ์œ ์ „์ž๊ฐ€ ๋ถ€๋ชจ ๋ฒ”์œ„๋ฅผ ํ›จ์”ฌ ๋„˜์–ด์„œ๊ฒŒ ๋˜์–ด, ๋ฌด์ž‘์œ„์„ฑ์ด ๊ณผ๋„ํ•˜๊ฒŒ ์ปค์ง€๊ณ  ์œ ์šฉํ•œ ์œ ์ „์ž ๊ตฌ์กฐ๊ฐ€ ์†์ƒ๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.


2, Say we have a real gene set for genetic algorithm finding maxima of multivariable function f(x, y, z). Can we get acceptable results with the usage of order crossover here?
f(x, y, z)๋ผ๋Š” ๋‹ค๋ณ€์ˆ˜ ํ•จ์ˆ˜์˜ ์ตœ๋Œ€๊ฐ’์„ ์ฐพ๋Š” ์œ ์ „ ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ์‹ค์ˆ˜ํ˜• ์œ ์ „์ž ์ง‘ํ•ฉ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋ฅผ ์ ์šฉํ•ด๋„ ๊ดœ์ฐฎ์€ ๊ฒฐ๊ณผ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์„๊นŒ์š”?

โœ”๏ธ ์•„๋‹ˆ์š”. ์ˆœ์„œ ๊ธฐ๋ฐ˜ ๊ต์ฐจ๋Š” ์ˆœ์—ด ๊ธฐ๋ฐ˜ ์œ ์ „์ž(์˜ˆ: ์™ธํŒ์› ๋ฌธ์ œ)์ฒ˜๋Ÿผ ์ˆœ์„œ๊ฐ€ ์ค‘์š”ํ•œ ๋ฌธ์ œ์— ๋งž์ถฐ ์„ค๊ณ„๋œ ๋ฐฉ์‹์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.