Top Banner
期期期期 TSP &SA
38

期末專題 TSP &SA

Mar 15, 2016

Download

Documents

jael-benson

期末專題 TSP &SA. 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. 10. 3. 4. TSP 是一個公認的難題 NP-Complete. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 期末專題 TSP &SA

期末專題TSP &SA

Page 2: 期末專題 TSP &SA

給定 4 個城市的相互距離1 2

3 4

12

1 8

10

3

2

Page 3: 期末專題 TSP &SA

最小展開樹問題尋找一個將四個城市最經濟的聯結1 2

3 4

12

1 8

10

3

2

Page 4: 期末專題 TSP &SA

旅行推銷員問題Traveling Salesman Problem (TSP)尋找一個從 (1) 出發,回到 (1) 的最短走法

1 2

3 4

12

1 8

10

3

2

Page 5: 期末專題 TSP &SA

TSP 是一個公認的難題NP-Complete

• 意義:我們現在無法對所有輸入找到一個有效率的解法• 避免浪費時間尋求更佳的解法• Ref: Horowitz & Sahni,

Fundamentals of Computer Algorithms, P528.

Page 6: 期末專題 TSP &SA

• 2n 相當可怕10 30 50

N 0.00001 s 0.00003 s 0.00005 sN2 0.0001 s 0.0009 s 0.0025 s2n 0.001 s 17.9 min 35.7 year

• 像 satisfiabilibility problem• 目前只有 exponential algorithm ,還沒有人找到 polynomial algorithm ( 你也不妨放棄! )這一類問題是 NP-Complete Problem• Garey & Johnson “Computers & Intractability”

Page 7: 期末專題 TSP &SA

模擬退火 回火 策略Simulated-Annealing

• Local maximal global maximal

• Local maximal 不是 global maximal

難題!

Page 8: 期末專題 TSP &SA

