You are on page 1of 175

Optimization (MSE) Lecture 12:

Heuristic optimization

Prof. Dr. Lin Himmelmann

OST - Ostschweizer Fachhochschule

Zurich, 5th December, 2022


Optimization

continuous discrete/combinatorial

linear nonlinear approximate special exact

local global

other gradient-based classical meta-heuristics special appr.

population-based trajectory-based

hybrid

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 2 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Overview

1 Heuristic optimization
Introduction, examples, motivation

2 Hill climbing
Algorithm

3 Tabu search
Algorithm

4 Simulated annealing
Algorithm

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 3 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Overview

1 Heuristic optimization
Introduction, examples, motivation

2 Hill climbing
Algorithm

3 Tabu search
Algorithm

4 Simulated annealing
Algorithm

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 4 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

We know the coordinates of start and goal.


We only see the immediate neighborhood of our position.
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 5 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

Model terrain by a grid graph. Vertices are cells.


Edges are only between neighboring cells.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 6 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

Dijkstra...

explores new vertex closest


to start in each step.

Dijkstra always finds a shor-


test path from start (green)
to target (red).

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 7 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

Best-first heuristic...

explores new vertex


closest to goal (relying on
coordinates) in each step.

Very quickly finds a shortest


path if no obstacle is pre-
sent!

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 8 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

Dijkstra...

always finds optimal path,


but is computationally ex-
pensive.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 9 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

Best-first heuristic...

runs into dead end, but


eventually finds a detour.
Less computationally expen-
sive.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 10 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Pathfinding

Find shortest path from current position to given goal.

A*...

Combines Dijkstra
(shortest distance to start)
and best-first heuristic
(shortest distance to goal):
Explores vertex with smal-
lest weighted sum in each
step.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 11 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A heuristic is a problem-solving strategy that is based on rules


of thumb or common sense, possibly also using expert
knowledge.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 12 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A heuristic is a problem-solving strategy that is based on rules


of thumb or common sense, possibly also using expert
knowledge.

Heuristics are often used when no efficient (exact) algorithms


are known, or when applying such algorithms would take too
long.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 13 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A heuristic is a problem-solving strategy that is based on rules


of thumb or common sense, possibly also using expert
knowledge.

Heuristics are often used when no efficient (exact) algorithms


are known, or when applying such algorithms would take too
long.

Advantage: Hopefully good solution in a reasonable amount


time.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 14 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A heuristic is a problem-solving strategy that is based on rules


of thumb or common sense, possibly also using expert
knowledge.

Heuristics are often used when no efficient (exact) algorithms


are known, or when applying such algorithms would take too
long.

Advantage: Hopefully good solution in a reasonable amount


time.

Disadvantage: Usually no reliable optimality guarantees.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 15 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes


Many algorithmic problems are solvable in principle (e.g. by
enumeration), but no efficient algorithm is known.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 16 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes


Many algorithmic problems are solvable in principle (e.g. by
enumeration), but no efficient algorithm is known.

Classification of algorithmic problems according to their


complexity (w.r.t. input length).
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 17 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes


Many algorithmic problems are solvable in principle (e.g. by
enumeration), but no efficient algorithm is known.

Conjecture!

Classification of algorithmic problems according to their


complexity (w.r.t. input length).
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 18 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes


P: solvable in polynomial time
Many algorithmic problems are solvable in principle (e.g. by
NP: solvable in polynomial time with a non-deterministic machine
enumeration), but no efficient algorithm is known.
NP-hard: at least as hard as the hardest problems in NP
NP-complete: in NP and NP-hard

Conjecture!

Classification of algorithmic problems according to their


complexity (w.r.t. input length).
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 19 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes


Many algorithmic problems are solvable in principle (e.g. by
enumeration), but no efficient algorithm is known.

Conjecture!

Classification of algorithmic problems according to their


complexity (w.r.t. input length).
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 20 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes

The following problems are known to be in P, i.e. a


polynomial-time algorithm is known for them:
minimum spanning tree in a graph
shortest paths in a graph
maximum flow in a network
sorting of items in alphabetically order
searching e.g. a text for instances of a word
...

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 21 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Problems and complexity classes

The following problems are known to be in P, i.e. a


