Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

CTI 2G3 Sistem Cerdas

Pertemuan 4: Metaheuristic Search


Author-Tim Dosen

Program Studi Teknologi Informasi

1 17/04/2021
Review-Metode Pencarian
Searching

Un-
Informed
informed

Greedy
BFS DFS A*
BFS

UCS DLS IDA*

IDS BDA*

2 17/04/2021
Large Solution Space - 13,509 cities in
the US

3 17/04/2021
Large Problem Space

1,904,711-city instance of locations,


http://www.tsp.gatech.edu/world/ima
ges/world.anim5a.gif

4 17/04/2021
Large Problem Space

http://www.tsp.gatech.edu/data/ml/
mona-lisa100K.gif

5 17/04/2021
Mona Lisa TSP
The current best known results for the Mona Lisa TSP:
Tour: 5,757,191 Bound: 5,757,072 Gap: 119 (0.0021%)
The tour was found on March 17, 2009, by Yuichi Nagata. The bound gives a
value B such that no tour has length less than B; this bound was found on
November 25, 2011, with the Concorde code.
The Gap number is the gap in our knowledge, that is, the difference between
the length of the tour and the value of the bound.
It has been over two years since Yuichi Nagata produced the best-known
tour. To help perk up interest in searching for an even better solution, we are
offering a $1,000 prize to the first person to find a tour shorter than
5,757,191.

6 17/04/2021
Our current best weapon A* [1]
A* = Sejarah + Masa Depan
– Sejarah (aktual) adalah baik.
– Masa Depan (prediksi) itu diperlukan.
– Sejarah bisa menjadi Pelajaran Berharga.
– “Jangan sekali-kali melupakan sejarah” [Soekarno].
– Sejarah yang ditulis Pemenang = ???
– Sikap kritis sangat diperlukan.

7 17/04/2021
Our current best weapon A* [2]
Perbandingan IDS dengan A* yang menggunakan h1 dan h2. Data yang digunakan
adalah rata-rata 100 kasus 8-puzzle dengan kedalaman solusi yang bervariasi [RUS95].

Jumlah node yang dibangkitkan Faktor percabangan


d
IDS A* (h 1 ) A* (h 2 ) IDS A* (h 1 ) A* (h 2 )
2 10 6 6 2,45 1,79 1,79
4 112 13 12 2,87 1,48 1,45
6 680 20 18 2,73 1,34 1,3
8 6.384 39 25 2,8 1,33 1,24
10 47.127 93 39 2,79 1,38 1,22
12 364.404 227 73 2,78 1,42 1,24
14 3.473.941 539 113 2,83 1,44 1,23
16 - 1.301 211 - 1,45 1,25
18 - 3.056 363 - 1,46 1,26
20 - 7.276 676 - 1,47 1,27
22 - 18.094 1.219 - 1,48 1,28
24 - 39.135 1.641 - 1,48 1,26

8 17/04/2021
So what’s with large problem space
TSP dengan 100 lokasi
Seorang kurir punya waktu kerja: 8 jam

Manual Software A Software B


Kriteria
(berpikir) (Dijkstra) (??)

Waktu running 0 2 jam 10 menit

Rute yang
11 jam 7 jam 7 jam 20 menit
dihasilkan
11 jam 9 jam 7,5 jam
Total Waktu
(lembur 3 jam) (lembur 1 jam) (tidak lembur)

9 17/04/2021
Optimasi [1]
Deterministic
State Space Search Dynamic Programming Branch and Bound

Probabilistic
Monte Carlo Algorithms

Simulated Evolutionary
Annealing (SA) Computation (EC)

Harmony Search
Tabu Search (TS)
(HS)

Random Artificial Immune


Optimization System (AIS)

Evolutionary Swarm Intelligence Particel Swarm


Paralel Tempering
Algorithms (EAs) (SI) Optimization

Stochastic Learning Classifier Ant Colony


Cultural Algorithms
Tunneling System (LCS) Optimization

Direct Monte Carlo Genetic Algoritms Artificial Bee


Artificial Life
Sampling (GA) Colony Algorithm

Evolutionary
Memetic Algorithm
Programming

Evolution Differential
Strategies (ES) Evolution (DE)

