1 / 40

# cytangcs.nthu.tw - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' cytangcs.nthu.tw ' - huela

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 以「旅行推銷員問題」為例，淺談如何利用計算機解題以「旅行推銷員問題」為例，淺談如何利用計算機解題

[email protected]

12

1

2

1

3

8

2

10

3

4

12

1

2

1

3

8

2

10

3

4

TSP是一個公認的難題NP-Complete
• 意義：我們現在無法對所有輸入找到一個有效率的解法
• 避免浪費時間尋求更佳的解法
• Ref: Horowitz & Sahni,Fundamentals of Computer Algorithms, P528.

• 目前只有exponential algorithm，還沒有人找到polynomial algorithm (你也不妨放棄！)這一類問題是NP-Complete Problem
• Garey & Johnson “Computers & Intractability”
• 2n相當可怕
Computational Biology

Database

P1

P2

P1P2 P1 P2

C2 [11] C1 [10]

C1 [10] C2 [11]

C3 [01] C3 [01] consecutive 1 propety

• False negative
• False positive

C1

C2

C3

A clones x probes matrix with added column p6*.

2

P1

P2

2

2

2

3

0

3

2

3

P6

P3

4

4

4

TSP graph for matrix of Table

1

2

P5

P4

2

• 有許多變型
• 平面TSP
• 幾何TSP（滿足三角不等式）
• 不對稱TSP

*

*

*

*

*

*

*

2

(1)

(2)

3

4

2

(3)

(1)

(2)

4

(想想看什麼問題不能窮舉解？)－加分題!

• 旅行推銷員問題：

3!走法 (n-1)!

• 最小展開樹問題：

16種樹 n(n-2) Cayley’s Thm.

Ref: Even, Graph Algorithms, PP26~28

2

1

1

4

3

12

4

Labeled tree  Number sequenceOne-to-One Mapping
• N個nodes的labeled tree可以用一個長度N-2的number sequence來表達。
• Encoding: Data Compression.
Labeled treeNumber sequence
• 在每一個iteration裡，切除目前所有leaves中編號最小的node及其edges，記錄切點，切到只剩一條edge為止。

Prune-sequence:7,4,4,7,5(切點)

• Label最大者必在最後的edge.
• 每個node原先的degree數=此node在Prune-sqeuence中出現的次數+1.

2

5

6

4

7

3

1

Number sequenceLabeled tree

Prune-sequence: 7,4,4,7,5

• 每一個iteration裡，選擇degree為1且編號最小的node，連接prune-sequence中相對的node，之後兩個nodes的degree均減1.

Iteration 1 Iteration 2

Iteration 3

Iteration 4 Iteration 6

Iteration 5

1

7

1

7

2

4

1

7

2

4

3

3

1

7

3

4

2

1

7

4

2

3

5

1

7

6

5

4

2

6

• 旅行推銷員問題 x
• 最小展開樹問題 o

1. 將邊由小到大加入，有迴圈即丟掉

2. 將樹從一點開始，最經濟向外擴展

Minimal spanning treeKruskal’a Algorithm

A

B

70

C

50

300

75

80

200

65

E

D

90

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;

Repeat.

End.

O (m log m) m = # of edge

O(log n)

Initial O(n)

• Tarjan: Union & Find可以almost linear (Amortized)
• Correctness
• 如果不選最小edge做tree而得到minimal
• 加入最小edge會有cycle
• Delete cycle中最大的edge會得到更小cost之tree (矛盾！)

1

2

4

3

7

5

6

1. 加 edge(2,3) 不合法

2. 加 edge(1,4) 合法

• 另一種看法：

S1={1,2,3}

S2={4,5}

Edge的端點要在不同set

Set的 Find, Union O(log n)

1

4

2

3

5

Prim’s Algorithm

A

B

70

C

50

300

75

80

200

65

E

D

90

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)

1

4

100

• 從(1)開始貪心 不成功！

1

3

15

8

2

