0% found this document useful (0 votes)
31 views4 pages

END 395 Lecture 4 Handout EX1. A TSP With 4 Cities

The document provides examples and algorithms for solving several optimization problems: (1) the traveling salesman problem, integer knapsack problem, single machine scheduling problem, and 0-1 knapsack problem; (2) pseudocode for nearest neighbor, simulated annealing, tabu search, and genetic algorithms. Flowcharts and pseudocode are given to describe the main steps of the heuristic algorithms.

Uploaded by

Ferda Çetik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

END 395 Lecture 4 Handout EX1. A TSP With 4 Cities

The document provides examples and algorithms for solving several optimization problems: (1) the traveling salesman problem, integer knapsack problem, single machine scheduling problem, and 0-1 knapsack problem; (2) pseudocode for nearest neighbor, simulated annealing, tabu search, and genetic algorithms. Flowcharts and pseudocode are given to describe the main steps of the heuristic algorithms.

Uploaded by

Ferda Çetik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

END 395

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 -

Pseudocode of Nearest Neighbor Algorithm for TSP


Input: 𝑁 = {1, 2, … , 𝑛} : set of cities, 𝑐𝑖𝑗 ∀(𝑖, 𝑗) ∈ 𝐴
(1) Select an arbitrary node 𝑗 ∈ 𝑁
Tour (List) 𝐿 ← ∅
Set of unvisited nodes: 𝑇 ← {1, 2, … , 𝑛}
(2) Insert 𝑗 to 𝐿
𝑇 ← 𝑇\{𝑗}
Set last visited node: 𝐼 ← 𝑗
(3) while 𝑇 ≠ ∅ do
𝑗 ← arg min{𝑐𝐼𝑗 }
i∈T

Insert 𝑗 to 𝐿 (Add 𝑗 to the end of 𝐿)


𝑇 ← 𝑇\{𝑗}
Set last visited node: 𝐼 ← 𝑗
endwhile
(4) Add the first node of 𝐿 to 𝐿.
Output: a feasible TSP 𝐿

EX2. Integer Knapsack Problem


Max 18𝑥1 + 25𝑥2 + 11𝑥3 + 14𝑥4
s.t. 2𝑥1 + 3𝑥2 + 𝑥3 + 𝑥4 ≤ 3

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

a) Develop a heuristic that minimizes makespan


b) Develop a heuristic that minimizes total completion time
c) Develop a heuristic that minimizes maximum tardiness

EX4. 0-1 Knapsack Problem


Max 18𝑥1 + 25𝑥2 + 11𝑥3 + 14𝑥4
s.t. 2𝑥1 + 3𝑥2 + 𝑥3 + 𝑥4 ≤ 3
𝑥𝑖 ∈ {0, 1}, ∀𝑖 ∈ {1, … ,4}

Flowchart of Improvement Heuristics

- 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 𝑠 𝑏𝑒𝑠𝑡

Pseudocode of Genetic Algorithm (GA)


Input: an initial population size 𝑝, initial solutions 𝑠 (1) , …, 𝑠 (𝑝) , crossover probability 𝑝𝑐 , mutation
probability 𝑝𝑚
(1) 𝑃(0) ← {𝑠 (1) , …, 𝑠 (𝑝) } // set initial generation
𝑡 ← 0 // initially, generation index is zero
(2) while stopping condition is not met do
𝑡 ←𝑡+1
𝑃(𝑡) ← 𝑺𝑬𝑳𝑬𝑪𝑻𝑰𝑶𝑵 (𝑃(𝑡 − 1)) //SELECT BEST INDIVIDUALS FROM GENERATION (𝑡 − 1)
CROSSOVER 𝑃(𝑡)
MUTATION 𝑃(𝑡)
EVALUATE 𝑃(𝑡)
endwhile
Output: the best individual(s) in the last generation

You might also like