Genetic
Standard GP
Programming (GP)

Linear GP

Grammatical
Guided GP

10 17/04/2021
Optimasi [2]

Jika d = 10, berapa luas lingkaran?


r 2 = (22 / 7)(52 )
= 78,57

10
Luas = (12/16).100
= 75

Lebih akurat jika


ribuan titik.

11 17/04/2021
Optimasi [3]

Jika d = 10, berapa luas area merah?


Luas lingkaran – luas
bulan sabit – 2 x luas
bintang = SULIT ???
10

Luas = (12/20).100
= 60

Lebih akurat jika


ribuan titik.
12 17/04/2021
Optimasi [4]

Berapa luas area merah?


Luas = ???

Model matematis ??

10
Luas = (16/20).100
= 80

Lebih akurat jika


ribuan titik.

10
13 17/04/2021
Evolutionary Computation
EC: abstraction from the theory of biological
evolution that is used to create optimization
procedures or methodologies, usually
implemented on computers, that are used to solve
problems“ [JUL07].

14 17/04/2021
Teori Evolusi
•Ilmuwan Berbeda pendapat
• Pro: Alam tercipta secara acak
• Kontra: Alam diciptakan oleh intelligent designer (Tuhan)
• Spesies ber-evolusi menjadi spesies lain yang lebih baik???

Evolusi

Seleksi Alam Mutasi

15 17/04/2021
Mutasi: bisa lebih baik?

• Struktur DNA amat sangat rumit !


• Perubahan acak (mutasi) selalu buruk !!
Ref: [ADN07]
16 17/04/2021
James Watson & Francis Crick [www.nature.com]

17 17/04/2021
Optimization Algorithms

Deterministic
State Space Search Dynamic Programming Branch and Bound

Probabilistic
Monte Carlo Algorithms

Simulated Evolutionary
Annealing (SA) Computation (EC)

Harmony Search
Tabu Search (TS)
(HS)

Random Artificial Immune


Optimization System (AIS)

Evolutionary Swarm Intelligence Particel Swarm


Paralel Tempering
Algorithms (EAs) (SI) Optimization

Stochastic Learning Classifier Ant Colony


Cultural Algorithms
Tunneling System (LCS) Optimization

Direct Monte Carlo Genetic Algoritms Artificial Bee


Artificial Life
Sampling (GA) Colony Algorithm

Evolutionary
Memetic Algorithm
Programming

Evolution Differential
Strategies (ES) Evolution (DE)

Genetic
Standard GP
Programming (GP)

Linear GP

Grammatical
Guided GP

18 17/04/2021
Skema umum EAs
Seleksi orangtua
Orangtua

Inisialisasi

Rekombinasi

Populasi
Mutasi

Terminasi

Anak
Seleksi survivor

19 17/04/2021
Beberapa algoritma EAs
1. Genetic Algorithms (GA): binary strings
2. Evolution Strategies (ES): real-valued vectors
3. Evolutionary Programming (EP): finite state
machines
4. Genetic Programming (GP): LISP trees
5. Differential Evolution (DE)  ES
6. Grammatical Evolution (GE)  GP

20 17/04/2021
Representasi Individu dan Fungsi Fitness

21 4/17/2021
genome

kromosom

...
...
...

gen genotype
Representasi Biner

Phenotype: x1 = 7 dan x2 = 5

Genotype dengan binary encoding:

x1 x2

0 1 1 1 0 1 0 1
Representasi Biner

(ra − rb )
x = rb + N
( g1.2 −1 + g 2 .2 − 2 + ... + g N .2 − N )
 2
i =1
−i

Rentang Nilai: [-
1, 2]
Representasi Integer
(ra − rb )
x = rb + N
( g1.10 −1 + g 2 .10 − 2 + ... + g N .10 − N )
 9.
i =1
10 −i

individu: x1 = -0,96096 dan x2 = 2 Rentang Nilai: [-


1, 2]

x1 x2

0 1 3 9 9 9
Representasi Real

x = rb + (ra − rb ) ( g1 + g 2 + ... + g N )

individu: x1 = -0,2830 dan x2 = 2 Rentang Nilai: [-


1, 2]

x1 x2

0,2390 1,0000
Representasi Permutasi
Individu: urutan kunjungan semua lokasi