2

3

1

2

3

1

2

3

4

100

• 貪　心　法（The Greedy Method）
• 各個擊破法（Divide-&-Conquer）
• 窮　舉　法（Enumerating）
• 樹狀搜尋法（Tree Searching Strategies）　　　　　（Branch & Bound）
• 動態規畫法（Dynamic Programming）
• 近　似　法（Approximation）

• 滿足遞迴關係

• 利用空間換取時間

• 算Fibonacci Number

F (i) = F (i - 1) + F (i - 2)

F (0) = F (1) = 1

• 預估B, C, D以下的解，如果D的最樂觀可能解，都比B以下的某解還差，則D以下可以不搜尋

A

B

C

D

• 不期望最佳解
• 用效率高的方法去求合理解
• 該合理解與最佳解有可預期的倍數關係
• 可以做如模擬退火法的其它解法的初始解or參考值
• 理論分類
• NPO complete
• MAX SNP hard
• PTAS

http://web.informatik.uni~bonn.de/IV/Mitarbeiter/rick/WS9687/approxvortr/approxvortr.html

Minimal spanning tree < TSP

Minimal matching < 1/2 TSP

=> < 3/2 TSP

• 模擬退火
• 神經計算
• 基因演算

• Local maximal  global maximal

• Local maximal 不是 global maximal

procedure SIMULATED-ANNEALING

begin

INITIALIZE ( i start, c0, L0);

k := 0;

i := i start;

repeat

for l := 1 to Lk do

begin

GENERATE (j form Si); Greedy

if f (j) <= f (i) then I := j

else 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 criterion

end;

TSP如何做？

• 模擬退火中有許多參數，要靠經驗或實驗。
Introduction Genetic Algorithms（基因計算）

Begin

Encoding

• Genetic Algorithms
• Artificial mechanisms of natural evolution.
• A robust search procedures and solving complex search problems.
• Low efficient if large problem space.
• Population homogeneous.

Initialize population

Evaluate population

Reproduction & Selection

Crossover

No

Mutation

Evaluate population

Termination criterion

End

Yes

The Eugenic Genetic Algorithm for TSPCrossover Phase

(a) A

1

(a) B

1

• Sequence preserving crossover (SPX)
• Schemata is preserved as more as possible.

2

9

2

9

3

8

3

8

4

7

4

7

Crossover

5

6

5

6

A=123||5748||69

B=934||5678||21

(a) A’

1

(a) B’

1

2

9

2

9

A’=234||5678||91

B’=936||5748||21

3

8

3

8

4

7

4

7

5

6

5

6

The Eugenic Genetic Algorithm for TSPMutation Phase
• Point mutation
• Inversion mutation
• Shift mutation

(a) Point mutation

(b) Inversion mutation

(c) Shift mutation (right shift)

• Use (DNA) molecules to represent the data instances. 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.

Ref. Adleman, Molecular Computation of Solutions to Combinatorial Problems, Science, Vol. 266, 11, 1994, PP1021-1024.

• 問題：有無從0  6，長度為6，各vertex恰走一遍的path?

O2 TATCGGATCGGTATATCCGA

O3 GCTATTCGAGCTTAAAGCTA

O4 GGCTAGGTACCAGCATGCTT

O23 GTATATCCGAGCTATTCGAG

O34 CTTAAAGCTAGGCTAGGTAC

O3 (bar) CGATAAGCTCGAATTTCGAT

O23 O34

GTATATCCGAGCTATTCGA

GCTTAAAGCTAGGCTACGATAAGCTCGAATTTCGAT

O3 (bar)

4

3

1

0

6

2

5

• 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-1 任意選vertex編碼

1-2 產生instance編碼

1-3 截取DNA

1-4 放入試管

2．分子過濾

3．分子過濾

4．分子過濾

1．產生一path

2．檢查首尾

3．檢查長度

4．檢查每個vertex都有

Yes

No

• 生物計算機
• 量子計算機