polynomial-time algorithm is known for them:
minimum spanning tree in a graph
shortest paths in a graph
maximum flow in a network
sorting of items in alphabetically order
searching e.g. a text for instances of a word
...

For many other problems no efficient (i.e. polynomial-time)


algorithm is known.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 22 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Traveling Salesman Problem

Given: A weighted graph G(V, E) on n vertices (cities).


Find: A tour through the n cities that has minimum length.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 23 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Traveling Salesman Problem

Given: A weighted graph G(V, E) on n vertices (cities).


Find: A tour through the n cities that has minimum length.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 24 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Traveling Salesman Problem

Given: A weighted graph G(V, E) on n vertices (cities).


Find: A tour through the n cities that has minimum length.

n cities ⇒ n! possibilities
5 cities ⇒ 120 possibilities
10 cities ⇒ 3’628’800 possibilities
15 cities ⇒ 1’307’674’368’000 possibilities
49 cities ⇒ 608’281’864’034’267’560’872’252’163’321’295’376’887’
’552’831’379’210’240’000’000’000 possibilities
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 25 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Traveling Salesman Problem

Given: A weighted graph G(V, E) on n vertices (cities).


Find: A tour through the n cities that has minimum length.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 26 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1954: 49 cities?

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 27 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1954: 49 cities!

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 28 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1977: 120 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 29 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1987: 532 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 30 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1987: 666 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 31 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records
1987: 2’392 points on a circuit board

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 32 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records
1994: 7’397 points on a circuit board

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 33 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

1998: 13’509 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 34 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

2001: 15’112 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 35 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

2001: 15’112 cities

Tour length ca. 66’000 km


Computation time for verifying this
on a 500 MHz computer: 22.6
years.

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 36 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

2004: 24’978 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 37 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - records

????: 1’904’711 cities

See also: http://www.math.uwaterloo.ca/tsp/index.html


Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 38 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Nearest Neighbor Heuristic

Nearest Neighbor Heuristic: Always go to closest city next.


Start in a. Does it find an optimal tour?

5
1
2
2 c
1
b
1 d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 39 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Nearest Neighbor Heuristic

Nearest Neighbor Heuristic: Always go to closest city next.


Start in a. Does it find an optimal tour?

5
1
2
2 c
1
b
1 d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 40 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Nearest Neighbor Heuristic

Nearest Neighbor Heuristic: Always go to closest city next.


Start in a. Does it find an optimal tour? No!
Compare with the optimistic approach...

5
1
2
2 c
1
b
1 d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 41 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - Nearest Neighbor Heuristic

Nearest Neighbor Heuristic: Always go to closest city next.


Start in a. Does it find an optimal tour? No!
Compare with the optimistic approach...

5
1
2
2 c
1
b
1 d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 42 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - MST-based Heuristic

MST-based Heuristic
Construct a minimal spanning tree.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 43 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - MST-based Heuristic

MST-based Heuristic
Construct a minimal spanning tree.
Duplicate each edge and convert them into directed edges
with opposite directions.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 44 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

TSP - MST-based Heuristic

MST-based Heuristic
Construct a minimal spanning tree.
Duplicate each edge and convert them into directed edges
with opposite directions.
Starting from a node s, traverse the cycle by using every
edge exactly once, such that you visit every node one time:
- Go to unvisited nodes first.
- If a node has only visited neighbors, take a shortcut to
the next unvisited node, following the unused edges.
Do so, until all edges are used and you are back at s.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 45 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A metaheuristic is a general heuristic problem-solving strategy


that can be employed in optimization problems.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 46 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A metaheuristic is a general heuristic problem-solving strategy


that can be employed in optimization problems.

Can be employed both in discrete and continuous problems.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 47 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A metaheuristic is a general heuristic problem-solving strategy


that can be employed in optimization problems.

Can be employed both in discrete and continuous problems.

Can be used both when looking for local and for global optima.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 48 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Definition

A metaheuristic is a general heuristic problem-solving strategy


that can be employed in optimization problems.

Can be employed both in discrete and continuous problems.

Can be used both when looking for local and for global optima.

Can sometimes be combined with more rigorous local methods