10
3
9
4
8
1
7

5
2
4
5
3

2
6
1

0
0 1 2 3 4 5 6 7 8 9 10

Kromosom: 1 5 2 6 3 4
1 2 3 4 5 6

Nilai gen menyatakan nomor lokasi

Posisi gen menyatakan urutan kunjungan


Fungsi Fitness

Maksimasi: f = h

1
Minimasi: f =
(h + a)
Fungsi Fitness

Maksimasi: f = h

1
Minimasi: f =
(h + a)
Seleksi Orangtua

30 4/17/2021
Seleksi Orangtua

1. Roulette wheel
2. Baker’s SUS (Stochastic Universal Sampling)
3. Tournament Selection
Roulette Wheel
Kromosom Fitness

K1 2

K4
K2 1

K1
K3 1

K3
K4 4

K2
Jumlah 8

Putaran ke-1

K2 K3

K4
K4
K3
K3

K2 K1
K4
K2

K1
K1

Putaran ke-2 Putaran ke-3 Putaran ke-4


Baker’s SUS

2 3
Kromosom Fitness

K1 2
K4 K1
K2 1

K3 1
K2
K4 4 K3

Jumlah 8
1 4
Kelemahan Baker’s SUS

2 3
Kromosom Fitness

K1 1,98
K4 K1
K2 2,01

K3 1,99
K3 K2
K4 2,02

Jumlah 8
1 4
Kelemahan Baker’s SUS

2 3
Kromosom Fitness
K1 K2 K3
K1 1

K2 1

K3 1 K4
K4 17

Jumlah 20
1 4
Tournament Selection

K1 0 1 1 1 0 1 1 1 0 1 0 1
.
.
K7 1 0 1 1 0 0 1 1 0 1 0 1
. K1 0 1 1 1 0 1 1 1 0 1 0 1
. K2 1 0 1 1 0 0 1 1 0 1 0 1
K30 1 1 1 1 0 1 1 1 1 1 1 1
K3 1 1 1 1 0 1 1 1 1 1 1 1
.
. K4 1 1 0 0 0 0 0 0 0 1 0 1

K61 1 1 0 0 0 0 0 0 0 1 0 1 K5 0 1 1 0 0 0 1 0 0 1 0 0
.
.
. Terpilih sebagai
K100 0 1 1 0 0 0 1 0 0 1 0 0
orangtua berdasarkan
prosedur tertentu

Populasi berukuran N = 100 individu Turnamen berukuran k = 5


Rekombinasi

37 4/17/2021
Rekombinasi

• Rekombinasi untuk representasi Biner


• Rekombinasi untuk representasi Integer
• Rekombinasi untuk representasi Real
• Rekombinasi untuk representasi Permutasi
Rekombinasi untuk Rep. Biner

• Rekombinasi satu titik (1-point crossover)


• Rekombinasi banyak titik (Multipoint crossover)
• Rekombinasi seragam (uniform crossover)
Rekombinasi satu titik

Titik potong

Orangtua 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 0 Anak 1

Orangtua 2 0 1 1 0 1 1 1 0 0 1 1 1 0 1 0 1 Anak 2
Rekombinasi banyak titik

Titik 1 Titik 2

Orangtua 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 Anak 1

Orangtua 2 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 0 Anak 2

(a)
Titik 1 Titik 2 Titik 3

Orangtua 1 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0 0 Anak 1

Orangtua 2 0 1 1 0 1 1 1 0 0 0 1 1 1 1 1 1 Anak 2

(b)
Rekombinasi Seragam

Orangtua 1 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 0 Anak 1

Pola 0 1 0 0 1 0 1 1

Orangtua 2 0 1 1 0 1 1 1 0 0 0 1 0 0 1 0 1 Anak 2
Rekombinasi untuk Rep. Integer

Rekombinasi satu titik (1-point crossover)


Rekombinasi banyak titik (Multipoint crossover)
Rekombinasi seragam (uniform crossover)
Rekombinasi untuk Rep. Real

• Discrete Crossover
• Single Arithmetic Crossover
• Simple Arithmetic Crossover
• Whole Arithmetic Crossover
Discrete Crossover

