以「旅行推銷員問題」為例,淺談 如何利用計算機解題
DESCRIPTION
以「旅行推銷員問題」為例,淺談 如何利用計算機解題. 唐傳義 教授 [email protected] 國立清華大學資訊工程系. 12. 1. 2. 1. 3. 8. 2. 10. 3. 4. 給定 4 個城市的相互距離. 12. 1. 2. 1. 3. 8. 2. 10. 3. 4. 最小展開樹問題 尋找一個將四個城市最經濟的聯結. 旅行推銷員問題 Traveling Salesman Problem (TSP) 尋找一個從 (1) 出發,回到 (1) 的最短走法. 12. 1. 2. 1. 3. 8. 2. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/2.jpg)
2
給定 4 個城市的相互距離
1 2
3 4
12
1 8
10
3
2
![Page 3: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/3.jpg)
3
最小展開樹問題尋找一個將四個城市最經濟的聯結
1 2
3 4
12
1 8
10
3
2
![Page 4: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/4.jpg)
4
旅行推銷員問題Traveling Salesman Problem (TSP)尋找一個從 (1) 出發,回到 (1) 的最短走法
1 2
3 4
12
1 8
10
3
2
![Page 5: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/5.jpg)
5
TSP 是一個公認的難題NP-Complete 意義:我們現在無法對所有輸入找到一
個有效率的解法
避免浪費時間尋求更佳的解法 Ref: Horowitz & Sahni,
Fundamentals of Computer Algorithms, P528.
![Page 6: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/6.jpg)
6
2n 相當可怕
10 30 50
N 0.00001 s
0.00003 s 0.00005 s
N2 0.0001 s 0.0009 s 0.0025 s
2n 0.001 s 17.9 min 35.7 year 像 satisfiabilibility problem 目前只有 exponential algorithm ,還沒有人找到 polynomial algorithm ( 你也不
妨放棄! )這一類問題是 NP-Complete Problem
Garey & Johnson “Computers & Intractability”
![Page 7: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/7.jpg)
7
生物應用的計算需求
數學問題
工具程式
Computational Biology
Database Added Value Database
抽象化
算法設計
![Page 8: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/8.jpg)
8
例 Physical Mapping of DNA
P1 P2 P1 P2 C2 [1 1] C1 [1 0] C1 [1 0] C2 [1 1] C3 [0 1] C3 [0 1]
consecutive 1 propety False negative False positive
C1
C2
C3
P1 P2
![Page 9: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/9.jpg)
9
A clones x probes matrix with added column p6*.
P1 P2 P3 P4 P5 P6
C1 1 1 1 0 0 0
C2 0 1 1 1 0 0
C2 1 0 0 1 1 0
C4 1 1 1 1 0 0
P1
P6
P2
P5
P3
P4
2
2
03
1
2
2
2
2 2
4 4
3
4
3
TSP graph for matrix of
Table
![Page 10: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/10.jpg)
10
旅行推銷員問題是許多排程應用的核心問題 (航運排程)
有許多變型 平面 TSP
幾何 TSP (滿足三角不等式)
不對稱 TSP
* *** *
* *2
3 4
(1)
(3)
(2)
(1) (2)2
4
![Page 11: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/11.jpg)
11
窮舉法( Enumerating )( 想想看什麼問題不能窮舉解? ) -加分題 ! 旅行推銷員問題:
3! 走法 (n-1)! 最小展開樹問題:
16 種樹 n(n-2) Cayley’s Thm.
Ref: Even, Graph Algorithms, PP26~28
12
4
1143
2
![Page 12: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/12.jpg)
12
Labeled tree Number sequenceOne-to-One Mapping
N 個 nodes 的 labeled tree 可以用一個長度 N-2 的 number sequence 來表達。
Encoding: Data Compression.
![Page 13: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/13.jpg)
13
Labeled treeNumber sequence 在每一個 iteration 裡,切除目前所有 leaves 中
編號最小的 node 及其 edges ,記錄切點,切到只剩一條 edge 為止。
例 .
Prune-sequence:7,4,4,7,5( 切點 )
Label 最大者必在最後的 edge. 每個 node 原先的 degree 數 = 此 node 在
Prune-sqeuence 中出現的次數 +1.
2
3
4 7
1
5 6
![Page 14: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/14.jpg)
14
Number sequenceLabeled tree
Prune-sequence: 7,4,4,7,5k 1 2 3 4 5 6 7
deg(k) 1 1 1 3 2 1 3
Iteration 1 0 1 1 3 2 1 2
Iteration 2 0 0 1 2 2 1 2
Iteration 3 0 0 0 1 2 1 2
Iteration 4 0 0 0 0 2 1 1
Iteration 5 0 0 0 0 1 0 1
Iteration 6 0 0 0 0 0 0 0
每一個 iteration 裡,選擇 degree 為 1且編號最小的 node ,連接 prune-sequence 中相對的 node ,之後兩個 nodes 的 degree均減 1.
Iteration 1 Iteration 2Iteration 3Iteration 4 Iteration 6
Iteration 5
1 7
1 7 2 41 7 2 4 3
1 7 41 7 4
3
2
1 7 43
26 5
3
25
6
![Page 15: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/15.jpg)
15
貪心法( Greedy ) 旅行推銷員問題 x 最小展開樹問題 o
兩種貪心都成功:1. 將邊由小到大加入,有迴圈即丟掉2. 將樹從一點開始,最經濟向外擴展
![Page 16: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/16.jpg)
16
Minimal spanning treeKruskal’a Algorithm
A B
D
C
E
70
65
300
90
50
80 75200
Begin T <- null While T contains less than n-1 edges, the smallest weight, choose an edge (v, w) form E of smallest weight 【 Using priority queue, heap O (log n) 】 , delete (v, w) form E. If the adding of (v, w) to T does not create a cycle in T, 【 Using union, find O (log m) 】 then add (v, w) to T; else discard (v, w). Repeat.End.
O (m log m) m = # of edge
![Page 17: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/17.jpg)
17
做 priority queue 可以用heap operation
O(log n)Initial O(n) Tarjan: Union & Find 可以 almost linear (Amortiz
ed) Correctness
如果不選最小 edge做 tree而得到 minimal 加入最小 edge會有 cycle Delete cycle 中最大的 edge會得到更小 cost之 tree
(矛盾! )
1
2 4
3 7 5 6
![Page 18: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/18.jpg)
18
建 spanning tree 可以看做spanning forest 加 link1. 加 edge(2,3) 不合法2. 加 edge(1,4) 合法 另一種看法:S1={1,2,3}S2={4,5}Edge 的端點要在不同 set
Set 的 Find, UnionO(log n)
1
32
4
5
![Page 19: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/19.jpg)
19
Prim’s AlgorithmA B
D
C
E
70
65
300
90
50
80 75200
Step 1: Let x be any vertex in V. Let A = {x} and B = V - {}.Step 2: Select an edge (u, v) form E such that u in A, v in B and (u, v) has the
smallest weight among edges between A and B.Step 3: Connect v to u in A. Let A = A + {v} and B = B – {v}.Step 4: If B is empty, terminate and the resulting tree is a minimal spanning tree.
Otherwise, go to Step 2.
O(n2)
![Page 20: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/20.jpg)
20
考慮以下的城市做旅行推銷員問題
從 (1) 開始貪心不成功!
1 4
2 3
100
1 15
2
3
8
1 2 3 4
1 2 3
100
![Page 21: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/21.jpg)
21
一些常用的方法 貪 心 法( The Greedy Method ) 各個擊破法( Divide-&-Conquer ) 窮 舉 法( Enumerating ) 樹狀搜尋法( Tree Searching Strategies )
( Branch & Bound ) 動態規畫法( Dynamic Programming ) 近 似 法( Approximation )
![Page 22: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/22.jpg)
22
動態規畫法( Dynamic Programming )原則: 滿足遞迴關係技巧: 利用空間換取時間最簡單的例子: 算 Fibonacci Number
F (i) = F (i - 1) + F (i - 2)F (0) = F (1) = 1
![Page 23: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/23.jpg)
23
樹狀搜尋法( Tree Searching Strategies ) ( Branch & Bound )
預估B, C, D 以下的解,如果 D 的最樂觀可能解,都比B以下的某解還差,則 D 以下可以不搜尋深藍!
A
B C D
![Page 24: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/24.jpg)
24
近似解法( Approximation ) 不期望最佳解 用效率高的方法去求合理解 該合理解與最佳解有可預期的倍數關係 可以做如模擬退火法的其它解法的初始解 or參考值 理論分類
NPO complete MAX SNP hard PTAS
http://web.informatik.uni~bonn.de/IV/Mitarbeiter/rick/WS9687/approxvortr/approxvortr.html
![Page 25: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/25.jpg)
25
以幾何 TSP 為例先做最小展開樹
![Page 26: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/26.jpg)
26
挑出所有奇數 degree 的點X X
X
X
X
X
X
![Page 27: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/27.jpg)
27
對他們做matching (Euler Graph)
X X
X
X
X
X
X
![Page 28: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/28.jpg)
28
一筆畫
Minimal spanning tree < TSPMinimal matching < 1/2 TSP=> < 3/2 TSP
時間 n2.5
X X
X
X
X
X
X
![Page 29: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/29.jpg)
29
模擬自然界一些其它的隨機方法 模擬退火 神經計算 基因演算
![Page 30: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/30.jpg)
30
模擬退火 回火 策略Simulated-Annealing
Local maximal global maximal
Local maximal 不是 global maximal
難題!
![Page 31: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/31.jpg)
31
模擬退火法 (Simulated Annealing)procedure SIMULATED-ANNEALINGbegin
INITIALIZE ( i start, c0, L0);k := 0;i := i start;repeat
for l := 1 to Lk dobegin
GENERATE (j form Si); Greedyif f (j) <= f (i) then I := jelse if exp { [f (i) – f (j)] / ck} > random [0, 1) then I := j
end; f (i) – f (j)比 ck愈小愈有機會反 Greedy但不要太離譜!
k := k +1;CALCULATE_ LENGTH (Lk);CALCULATE_ CONTROL (Lk);
until stop criterionend;
![Page 32: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/32.jpg)
32
TSP 如何做?從一個 tour 裡任取兩個 edge
決定到底要不要用
取代
原則:通常還是貪心,偶而讓它反其道一下
![Page 33: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/33.jpg)
33
模擬退火是一種隨機方法,只能預設一個停止時間,看天吃飯。
模擬退火中有許多參數,要靠經驗或實驗。
![Page 34: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/34.jpg)
34
Introduction Genetic Algorithms (基因計算)
Genetic Algorithms Artificial mechanisms of natural
evolution. A robust search procedures and
solving complex search problems. Disadvantage
Low efficient if large problem space.
Population homogeneous.End
Begin
Encoding
Initialize population
Reproduction & Selection
Crossover
Mutation
Evaluate population
Termination criterion
Evaluate population
No
Yes
![Page 35: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/35.jpg)
35
The Eugenic Genetic Algorithm for TSPCrossover Phase
Sequence preserving crossover (SPX) Schemata is preserved
as more as possible.
A=123||5748||69B=934||5678||21
A’=234||5678||91B’=936||5748||21
1
2 9
3 8
4 7
5 6
1
2 9
3 8
4 7
5 6
1
2 9
3 8
4 7
5 6
1
2 9
3 8
4 7
5 6
(a) A
(a) A’
(a) B
(a) B’
Cro
ssover
![Page 36: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/36.jpg)
36
Point mutation Inversion mutation Shift mutation
The Eugenic Genetic Algorithm for TSPMutation Phase
(a) Point mutation
(b) Inversion mutation
(c) Shift mutation (right shift)
![Page 37: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/37.jpg)
37
分子計算( Molecular Computation ) Use (DNA) molecules to represent the data in
stances. Put the molecules into a tube, control the environments.
The molecules will bind with each other. The most tightly binging is the minimum cost solution.
Massive parallelism since the large number of molecules.
一莫耳 = 6.02 * 1023
Ref. Adleman, Molecular Computation of Solutions to Combinatorial Problems, Science, Vol. 266, 11, 1994, PP1021-1024.
![Page 38: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/38.jpg)
38
以 TSP 的特例 Hamiltonian Path 為例(也是難題)
問題:有無從 0 6 ,長度為 6 ,各 vertex恰走一遍的 path? O2 TATCGGATCGGTATATCCGA
O3 GCTATTCGAGCTTAAAGCTA
O4 GGCTAGGTACCAGCATGCTT
O23 GTATATCCGAGCTATTCGAG
O34 CTTAAAGCTAGGCTAGGTAC
O3 (bar) CGATAAGCTCGAATTTCGAT
O23 O34
↓
GTATATCCGAGCTATTCGAGCTTAAAGCTAGGCTACGA
TAAGCTCGAATTTCGAT↓
O3 (bar)
Fig.1. Directed graph. When Vin = 0 and Vout = 6, unique Hamiltonian path exists: 0 1, 1 2, 2 3, 3 4, 4 5, 5 6.
1
6
5
4
3
0
2
![Page 39: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/39.jpg)
39
計算做法1.產生一 path
2.檢查首尾3.檢查長度4.檢查每個
vertex都有YesNo
分子做法1-1 任意選 vertex 編碼1-2 產生 instance 編碼1-3 截取 DNA1-4 放入試管2.分子過濾3.分子過濾4.分子過濾
還有 path存在
![Page 40: 以「旅行推銷員問題」為例,淺談 如何利用計算機解題](https://reader033.vdocuments.site/reader033/viewer/2022061612/568134ec550346895d9c2a8e/html5/thumbnails/40.jpg)
40
未來的計算機 生物計算機 量子計算機