模擬退火法 (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 9: 期末專題 TSP &SA

TSP 如何做?從一個 tour 裡任取兩個 edge

決定到底要不要用取代

原則:通常還是貪心,偶而讓它反其道一下

Page 10: 期末專題 TSP &SA

• 模擬退火是一種隨機方法,只能預設一個停止時間,看天吃飯。• 模擬退火中有許多參數,要靠經驗或實驗。

Page 11: 期末專題 TSP &SA

Simulated Annealing(模擬退火法)Graham Kendall

Artificial Intelligence Methods (G5BAIM)

The University of Nottingham

Page 12: 期末專題 TSP &SA

大綱• 簡介• 模擬退火法 v.s. Hill Climbing• 模擬退火法的檢測標準• 實際退火與模擬退火之間的關係• 演算法• 冷卻排程• 其他的問題• 提高效能• 演算法修正• 結論

Page 13: 期末專題 TSP &SA

簡介• 模擬退火法是模擬冷卻晶體的過程• 最早是由Metropolis等人在 1953年提出• 1982年, Kirkpatrick等人將其運用在求最佳化的問題上

Page 14: 期末專題 TSP &SA

模擬退火法 v.s. Hill Climbing

• Hill Climbing是挑選鄰近點中最好的點,但這樣會有局部最大值的問題• 模擬演算法是亂數找尋鄰近的點

– 若找到的點比立足點好,則取之– 否則依照機率決定是否取之

Page 15: 期末專題 TSP &SA

模擬退火法的檢測標準• 根據熱力學定律,在溫度為 t的情況下,能量差所表現的機率如下:

P(ΔE)=exp(-ΔE / kt)– k是 Boltzmann’s Constant

• 轉換到模擬退火法,則變成P=exp(-c / t)>r

– c是評估函數的差– r是 0~1之間的亂數

Page 16: 期末專題 TSP &SA

實際退火與模擬退火之間的關係實際退火法 模擬退火法系統狀態 適合解能量 價值轉換狀態 鄰近解溫度 控制參數冷卻狀態 最終解

Page 17: 期末專題 TSP &SA

演算法1. 設定終結溫度 T及初始溫度 t2. 若 t=0,則結束冷卻• 否則亂數找一可用之點• 計算 ΔE,若大於零則接受新的值• 若小於零,則透過機率函數已決定是否接受新值• 決定是否下降溫度,做進一步的搜尋

Page 18: 期末專題 TSP &SA

冷卻排程• 初始溫度( Starting Temperature)

– 溫度要夠高才能移動到任何的狀態– 溫度不能太高,否則會導致在一段時間內皆用亂數在湊解答1. 如果可以知道檢測函數的最大值就可以找到最好的初始溫度2. 快速提高溫度,然後又快速降溫,直到有 60

%的最差解被接受3. 快速提高溫度,但慢慢降溫,並定出適當比例最差解的接受度

Page 19: 期末專題 TSP &SA

冷卻排程(續)• 最終溫度( Final Temperature)

– 通常是零,但會耗掉許多模擬時間– 溫度趨近於零,其周遭狀態幾乎是一樣的– 所以尋找一個低到可接受的溫度

Page 20: 期末專題 TSP &SA

冷卻排程(續)• 溫度減少( Temperature Decrement)

– 每次降低溫度的差距以及在同一溫度反覆尋找最適解會導致指數般成長的搜尋空間 1.以線性降溫來說

Temp=Temp-x 2.以幾何觀念來看

Temp=Temp*y(y約 0.8~0.99為佳 )

Page 21: 期末專題 TSP &SA

冷卻排程(續)• 反覆次數( Iterations at each Temperature)

– 一般會定一個常數– Lundy認為只要反覆一次,但每次降低的溫度差距必須非常小

Temp=Temp / (1+a*Temp)a是非常小的值

– 低溫需要較多反覆次數以避免找到局部最大值,但高溫則可減少次數

Page 22: 期末專題 TSP &SA

其他的問題• 價值函數( Cost Function)

– 用來評估解的品質– Delta Evaluation

• 求某解與其鄰近點的價值– Partial Evaluation

• 不需額外產生的計算結果就可以判斷出來解的價值

Page 23: 期末專題 TSP &SA

其他的問題(續)• 價值函數( Cost Function)

– Hard Constraints• 在不違背合適解的條件下,所提出的強制規定

– Soft Constraints• 無論這種解是否違背條件,都算是合適解

– Hard Constraints會給一個很大的 weight– Soft Constraints則是情況給予不同的 weight

Page 24: 期末專題 TSP &SA

其他的問題(續)• 鄰近點的結構( Neighborhood Structure)

– 有些結構是對稱性的,即可以從 A狀態到 B狀態,也可以從 B狀態到 A狀態– 條件較弱(結構較鬆散)的有穩定的收斂– 條件定的好,就可以使得在各種狀態之下都可以到達另一種狀態

Page 25: 期末專題 TSP &SA

其他的問題(續)• 所有解的空間( The Solution Space)

– 空間小,可以展開搜尋– 若允許不合適的解也存在的話就會加大搜尋空間– 我們想辦法取一個適當值,期望能快速搜尋,又可避免在不利的情況下沒有好的進展

Page 26: 期末專題 TSP &SA

提高效能• 初始化( Initialization)

– 將原本用亂數取初始值的方式改為盡可能找出一有用的起始點• 雜交( Hybridization)

– 結合兩種以上的搜尋演算法

Page 27: 期末專題 TSP &SA

演算法修正• 可接受的機率( Acceptance Probability)

P(ΔE)=1- (ΔE / t)– 少計算 exponential會加快速度– 建立一個可查詢各種值的 table

• 冷卻( Cooling)– 花一些時間找尋最佳溫度(包括最終溫度、溫差)

Page 28: 期末專題 TSP &SA

演算法修正(續)• 鄰近點( Neighborhood)

– 對於不好的鄰近點給予一個懲罰值• 價值函數( Cost Function)

– 利用其他演算法的價值函數來做計算

Page 29: 期末專題 TSP &SA

結論• 模擬退火法已經證明可能收斂出最好解• 要花較多的時間去搜尋各種解• 可將模擬退火法應用於其他問題上

Page 30: 期末專題 TSP &SA

Mathematic model

Description:• A salesman transports the products to all

the cities in the map.• The salesman visits each city once and

only once, and returns to the starting city.• Find the shortest route to transport to

lower cost.

Flash demo

Page 31: 期末專題 TSP &SA

Mathematic model

• The total distance of the plan (order) P is the function - the sum of all distances in plan.

• The aim of TSP is to get the minimum of this function f(P).

11

( ) ( , )n

i ii

f P dist p p

Page 32: 期末專題 TSP &SA

Design of Simulated Annealing

• Simulated Annealing (SA)It’s an algorithm to find the minimum of the function.

The function of the problem is discrete and complex.

the discrete function of the problem

minimum

Page 33: 期末專題 TSP &SA

Design of Simulated AnnealingRule of nature

• Consider the rule of nature:Substance always closes to the lowest energy state.

For example:1.The river always goes to the lower height.2.The thing at a high temperature always goes to the lower temperature.

Page 34: 期末專題 TSP &SA

Design of Simulated AnnealingCooling Process

• Simulated Annealing (SA)It simulates cooling the solid which is a behavior of physical process. At first the solid is at a high temperature, namely has a high energy. With the solid cooling, its energy is getting lower and lower. At last, the solid reaches the lowest energy at the normal temperature. The process of cooling is known as annealing.

t0 7 a 0.187 H 5

T t( ) H t0 H( )e a t t0( )

0 10 20 300

5

10

15

T t( )

t

temperature

time

the lowest energy

Page 35: 期末專題 TSP &SA

Design of Simulated AnnealingSupposition

• Notice the lowest energy state has certain similarity to the minimum of the function!!!

We can design an algorithm that can find the minimum automatically as substance closing to the lowest energy state.

Lowering energy figure Discrete function figure

Similarity? minimumlowest energy

Page 36: 期末專題 TSP &SA

Simulated Annealing Algorithm• I’m Sorry.

Because of the time limit, I jump over introducing the detail of SA.

Page 37: 期末專題 TSP &SA

AnalyzeEfficiency

1. The rate of the value of the solution and the used time is quite higher than the way to get the real minimum in traditional way.When the traditional algorithm runs for years, SA runs in only seconds.

“Time is money.” It satisfies the need of time for moderns.

2. For economy, the management used an efficient algorithm is important for the progress of the company in modern markets.

• I think SA satisfies those conditions.

Page 38: 期末專題 TSP &SA

Analyze Expandability

• SA is not only used in solving TSP. It is the general algorithm for optimization.It can solve all the complex problems forming functions.

• SA isn’t only a algorithm, but also a good thought to solve problems.It can be combined with some other algorithm for concrete problems.