Tải bản đầy đủ (.pdf) (20 trang)

Tài liệu giải thuật di truyền

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (675.63 KB, 20 trang )

ị nguyên
– Tập có thứ tự các ký tự

• Các kiểu biến dị khác nhau
41

Lai ghép đồng nhất





42

Lai ghép hay đột biến

Gán ‘đầu’

đầu vào 1 ccha,
a, ‘đuôi’
đuô vào 1 cchaa khác
ác
Tung đồng xu cho mỗi gene của con đầu tiên
Làm 1 bản sao đảo của gene cho con thứ 2
Sự kế thừa độc lập vị trí

– Phụ thuộc vào bài toán,
toán nhưng
– Tốt nhất nên có cả 2
– Nếu chỉ đột biến, có thể tiến hóa
– Nếu chỉ lai ghép , không tiến hóa



43

44

11


7/21/2012

Lai ghép hay đột biến

Lai ghép hay đột biến

Khám phá: Phát hiện các vùng hứa hẹn trong không gian tìm

• Chỉ có lai ghép có thể kết hợp các thông tin từ thế hệ cha

kiế tứ
kiếm,
tức là lấy
lấ đđược thô
thông tin
ti từ bài toán
t á
Khai thác: Tối ưu hóa trong vùng hứa hẹn, tức là sử dụng thông
tin

• Chỉ có đột biến tạo ra các thông tin mới (gene)
• lai ghép không thay đổi tần suất của gene trong quần thể

• Để đạt được kết quả tối ưu, cần 1 chút may mắn trong phép
đột biến

Thường kết hợp cả 2 phương pháp này.
a ghép
g ép làà việc
v ệc khám
á phá,
p á, nóó sẽ làà 1 bước nhảy
ảy đế
đến 1 miền
ề nào
ào
• Lai
đó trong 2 cá thể bố mẹ
• Đột biến là việc khai thác, nó tạo ra 1 sự thay đổi nhỏ, vì vậy nó
ở gần miền của cha nó
45

Các cách biểu diễn khác

46

Biểu diễn dạng số nguyên

Có thể mã hóa các biến số trực tiếp dưới dạng:
• Mộ
Một số
ố bài toán
á sử

ử ddụng số
ố nguyên
ê để biể
biểu diễ
diễn như
h xử
ử lý
ảnh
• Một số bài toán khác sử dụng các giá trị từ 1 tập cố định, vd
{blue, green, yellow, pink}
• Có thể sử dụng phép toán lai ghép 1 điểm hoặc N điểm

• Số nguyên
• Các biến dấu phẩy động

47

48

12


7/21/2012

Biểu diễn dạng số thực

Chuyển số thực về dạng chuỗi bit
z ∈ [x,y] ⊆ ℜ chuyển về dạng {a1,…,aL} ∈ {0,1}L

• VD

VD: bài toán
á tối
ối ưu các
á tham
h sốố dạng
d
liên
liê tục
n
f:ℜ Æℜ
• Hàm Ackley

• [x,y] → {0,1}L
• Hàm Γ: {0,1}L → [x,y] xác định phép biểu diễn

Γ( a1 ,,...,, aL ) = x +

y − x L−1
⋅ ( ∑ aL− j ⋅ 2 j ) ∈ [ x, y ]
2 L − 1 j =0

• Chỉ biểu diễn qua 2L giá trị
• L quyết định độ chính xác của phương pháp
• Độ chính xác cao Æ cá thể dài Æ hội tụ chậm
49

Phép đột biến dấu phẩy động

Đột biến dấu phẩy động


Sơ đồ tổng quát

• Đột biến không duy nhất:

x = x1 , ..., xl → x ′ = x1′ , ..., xl′
xi , xi′ ∈ [LBi , UBi ]
z