(e.g. intensification strategy) to search for global optima in
continious optimization problems (hybrid methods).

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 49 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Trajectory-based metaheuristics

Given a discrete or continuous optimization problem. No


efficient algorithm is known and enumerating all possibilities is
not feasible.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 50 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Trajectory-based metaheuristics

Given a discrete or continuous optimization problem. No


efficient algorithm is known and enumerating all possibilities is
not feasible.

=> Trajectory-based metaheuristics:


Start with a (random) „solution“ (e.g. an initial tour in the TSP)
and improve it step by step by exploring its „neighborhood“
(improve the tour).

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 51 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Trajectory-based metaheuristics

Given a discrete or continuous optimization problem. No


efficient algorithm is known and enumerating all possibilities is
not feasible.

=> Trajectory-based metaheuristics:


Start with a (random) „solution“ (e.g. an initial tour in the TSP)
and improve it step by step by exploring its „neighborhood“
(improve the tour).
We obtain a trajectory through the solution space, similar to
e.g. gradient descent.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 52 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Trajectory-based metaheuristics

Given a discrete or continuous optimization problem. No


efficient algorithm is known and enumerating all possibilities is
not feasible.

=> Trajectory-based metaheuristics:


Start with a (random) „solution“ (e.g. an initial tour in the TSP)
and improve it step by step by exploring its „neighborhood“
(improve the tour).
We obtain a trajectory through the solution space, similar to
e.g. gradient descent.

Often not obvious for a given problem:


- How to define and explore the solution space?
- How to define a good neighborhood?
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 53 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Overview

1 Heuristic optimization
Introduction, examples, motivation

2 Hill climbing
Algorithm

3 Tabu search
Algorithm

4 Simulated annealing
Algorithm

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 54 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing idea

Idea: Search for improvements in neighborhood and improve


current solution successively.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 55 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing
Hill climbing algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 56 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing
Hill climbing algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Continue with best solution found, if this
improves the target function. (Otherwise we’re in a local
optimum.)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 57 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing
Hill climbing algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Continue with best solution found, if this
improves the target function. (Otherwise we’re in a local
optimum.)
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 58 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing
Hill climbing algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Continue with best solution found, if this
improves the target function. (Otherwise we’re in a local
optimum.)
3 Return solution.

Variant: Always take best solution from neighborhood, even if


this decreases target function. Pros and cons?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 59 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing
Hill climbing algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Continue with best solution found, if this
improves the target function. (Otherwise we’re in a local
optimum.)
3 Return solution.

Variant: Always take best solution from neighborhood, even if


this decreases target function. Pros and cons?
+ Might better escape from local optima.
- Not monotone increasing any more.
- Might go back and forth, i.e. run into a cycle.
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 60 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Hill climbing

Implementation is trivial in principle, but...


How to define a neighbourhood, or respectively
modification steps?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 61 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Hill climbing

Implementation is trivial in principle, but...


How to define a neighbourhood, or respectively
modification steps?
Size of neighbourhood:
Too large: Computational efforts for evaluating solution
candidates are too time consuming.
Too small: Progress is slow and it might fail to explore the
solution space & gets stuck in a local optima.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 62 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Hill climbing

Implementation is trivial in principle, but...


How to define a neighbourhood, or respectively
modification steps?
Size of neighbourhood:
Too large: Computational efforts for evaluating solution
candidates are too time consuming.
Too small: Progress is slow and it might fail to explore the
solution space & gets stuck in a local optima.
Always a good idea: Multiple runs from different random
starting points.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 63 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Hill climbing

Implementation is trivial in principle, but...


How to define a neighbourhood, or respectively
modification steps?
Size of neighbourhood:
Too large: Computational efforts for evaluating solution
candidates are too time consuming.
Too small: Progress is slow and it might fail to explore the
solution space & gets stuck in a local optima.
Always a good idea: Multiple runs from different random
starting points.
Sometimes helpful: Evaluating solutions by updates, or by
some approximate computation.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 64 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Hill climbing for TSP

Find a tour through n cities with minimum length.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 65 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Neighborhood defined through modification/move steps.

g
i
h
f
e
a
b

c d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 66 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Neighborhood defined through modification/move steps.