• Setiap gen pada anak z berasal dari salah satu


orangtuanya (x,y) dengan probabilitas yang
sama, zi = xi or yi
• Cara pemilihan posisi gen bisa menggunakan
rekombinasi banyak titik atau rekombinasi
seragam
Single arithmetic crossover

Alfa = 0,7

0,5 0,1 0,2 0,3 0,8 0,2 0,7 0,5 0,1 0,2 0,3 0,52 0,2 0,7

0,2 0,7 0,3 0,5 0,4 0,1 0,9 0,2 0,7 0,3 0,5 0,68 0,1 0,9

Anak 1 : x1 ,..., xk −1 , y k + (1 −  ) xk ,..., xn


Anak 2 : y1 ,..., y k −1 , xk + (1 −  ) y k ,..., y n
Simple arithmetic crossover

Alfa = 0,5

0,5 0,1 0,2 0,3 0,8 0,2 0,7 0,5 0,1 0,2 0,3 0,8 0,15 0,8

0,2 0,7 0,3 0,5 0,4 0,1 0,9 0,2 0,7 0,3 0,5 0,4 0,15 0,8

Anak 1 : x1 ,..., xk , y k +1 + (1 −  ) xk +1 ,...,y n + (1 −  ) xn


Anak 2 : y1 ,..., y k , xk +1 + (1 −  ) y k +1 ,...,xn + (1 −  ) y n
Whole arithmetic crossover

Alfa = 0,5

0,5 0,1 0,2 0,3 0,8 0,2 0,7 0,35 0,4 0,25 0,4 0,6 0,15 0,8

0,2 0,7 0,3 0,5 0,4 0,1 0,9 0,35 0,4 0,25 0,4 0,6 0,15 0,8

Anak 1 :   x + (1 −  )  y
Anak 2 :   y + (1 −  )  .x
Rekombinasi untuk Rep. Permutasi

• Order Crossover
• Partially Mapped Crossover
• Cycle Crossover
• Edge Recombination
Order Crossover

TP1 TP2

Orangtua 1 1 5 2 7 6 4 8 3 2 7 6 Anak 1

Orangtua 2 3 2 1 8 4 6 7 5 1 8 4 Anak 2

Gen orangtua 2 yang belum ada di Anak 1, 8 4 2 7 6 5 3 1 Anak 1


terurut setelah TP2: {5, 3, 1, 8, 4}

Gen orangtua 1 yang belum ada di Anak 2, 7 6 1 8 4 3 5 2 Anak 2


terurut setelah TP2: {3, 5, 2, 7, 6}
Order Crossover

TP1 TP2

Orangtua 1 1 5 2 7 6 4 8 3 2 7 6 Anak 1

Orangtua 2 3 2 1 8 4 6 7 5 1 8 4 Anak 2

Gen orangtua 2 yang belum ada di Anak 1, 8 4 2 7 6 5 3 1 Anak 1


terurut setelah TP2: {5, 3, 1, 8, 4}

Gen orangtua 1 yang belum ada di Anak 2, 7 6 1 8 4 3 5 2 Anak 2


terurut setelah TP2: {3, 5, 2, 7, 6}
Mutasi

52 4/17/2021
Mutasi

• Mutasi bersifat kecil, acak, berbahaya, dan jarang


terjadi.
• Jika terjadi, kemungkinan besar mutasi itu tidak
berguna.

• Empat karakteristik mutasi ini menunjukkan bahwa


mutasi tidak dapat mengarah pada perkembangan
evolusioner.
• Suatu perubahan acak pada organisme yang sangat
terspesialisasi bersifat tidak berguna atau
membahayakan.
Mutasi: bisa lebih baik?

• Struktur DNA amat sangat rumit !


• Perubahan acak (mutasi) selalu buruk !!
Mutasi pada EA

• Mutasi untuk representasi Biner


• Mutasi untuk representasi Integer
• Mutasi untuk representasi Real
• Mutasi untuk representasi Permutasi
Mutasi untuk Representasi Biner

Kromosom awal Kromosom hasil mutasi


0 1 1 0 1 1 1 0 0 0 1 0 1 1 1 0

a <= Pm

Membalik bit: 1 → 0 dan


sebaliknya.
Mutasi untuk representasi Integer