– Có nhiều phương pháp, vd các thay đổi theo khoảng
thời gian
– Phần lớn lược đồ là xác suất, nhưng thường tạo nên
thay đổi nhỏ ở giá trị
– Phương pháp thông dụng nhất là thêm 1 sai số ngẫu
nhiên vào mỗi biến,, lấyy giá
g trịị dựa
ự trên pphân bố
Gaussian N(0, σ) và sau đó rút gọn cho ở trong khoảng
nhất định
– Độ lệch chuẩn σ kiểm soát số thay đổi (2/3 các độ lệch
ở trong khoảng (- σ đến + σ)

Đột biến tại 1 điểm
z

50

X’i chọn ngẫu nhiên trong khoảng [LBi,UBi]

51


52

13


7/21/2012

Lai ghép với số thực

Lai ghép theo công thức đơn

• Rời rạc
– Mỗi NST trong cá thể con z lấy từ cá thể bố mẹ
(x y) với xác suất như nhau zi = xi or yi
(x,y)
– Có thể sử dụng n điểm hoặc 1 điểm

• Liên tục
– Tạo con “giữa” các cha (sử dụng công thức toán
học để kết hợp)
– zi = α xi + (1 - α) yi với α : 0 ≤ α ≤ 1.
1
– α có thể là :





Bố mẹ: 〈x1,…,xn 〉 và 〈y1,…,yn〉
Lấ ngẫu

Lấy
ẫ nhiên
hiê 1 NST k
Con thứ 1 là




Con thứ 2 ngược lại
VD: α = 0.5

x1 , ..., xk , α ⋅ yk + (1 − α ) ⋅ xk , ..., xn

• Hằng số
• Biến
• Lấy ngẫu nhiên mỗi lần thực hiện

53

54

Lai ghép theo công thức đơn



Lai ghép toàn bộ theo công thức

Bố mẹ: 〈x1,…,xn 〉 và 〈y1,…,yn〉
Lấy ngẫu nhiên 1 NST k. Sau điểm này, các giá trị là


x , ..., x , α ⋅ y
+ (1 − α ) ⋅ x
, ..., α ⋅ y + (1 − α ) ⋅ x
1
k
k +1
k +1
n
n



Con thứ 2 ngược lại
VD: α = 0.5

55





Hay dùng
Bố mẹ: 〈x1,…,xxn 〉 và 〈y1,…,yyn〉
Con 1:




Con thứ 2 ngược lại
VD: α = 0.5


a ⋅ x + (1 − a ) ⋅ y

56

14


7/21/2012

Biểu diễn phép hoán vị: VD bài toán TSP

Biểu diễn phép hoán vị




Bài toán sắp
p thứ tự

VD: thuật toán sắp xếp: các thành phàn quan trọng được xếp
trước
VD bài toán người du lịch - Travelling Salesman Problem
(TSP) :

• Bài toán:
• Có n thành phố
• Tìm hành trình với độ dài ngắn
nhất


• Mã hóa:
• Các thành phố 1,2, … , n
• 1 đường đi hoàn chỉnh là 1 phép
h á vịị (vd
hoán
( d n =4
4 [1,2,3,4],
[1 2 3 4]
[3,4,2,1] )
• Không gian tìm kiếm lớn :
30 thành phố Æ 30! ≈ 1032 hành
trình

57

Phép đột biến cho hoán vị

58

Đột biến kiểu chèn

• Các phép đột biến thông thường đem lại giải
pháp vi phạm điều kiện bài toán
• Cần thay đổi ít nhất 2 biến
• Tham số cho đột biến phản ánh xác suất 1 số
thao tác được áp dụng cho toàn xâu, thay vì
cho 1 vịị trí

59


• Lấy ngẫu nhiên 2 NST
• Chuyển NST thứ 2 theo sau cái thứ 1, dịch
phần còn lại sang phải
• Phép đột biến này giữ lại hầu hết trật tự các
NST và thông
g tin về sự
ự liền kề của chúng
g

60

15


7/21/2012

Đột biến kiểu đảo

Đột biến kiểu trộn
• Lấy ngẫu nhiên 2 NST và đổi chỗ của
chúng
• Giữ lại được hầu hết thông tin về sự liền kề
của chúng, phá vỡ trật tự nhiều hơn

• Lấy ngẫu nhiên 2 NST và đổi chỗ các NST
nằm giữa chúng
• Giữ lại được hầu hết thông tin về sự liền kề
của chúng, nhưng phá vỡ trật tự các NST

61


Đột biến kiểu ngẫu nhiên

62

Phép lai ghép cho chuỗi hoán vị
• “Normal
Normal”

crossover operators will often lead
to inadmissible solutions

• Lấy ngẫu nhiên 1 tập con các NST
• Sắp xếp lại 1 cách ngẫu nhiên các NST đó

(các tập con không nhất thiết phải liên tục)
t c)

63

12345

12321

54321

54345

• Many specialised operators have been
devised which focus on combining order or

adjacency information from the two parents64

16


7/21/2012

1 4| 5 9 3| 2 7 8 6
Order 1 crossover
2 5|example
7 8 9| 1 6 3 4

Order 1 crossover
• Idea is to preserve relative order that elements occur
p
• Informal procedure:
1. Choose an arbitrary part from the first parent
2. Copy this part to the first child
3. Copy the numbers that are not in the first part, to the first
child:
• starting right from cut point of the copied part,
• using the order of the second parent
• and wrapping around at the end
4. Analogous for the second child, with parent roles
reversed

• Copy randomly selected set from first parent

• Copy
C

restt from
f
secondd parentt in
i order
d 1,9,3,8,2
19382

65

66

1 4| 5 9 3| 2 7 8 6
PMX example
2 5| 7 8 9| 1 6 3 4

Partially Mapped Crossover (PMX)
Informal procedure for parents P1 and P2:
1. Choose random segment and copy it from P1
2. Starting from the first crossover point look for elements in that segment of
P2 that have not been copied
3. For each of these i look in the offspring to see what element j has been
copied in its place from P1
4. Place i into the position occupied j in P2, since we know that we will not
be putting j there (as is already in offspring)
5. If the place occupied by j in P2 has already been filled in the offspring k,
put i in the position occupied by k in P2
6. Having dealt with the elements from the crossover segment, the rest of the
offspring can be filled from P2.
Second child is created analogously
67


• Step 1

• Step 2

• Step 3

68

17


7/21/2012

1 4| 5 9 3| 2 7 8 6
5| 7 8 9| 1 6 3 4
Cycle crossover2 example

Cycle crossover
Basic idea:
Each allele comes from one parent together with its position.

• Step
p 1: identifyy cycles
y

Informal procedure:
1. Make a cycle of alleles from P1 in the following way.
(a) Start with the first allele of P1.
(b) Look at the allele at the same position in P2.

(c) Go to the position with the same allele in P1.
(d) Add
dd thiss allele
a e e too thee cycle.
cyc e.
(e) Repeat step b through d until you arrive at the first allele of P1.

• Step 2: copy alternate cycles into offspring

2. Put the alleles of the cycle in the first child on the positions they
have in the first parent.
3. Take next cycle from second parent
69

145932786
Edge Recombination
257891634

• Works by constructing a table listing which
edges
g are present
p
in the two parents,
p
, if an
edge is common to both, mark with a +
• e.g. [1 2 3 4 5 6 7 8 9] and [9 3 7 8 2 6 5
1 4]

70


Edge Recombination
Informal procedure once edge table is constructed
1. Pick an initial element at random and put it in the offspring
2. Set the variable current element = entry
3. Remove all references to current element from the table
4. Examine list for current element:
– If there is a common edge, pick that to be next element
– Otherwise pick the entry in the list which itself has the shortest list
– Ties are split at random

5. In the case of reaching an empty list:
– Examine the other end of the offspring is for extension
– Otherwise a new element is chosen at random
71

72

18


7/21/2012

145932786
Edge Recombination
2 5 7example
891634

Population Models
• SGA uses a Generational model:

– each individual survives for exactly one generation
– the
th entire
ti sett off parents
t is
i replaced
l d by
b the
th offspring
ff i
• At the other end of the scale are Steady-State models:
– one offspring is generated per generation,
– one member of population replaced,
• Generation Gap
– the proportion of the population replaced
– 1.0 for GGA, 1/pop_size for SSGA

73

74

Fitness Based Competition
Example application of order based GAs: JSSP
• Selection can occur in two places:
– Selection from current generation to take part in
mating (parent selection)
– Selection from parents + offspring to go into next
generation (survivor selection)
• Distinction between selection
– operators: define selection probabilities

– algorithms: define how probabilities are
implemented
75

Precedence
ecede ce constrained
co st a ed job shop
s op scheduling
sc edu g problem
p ob e







J is a set of jobs.
O is a set of operations
M is a set of machines
Able ⊆ O × M defines which machines can perform which operations
Pre ⊆ O × O defines which operation should precede which
Dur : ⊆ O × M → IR defines the duration of o ∈ O on m ∈ M

The goal is now to find a schedule that is:
• Complete: all jobs are scheduled
• Correct: all conditions defined by Able and Pre are satisfied
• Optimal: the total duration of the schedule is minimal
76


19


7/21/2012

Precedence constrained job shop scheduling GA
• Representation: individuals are permutations of operations
• Permutations are decoded to schedules by a decoding procedure
– take the first (next) operation from the individual
– look up its machine (here we assume there is only one)
– assign the earliest possible starting time on this machine, subject to
• machine occupation
• precedence relations holding for this operation in the schedule created so far

• fitness of a permutation is the duration of the corresponding schedule (to be
minimized)
• use any suitable mutation and crossover
• use roulette wheel parent selection on inverse fitness
• Generational GA model for survivor selection
• use random initialisation
77

20



×