Example: 2-change
g
i
h
f
e
a
b

c d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 67 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Neighborhood defined through modification/move steps.


Example: 2-change
g
i
h
f
e
a
b

c d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 68 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Neighborhood defined through modification/move steps.


Example: 2-change
g
i
h
f
e
a
b

c d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 69 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g
i
h
f
a
e

b c
d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 70 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 71 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 72 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 73 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 74 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 75 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 76 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 77 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 78 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 79 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 80 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 81 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 82 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 83 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 84 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 85 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 86 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 87 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 88 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Example: Move-Set for TSP

Example: 3-change

g g
i i
h h
f f
a a
e e

b c b c
d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

g g g g
i i i i
h h h h
f f f f
a a a a
e e e e

b c b c b c b c
d d d d

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 89 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Stochastic hill climbing

Stochastic hill climbing algorithm


1 Initialization: Start with random solution.
Evaluate initial solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 90 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Stochastic hill climbing

Stochastic hill climbing algorithm


1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose random solution in neighborhood (i.e. perform a
random modification). Evaluate new solution candidate,
and accept it, if it is better. Continue until termination
criterion is reached.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 91 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Stochastic hill climbing

Stochastic hill climbing algorithm


1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose random solution in neighborhood (i.e. perform a
random modification). Evaluate new solution candidate,
and accept it, if it is better. Continue until termination
criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 92 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Stochastic hill climbing

Stochastic hill climbing algorithm


1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose random solution in neighborhood (i.e. perform a
random modification). Evaluate new solution candidate,
and accept it, if it is better. Continue until termination
criterion is reached.
3 Return solution.

Pros and cons?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 93 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Terminating conditions

Terminate

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 94 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Terminating conditions

Terminate
if no significant improvement occurs after a fixed number of
steps without improvement.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 95 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Terminating conditions

Terminate
if no significant improvement occurs after a fixed number of
steps without improvement.
after a fixed total number of iterations or computing time.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 96 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Terminating conditions

Terminate
if no significant improvement occurs after a fixed number of
steps without improvement.
after a fixed total number of iterations or computing time.
when a prescribed target value for the target function is
reached.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 97 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Continuous hill climbing

Setup as previously in continuous optimization: Find x⃗


minimizing f (x⃗ ) for a given target function f ∶ Rn → R.