• Membalik nilai integer


• Memilih nilai secara acak
• Mutasi Creep (Perlahan)
Mutasi untuk Representasi Integer

Membalik nilai integer

Kromosom awal Kromosom hasil mutasi


3 6 1 0 5 1 2 9 3 6 8 0 5 1 2 9

a <= Pm
Mutasi untuk Representasi Integer

Memilih nilai secara acak

Kromosom awal Kromosom hasil mutasi


3 6 1 0 5 1 2 9 3 6 5 0 5 1 2 9

a <= Pm
Mutasi untuk Representasi Integer

Probabilitas
Mutasi Creep (Perlahan)

Kromosom awal Kromosom hasil mutasi


3 6 1 0 5 1 2 9 3 6 2 0 5 1 2 9
-3 -2 -1 0 1 2 3
a <= Pm Nilai perubahan
Mutasi untuk Representasi Real

• Mutasi Uniform
• Mutasi Non-uniform dengan distribusi tetap
Mutasi untuk Rep. Permutasi

• Mutasi harus menghasilkan kromosom yang valid

• Mutasi dilakukan secara khusus yang menjamin kromosom hasil mutasi


tetap valid

• Banyak cara yang bisa digunakan, diantaranya adalah:


• Mutasi pertukaran (Swap Mutation)
• Mutasi penyisipan (Insert Mutation)
• Mutasi pengacakan (Scramble Mutation)
• Mutasi pembalikan (Inversion Mutation)
Mutasi Pertukaran (Swap
Mutation)

Kromosom awal Kromosom hasil mutasi


1 5 2 7 6 4 8 3 1 8 2 7 6 4 5 3

Swap Mutation. Pemilihan gen secara acak menghasilkan


gen yang bernilai 5 dan 8. Sehingga gen bernilai 5
dipertukarkan dengan gen bernilai 8.
Mutasi Penyisipan (Insert
Mutation)

Kromosom awal Kromosom hasil mutasi


1 5 2 7 6 4 8 3 1 5 8 2 7 6 4 3

Mutasi penyisipan (Insert Mutation). Pemilihan dua


posisi gen secara acak menghasilkan gen bernilai 5 dan
8. Kemudian gen bernilai 8 disisipkan setelah gen
bernilai 5.
Mutasi Pengacakan (Scramble Mutation)

Kromosom awal Kromosom hasil mutasi


1 5 2 7 6 4 8 3 1 2 6 5 7 8 4 3

Mutasi pengacakan (Scramble Mutation). Pemilihan


segmen kromosom menghasilkan {5, 2, 7, 6}. Kemudian
pengacakan gen dalam segmen menghasilkan {2, 6, 5, 7}
Mutasi Pembalikan (Inversion
Mutation)

Kromosom awal Kromosom hasil mutasi


1 5 2 7 6 4 8 3 1 6 7 2 5 8 4 3

Mutasi pembalikan (Inversion Mutation). Pemilihan


segmen kromosom menghasilkan {5, 2, 7, 6}. Kemudian
pembalikan posisi gen dalam segmen tersebut
menghasilkan {6, 7, 2, 5}.
Seleksi Survivor

67 4/17/2021
Seleksi Survivor

• Generational Model
• Steady State Model
K1 1 1 0 0 0 0 0 1
Pas 1
K3 0 0 1 1 0 0 0 0
K1 1 1 0 0 0 0 0 1
Seleksi
orangtua K2 1 1 0 0 0 0 0 1
K2 1 0 0 1 0 0 1 1 Pas 2
KN 0 0 1 1 0 0 0 0
K3 1 0 0 1 0 0 1 1

. .
. .
. .

KN 1 0 0 0 1 0 0 1
K1 1 1 0 0 0 0 0 1
Pas
K2 1 0 0 1 0 0 1 1 N/2

Generasi 1: Populasi N kromosom/individu Mating pool: N/2 pasang kromosom orangtua

Rekombinasi
Penggantian dan Mutasi
N kromosom

K1 0 0 0 0 1 1 0 1

K2 0 1 0 1 0 0 0 1

K3 0 1 0 0 1 0 1 0

.
.
.

KN 1 1 0 0 1 1 1 1

