Professional Documents
Culture Documents
LECTURE 4 HANDOUT
EX1. A TSP with 4 cities.
Traveling cost matrix
𝑐𝑖𝑗 1 2 3 4
1 - 50 15 42
2 16 - 60 20
3 20 80 - 54
4 10 24 30 -
1
𝑥𝑖 ≥ 0, 𝑖𝑛𝑡𝑒𝑔𝑒𝑟, ∀𝑖 ∈ {1, … ,4}
EX3. Single Machine Scheduling Problem
𝒋 𝒑𝒋 𝒓𝒋 𝒅𝒋
1 5 0 5
2 10 3 15
3 7 0 10
4 12 5 10
- Construct an
initial feasible Find a Search the best neighbor
solution, 𝑠 (0) neighborhood in 𝑁(𝑠 (𝑡) ), 𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ
- Set solution definition, 𝑁
index: 𝑡 ← 0
Is
𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ
𝑡 ←𝑡+1 Yes 𝑓(𝑠 ) No Return 𝑠 (𝑡)
(𝑡)
𝑠 ←𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ better than (Local optima)
𝑓(𝑠 (𝑡) )?
2
Pseudocode of Simulated Annealing (SA)
Input: initial solution 𝑠 (0) , a neighborhood definition 𝑁, a cooling schedule 𝛼(𝑡), initial
temperature 𝑡 (0) , an iteration limit 𝜇𝑘 for each temperature level 𝑡 (𝑘)
(1) 𝑠 ← 𝑠 (0) // set current solution as the starting solution
𝑠 𝑏𝑒𝑠𝑡 ← 𝑠 (0) // set the best found solution as the starting solution
𝑘←0
(2) while stopping condition is not met do
for 𝑖 = 1 to 𝜇𝑘 do
Pick a random neighbor: 𝑠 𝑁 ← 𝑁(𝑠)
if 𝑓(𝑠 𝑁 ) is better than 𝑓(𝑠 𝑏𝑒𝑠𝑡 ) then //UPDATE INCUMBENT IF NEIGHBOR IS BETTER
𝑠 𝑏𝑒𝑠𝑡 ← 𝑠 𝑁
endif
Generate a random number 𝑟 ∈ (0,1)
𝑓(𝑠𝑁 )−𝑓(𝑠)
−
if e 𝑡(𝑘) ≥ 𝑟 then // ACCEPTANCE
𝑁
𝑠←𝑠
endif
endfor
𝑡 (𝑘+1) ← 𝛼(𝑡 (𝑘) ) //TEMPERATURE REDUCTION
𝑘 ←𝑘+1
endwhile
Output: best found solution 𝑠 𝑏𝑒𝑠𝑡
3
Pseudocode of Tabu Search (TS)
Input: initial solution 𝑠 (0) , a neighborhood definition 𝑁, a tabu tenure 𝛿
(1) 𝑠 ← 𝑠 (0) // set current solution as the starting solution
𝑠 𝑏𝑒𝑠𝑡 ← 𝑠 (0) // set the best found solution as the starting solution
𝑇 ← ∅ // initially, tabu list is empty
(2) while stopping condition is not met do
𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ ← ∅
for each 𝑠 𝑛𝑒𝑖𝑔ℎ ∈ 𝑁(𝑠) and (𝑚𝑜𝑣𝑒(𝑠, 𝑠 𝑛𝑒𝑖𝑔ℎ ) ∉ 𝑇 or 𝑓(𝑠 𝑛𝑒𝑖𝑔ℎ ) is better than 𝑓(𝑠 𝑏𝑒𝑠𝑡 ) ) do
if 𝑓(𝑠 𝑛𝑒𝑖𝑔ℎ ) is better than 𝑓(𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ ) or 𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ == ∅ then
𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ ← 𝑠 𝑛𝑒𝑖𝑔ℎ
endif
endfor
if 𝑓(𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ ) is better than 𝑓(𝑠 𝑏𝑒𝑠𝑡 ) then //UPDATE INCUMBENT IF BEST NEIGHBOR IS BETTER
𝑠 𝑏𝑒𝑠𝑡 ← 𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ
endif
𝑠 ← 𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ //UPDATE THE CURRENT SOLUTION
if |𝑇| ≥ 𝛿 then
𝑇 ← 𝑇 \ {𝑜𝑙𝑑𝑒𝑠𝑡 𝑒𝑙𝑒𝑚𝑒𝑛𝑡}
endif
𝑇 ← 𝑇 ∪ { 𝑚𝑜𝑣𝑒(𝑠, 𝑠 𝑏𝑒𝑠𝑡𝑁𝑒𝑖𝑔ℎ ) } //UPDATE TABU LIST
endwhile
Output: best found solution 𝑠 𝑏𝑒𝑠𝑡