1 Initialization i = 0:
Initial solution x0 .
2 Iteration i → i + 1:
Sample random solution yi near xi .
yi , if f (yi ) ≤ f (xi )
xi+1 = {
xi , if f (yi ) > f (xi )
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 98 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Continuous hill climbing

Setup as previously in continuous optimization: Find x⃗


minimizing f (x⃗ ) for a given target function f ∶ Rn → R.

1 Initialization i = 0:
Initial solution x0 .
2 Iteration i → i + 1:
Sample random solution yi near xi .
yi , if f (yi ) ≤ f (xi )
xi+1 = {
xi , if f (yi ) > f (xi )
3 Return solution.
Similar to gradient descent, but since we don’t rely on
derivatives, the idea also works in discrete settings.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 99 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Continuous hill climbing

Setup as previously in continuous optimization: Find x⃗


minimizing f (x⃗ ) for a given target function f ∶ Rn → R.

1 Initialization i = 0:
Initial solution x0 .
2 Iteration i → i + 1:
Sample random solution yi near xi .
yi , if f (yi ) ≤ f (xi )
xi+1 = {
xi , if f (yi ) > f (xi )
3 Return solution.
Similar to gradient descent, but since we don’t rely on
derivatives, the idea also works in discrete settings.
Again: What does a random solution near xi mean?
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 100 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 101 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

See demo.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 102 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 103 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Hill climbing: Example

Randormisiertes Hill Climbing (100 Iterationen, sigma=0.1)


3.0

800
2.5

20

600
0
2.0

400
1.5

200
1.0

100 ●

50 50
0.5

10 ●


●●

●●●●
0.0

● ●

10
10
−0.5

60

0
0

0
40

0
0
20

0 10

60
50

80
40
20
50
0

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 104 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Overview

1 Heuristic optimization
Introduction, examples, motivation

2 Hill climbing
Algorithm

3 Tabu search
Algorithm

4 Simulated annealing
Algorithm

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 105 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search idea

Idea: Similar to hill climbing, but with some memory.


Try to avoid steps that go back to previously visited solutions, or
that undo the effect of previous steps. (These steps are „tabu“.)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 106 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search idea

Idea: Similar to hill climbing, but with some memory.


Try to avoid steps that go back to previously visited solutions, or
that undo the effect of previous steps. (These steps are „tabu“.)
The goal is to promote diversity of the solutions explored, in
particular to reduce cyclic behaviour and to escape from local
optima.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 107 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search

Tabu search algorithm (Fred Glover 1986)


1 Initialization: Start with random solution.
Evaluate initial solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 108 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search

Tabu search algorithm (Fred Glover 1986)


1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Only consider steps that are not tabu.
Proceed with step 2 with the best solution found and
update tabu list until termination criterion is reached.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 109 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search

Tabu search algorithm (Fred Glover 1986)


1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Explore neighborhood and evaluate new solution
candidates. Only consider steps that are not tabu.
Proceed with step 2 with the best solution found and
update tabu list until termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 110 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Given: Graph G = (V , E). One vertex is the depot with m


identical trucks of capacity N. All other vertices represent
customers with demand ni and service time ti . All edges are
assigned travel costs kij und travel times tij .

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 111 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Find: The least expensive set of delivery routes s.t.:


each customer gets his delivery, i.e. is on one of the routes,
each route begins and ends at the depot,
the total demand on each route does not exceed N, and
for each route, the total time (travel times tij plus service
times ti ) does not exceed some global limit T .
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 112 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 113 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:


Reassign customer to a different route.
Insert it randomly or at best possible position.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 114 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:


Reassign customer to a different route.
Insert it randomly or at best possible position.
Exchange two customers (between different routes).

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 115 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:


Reassign customer to a different route.
Insert it randomly or at best possible position.
Exchange two customers (between different routes).
Exchange two customer and reoptimize involved route(s).

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 116 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:


Reassign customer to a different route.
Insert it randomly or at best possible position.
Exchange two customers (between different routes).
Exchange two customer and reoptimize involved route(s).
Chains of exchanges, e.g. of length 3
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 117 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Neighborhoods, defined by possible moves:


Reassign customer to a different route.
Insert it randomly or at best possible position.
Exchange two customers (between different routes).
Exchange two customer and reoptimize involved route(s).
Chains of exchanges, e.g. of length 3
Optimizing the routes individually
Optimization (MSE) Autumn 2022
(cf. TSP)
Prof. Dr. Lin Himmelmann 118 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Tabu lists: Customer 1 was reassigned from route 1 to route 2:


Possible entries in the tabu list to block the reverse move:

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 119 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Tabu lists: Customer 1 was reassigned from route 1 to route 2:


Possible entries in the tabu list to block the reverse move:
Variant 1: tabu (customer 1, route 2 → route 1)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 120 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Tabu lists: Customer 1 was reassigned from route 1 to route 2:


Possible entries in the tabu list to block the reverse move:
Variant 1: tabu (customer 1, route 2 → route 1)
Variant 2: tabu (customer 1, route 2 → any other route)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 121 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

CVRP - Capacitated Vehicle Routing Problem

Tabu lists: Customer 1 was reassigned from route 1 to route 2:


Possible entries in the tabu list to block the reverse move:
Variant 1: tabu (customer 1, route 2 → route 1)
Variant 2: tabu (customer 1, route 2 → any other route)
Variant 3: tabu (customer 1) even within route 2

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 122 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu list

Organisation: Different lists for different kind of tabus?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 123 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu list

Organisation: Different lists for different kind of tabus?


Size of tabu list(s)?
Simplest variant with fixed size: Keep last k moves in the
tabu list, replace cyclically oldest entry.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 124 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu list

Organisation: Different lists for different kind of tabus?


Size of tabu list(s)?
Simplest variant with fixed size: Keep last k moves in the
tabu list, replace cyclically oldest entry.
Duration of tabus? Short-, mid- or longterm?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 125 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu list

Organisation: Different lists for different kind of tabus?


Size of tabu list(s)?
Simplest variant with fixed size: Keep last k moves in the
tabu list, replace cyclically oldest entry.
Duration of tabus? Short-, mid- or longterm?
How restrictive should the tabus be?
Forbid specific configurations, certain values for certain
variables, whole classes of moves, ...?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 126 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu list

Organisation: Different lists for different kind of tabus?


Size of tabu list(s)?
Simplest variant with fixed size: Keep last k moves in the
tabu list, replace cyclically oldest entry.
Duration of tabus? Short-, mid- or longterm?
How restrictive should the tabus be?
Forbid specific configurations, certain values for certain
variables, whole classes of moves, ...?
Are tabus enforced strictly? Allow exceptions?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 127 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Invalid solutions

Should we always rule out steps that violate constraints (e.g.


capacity or time constraints in CVRP)?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 128 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Invalid solutions

Should we always rule out steps that violate constraints (e.g.


capacity or time constraints in CVRP)?
Good valid solutions often are very close to violating the
constraints. Considering invalid solution might help with finding
these! ⇒ Allow invalid solutions but penalize them.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 129 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Invalid solutions

Should we always rule out steps that violate constraints (e.g.


capacity or time constraints in CVRP)?
Good valid solutions often are very close to violating the
constraints. Considering invalid solution might help with finding
these! ⇒ Allow invalid solutions but penalize them.
Strategic oscillation: Dynamically adjust size of penalty to
reach limits of feasiblity. If we encounter many invalid solutions,
increase penalty, if we encounter few invalid solutions, maybe
decrease penalty to encourage diversity.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 130 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Invalid solutions

Should we always rule out steps that violate constraints (e.g.


capacity or time constraints in CVRP)?
Good valid solutions often are very close to violating the
constraints. Considering invalid solution might help with finding
these! ⇒ Allow invalid solutions but penalize them.
Strategic oscillation: Dynamically adjust size of penalty to
reach limits of feasiblity. If we encounter many invalid solutions,
increase penalty, if we encounter few invalid solutions, maybe
decrease penalty to encourage diversity.
Variants:
Fixed penalty for invalid solutions
Variable penalty, adapting to degree of violation.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 131 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Randomized tabu search

Stochastic version.
1 Initialization: Start with random solution.
Evaluate initial solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 132 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Randomized tabu search

Stochastic version.
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose a random solution from the neighborhood.
Evaluate the new solution candidate, if its not tabu.
If a better solution is found, continue with this solution,
update tabu list and proceed with step 2. Continue until
termination criterion is reached.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 133 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Randomized tabu search

Stochastic version.
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose a random solution from the neighborhood.
Evaluate the new solution candidate, if its not tabu.
If a better solution is found, continue with this solution,
update tabu list and proceed with step 2. Continue until
termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 134 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Randomized tabu search

Stochastic version.
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose a random solution from the neighborhood.
Evaluate the new solution candidate, if its not tabu.
If a better solution is found, continue with this solution,
update tabu list and proceed with step 2. Continue until
termination criterion is reached.
3 Return solution.
Appropriate tabus, when optimizing a continous function?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 135 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Randomized tabu search

Stochastic version.
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Choose a random solution from the neighborhood.
Evaluate the new solution candidate, if its not tabu.
If a better solution is found, continue with this solution,
update tabu list and proceed with step 2. Continue until
termination criterion is reached.
3 Return solution.
Appropriate tabus, when optimizing a continous function?
Disable contrary moves, i.e. moves in the opposite direction.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 136 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Tabu search

Start tabu search with different starting configurations


and compare the best found solutions.
Especially: Restart in parts of the solution space that have
not yet been explored.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 137 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Tabu search

Start tabu search with different starting configurations


and compare the best found solutions.
Especially: Restart in parts of the solution space that have
not yet been explored.
Consider common parts of solutions encountered and
rule them out to explore solution space (diversity early in
the process) or
focus on them to exploit solution space (intensification later
in the process)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 138 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Tabu search

Start tabu search with different starting configurations


and compare the best found solutions.
Especially: Restart in parts of the solution space that have
not yet been explored.
Consider common parts of solutions encountered and
rule them out to explore solution space (diversity early in
the process) or
focus on them to exploit solution space (intensification later
in the process)
Keep track, if the tabus take effect.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 139 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 140 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

See demo.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 141 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 142 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Tabu search: Example

Tabu Suche (100Iterationen, r, alpha) Gegenrichtung Tabu


3.0

800
2.5

20

600
0
2.0

400
1.5

200
1.0

●●
100 ●


50 50 ●

0.5


10 ●●


● ●●
0.0

● ●

10
10
−0.5

60

0
0

0
40

0
0
20

0 10

60
50

80
40
20
50
0

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 143 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Overview

1 Heuristic optimization
Introduction, examples, motivation

2 Hill climbing
Algorithm

3 Tabu search
Algorithm

4 Simulated annealing
Algorithm

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 144 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Idea

Idea from solid physics when cooling down crystalline


structures


◊ ◊



◊◊



liquid fused
crystal substance

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 145 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Idea

Idea from solid physics when cooling down crystalline


structures

◊◊
◊◊


◊◊ ◊
◊◊
fast cooling
defective crystal
◊ structure
◊ ◊



◊◊



liquid fused
crystal substance

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 146 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Idea

Idea from solid physics when cooling down crystalline


structures

◊◊
◊◊


◊◊ ◊
◊◊
fast cooling
defective crystal
◊ structure
◊ ◊



◊◊



liquid fused slow cooling
crystal substance ◊◊◊
◊◊◊◊
◊◊◊
perfect crystal
structure
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 147 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Idea

The ideal state of minimal energy is a perfect crystal


structure. When cooling happens too quickly, the crystalline
structures cannot form properly – the liquid fused material gets
stuck in suboptimal state.
To get a perfect crystal structure it is necessary to escape from
local optima. The probability of a state (crystal structure) x with
E(x)
energy E(x) at temperature T ≥ 0 is proportional to e− T .
Determined by these probabilities the material changes its
structure and it is also possible to switch to inferior states (and
leave local optima). These probabilities increase with higher
temperature.
Do hill climbing with a high temperature T and decrease T to
zero over time according to some cooling schedule.
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 148 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 149 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 150 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Propose random solution in neighborhood and evaluate it.
If it is better, accept it. If it is worse, accept it only with
some probability.
Iterate step 2 until termination criterion is reached.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 151 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Propose random solution in neighborhood and evaluate it.
If it is better, accept it. If it is worse, accept it only with
some probability.
Iterate step 2 until termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 152 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Idea 1: Accept with fixed probability e.g. 0.1
Propose random solution in neighborhood and evaluate it.
If it is better, accept it. If it is worse, accept it only with
some probability.
Iterate step 2 until termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 153 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Idea 1: Accept with fixed probability e.g. 0.1
Propose random solution in neighborhood and evaluate it.
IfIdea
it is 2:
better, accept it.decreases
Probability If it is worse,
overaccept
time it only with
some probability.
Iterate step 2 until termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 154 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Idea 1: Accept with fixed probability e.g. 0.1
Propose random solution in neighborhood and evaluate it.
IfIdea
it is 2:
better, accept it.decreases
Probability If it is worse,
overaccept
time it only with
some probability.
Iterate
Idee 3:step 2 until termination
Probability decreases criterion is reached.
over time and
3 also
Return solution. depends on quality of solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 155 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Algorithm

Simulated annealing is similar to hill climbing, but also allows


non-improving moves to escape from local optima.

Algorithm
1 Initialization: Start with random solution.
Evaluate initial solution.
2 Iteratively:
Propose random solution in neighborhood and evaluate it.
If it is better, accept it. If it is worse, accept it only with
some probability.
Iterate step 2 until termination criterion is reached.
3 Return solution.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 156 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing

1 Initialization:
Start with random solution x0 .

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 157 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing

1 Initialization:
Start with random solution x0 .
2 Iteratively: xi → xi+1
Propose random solution yi in the neighborhood of xi and
f (xi )−f (yi )
accept it to be xi+1 with probability min {1, e Ti
}.
Otherwise xi+1 = xi .

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 158 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing

1 Initialization:
Start with random solution x0 .
2 Iteratively: xi → xi+1
Propose random solution yi in the neighborhood of xi and
f (xi )−f (yi )
accept it to be xi+1 with probability min {1, e Ti
}.
Otherwise xi+1 = xi .
Note:
f (xi )−f (yi )
If f (yi ) ≤ f (xi ) we have e Ti
≥ 1 and yi is accepted.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 159 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing

1 Initialization:
Start with random solution x0 .
2 Iteratively: xi → xi+1
Propose random solution yi in the neighborhood of xi and
f (xi )−f (yi )
accept it to be xi+1 with probability min {1, e Ti
}.
Otherwise xi+1 = xi .
Note:
f (xi )−f (yi )
If f (yi ) ≤ f (xi ) we have e Ti
≥ 1 and yi is accepted.
If T is very large, every solution yi will be accepted.
f (xi )−f (yi ) f (xi )−f (yi )
min{1, e Ti
} = min{1, e ∞ } = min{1, e±0 } = 1

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 160 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing

1 Initialization:
Start with random solution x0 .
2 Iteratively: xi → xi+1
Propose random solution yi in the neighborhood of xi and
f (xi )−f (yi )
accept it to be xi+1 with probability min {1, e Ti
}.
Otherwise xi+1 = xi .
Note:
f (xi )−f (yi )
If f (yi ) ≤ f (xi ) we have e Ti
≥ 1 and yi is accepted.
If T is very large, every solution yi will be accepted.
f (xi )−f (yi ) f (xi )−f (yi )
min{1, e Ti
} = min{1, e ∞ } = min{1, e±0 } = 1
If T →0 only better solutions (f (yi )<f (xi )) will be accepted.
f (xi )−f (yi ) f (xi )−f (yi )
min{1, e Ti
} = min{1, e +0 } = min{1, e±∞ } = 0 or 1
Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 161 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Cooling schedules

Different cooling schedules for Ti are possible:

temperature

120
100
80
60
40
20
0
0 100 200 300 400 500 600 700 800 900 1000 iteration i

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 162 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Cooling schedules

Different cooling schedules for Ti are possible:

temperature

120
100
80
60
40
20
0
0 100 200 300 400 500 600 700 800 900 1000 iteration i

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 163 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Cooling schedules

Different cooling schedules for Ti are possible:

temperature

120
100
80
60
40
20
0
0 100 200 300 400 500 600 700 800 900 1000 iteration i

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 164 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Cooling schedules

Different cooling schedules for Ti are possible:

temperature

120
100
80
60
40
20
0
0 100 200 300 400 500 600 700 800 900 1000 iteration i

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 165 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Cooling schedules

Different cooling schedules for Ti are possible:

temperature

120
100
80
60
40
20
0
0 100 200 300 400 500 600 700 800 900 1000 iteration i

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 166 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Simulated annealing

Start Simulated annealing with different starting


configurations and compare the best found solutions.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 167 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Simulated annealing

Start Simulated annealing with different starting


configurations and compare the best found solutions.
Adjust the neighbourhood dynamically. How?

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 168 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Remarks on Simulated annealing

Start Simulated annealing with different starting


configurations and compare the best found solutions.
Adjust the neighbourhood dynamically. How?
wider neighbourhood to explore solution space (diversity
early in the process)
closer neighbourhood to exploit solution space
(intensification later in the process)

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 169 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 170 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

See demo.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 171 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Example


2
Rosenbrock function: f (x, y ) = (1 − x)2 + 100(y − x 2 )

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 172 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

Simulated annealing: Example

Simulated Annealing (100 Iterationen, sigma=0.1)


3.0

800
2.5

20

600
0
2.0

400
1.5

200
1.0

100 ●

50 50
0.5


10 ●●
● ●

0.0

●●

10
10
−0.5

60

0
0

0
40

0
0
20

0 10

60
50

80
40
20
50
0

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 173 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

What’s next?

Next time: Metaheuristic optimization: Population-based


methods.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 174 von 174
Heuristic optimization Hill climbing Tabu search Simulated annealing

What’s next?

Next time: Metaheuristic optimization: Population-based


methods.
Exercise session: - Exercises, time for individual
questions.

Optimization (MSE) Autumn 2022 Prof. Dr. Lin Himmelmann 175 von 174

You might also like