N kromosom baru
Seleksi Survivor: Generational
K1 1 1 0 0 0 0 0 1
Pas 1
K3 0 0 1 1 0 0 0 0
K1 1 1 0 0 0 0 0 1
Seleksi
orangtua K2 1 1 0 0 0 0 0 1
K2 1 0 0 1 0 0 1 1 Pas 2
KN 0 0 1 1 0 0 0 0
K3 1 0 0 1 0 0 1 1

. .
. .
. .

KN 1 0 0 0 1 0 0 1
K1 1 1 0 0 0 0 0 1
Pas
K2 1 0 0 1 0 0 1 1 N/2

Generasi 1: Populasi N kromosom/individu Mating pool: N/2 pasang kromosom orangtua

Rekombinasi
Penggantian dan Mutasi
N kromosom

K1 0 0 0 0 1 1 0 1

K2 0 1 0 1 0 0 0 1

K3 0 1 0 0 1 0 1 0

.
.
.

KN 1 1 0 0 1 1 1 1

N kromosom baru
Seleksi Survivor: Generational
K1 1 1 0 0 0 0 0 1
K1 1 1 0 0 0 0 0 1 Pas 1
Seleksi
orangtua K3 0 0 1 1 0 0 0 0
K2 1 0 0 1 0 0 1 1
.
K3 1 0 0 1 0 0 1 1 .
.
.
. K1 1 1 0 0 0 0 0 1
. Pas
K2 1 0 0 1 0 0 1 1 M/2
KN 1 0 0 0 1 0 0 1

Mating pool: M/2 pasang kromosom orangtua

Generasi 1: Populasi N kromosom/individu

Rekombinasi
dan Mutasi

Penggantian
M kromosom
berdasarkan
metode seleksi
survivor

K1 0 0 0 0 1 1 0 1
.
.
.

KM 1 1 0 0 1 1 1 1

M kromosom baru Seleksi Survivor: Steady State


K1 1 1 0 0 0 0 0 1
K1 1 1 0 0 0 0 0 1 Pas 1
Seleksi
orangtua K3 0 0 1 1 0 0 0 0
K2 1 0 0 1 0 0 1 1
.
K3 1 0 0 1 0 0 1 1 .
.
.
. K1 1 1 0 0 0 0 0 1
. Pas
K2 1 0 0 1 0 0 1 1 M/2
KN 1 0 0 0 1 0 0 1

Mating pool: M/2 pasang kromosom orangtua

Generasi 1: Populasi N kromosom/individu

Rekombinasi
dan Mutasi

Penggantian
M kromosom
berdasarkan
metode seleksi
survivor

K1 0 0 0 0 1 1 0 1
.
.
.

KM 1 1 0 0 1 1 1 1

M kromosom baru Seleksi Survivor: Steady State


GA untuk Optimasi Fungsi Kontinu

73 4/17/2021
Minimasi Fungsi

Nilai minimum h = ?

h( x1 , x 2 ) = x + x
2
1
2
2

x1 , x 2  [−5,12; 5,12]
Individu Biner

x1 x2

1 1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1

g1 g10 g11 g20


Fungsi Fitness

1
f = 2
( x1 + x 2 ) + 0,01
2

Jika nilai minimum = 0, nilai maks f = ?


Operator Evoluasi

• Model populasi: generational


• Seleksi orangtua: roulette wheel
• Rekombinasi: satu titik potong
• Mutasi: biner
• Seleksi Survivor: dengan elitisme
Operator Evoluasi

• Model populasi: generational (up = 50)


• Seleksi orangtua: roulette wheel
• Rekombinasi: satu titik potong (pc = 0,8)
• Mutasi: biner (pm = 0,05)
• Seleksi Survivor: dengan elitisme
Generasi 1 x = rb +
(ra − rb )
N
( g1.2 −1 + g 2 .2 − 2 + ... + g N .2 − N )
2
i =1
−i

x1 , x 2  [−5,12; 5,12]
Generasi 1
Generasi 10 x = rb +
(ra − rb )
N
( g1.2 −1 + g 2 .2 − 2 + ... + g N .2 − N )
2
i =1
−i

x1 , x 2  [−5,12; 5,12]
Generasi 10
Generasi 100

You might also like