Search and Optimization Strategies

55
Search and Optimization Strategies Tecniche di Programmazione – A.A. 2012/2013

description

Search and Optimization Strategies Topics: Definitions Branch & Bound Greedy Local Search Teaching material for the course of "Tecniche di Programmazione" at Politecnico di Torino in year 2012/2013. More information: http://bit.ly/tecn-progr

Transcript of Search and Optimization Strategies

Page 1: Search and Optimization Strategies

Search and Optimization Strategies

Tecniche di Programmazione – A.A. 2012/2013

Page 2: Search and Optimization Strategies

Summary

A.A. 2012/2013 Tecniche di programmazione 2

Definitions

Branch & Bound

Greedy

Local Search

Page 3: Search and Optimization Strategies

Definitions

Search and Optimization Strategies

Page 4: Search and Optimization Strategies

Search vs Optimization

A.A. 2012/2013 Tecniche di programmazione 4

A search algorithm is an algorithm for finding an item

with specified properties among a collection of items

Specified properties: usually “local” properties, defined by some

“feasibility” criteria

Collection: explicit, or virtual (implicit)

An optimization algorithm aims ad finding the best

possible solution, according to an objective function,

among all possible feasible solutions for a given

problem

Page 5: Search and Optimization Strategies

Objective function

A.A. 2012/2013 Tecniche di programmazione 5

Must be computable for all feasible solutions

May be undefined for unfeasible (or incomplete) solutions

Maximization problems

Objective function = value, goodness

Must find the maximum value of objective function

Minimization problems

Objective function = cost

Must find the minimum value of objective function

Page 6: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 6

Types of problems

Search problems: is there (at least one) feasible solution?

Ex: magical square

Ex: Hamiltonian cycle

Optimization problems: what is the best solution?

In these problems finding feasible solutions is usually easy

Ex: Hamiltonian cycle on a complete graph (Hamiltonan bee)

Hybrid problems (search + optimization): are there any valid

solutions? And what is the best?

Ex: travelling salesman problem

Page 7: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 7

Representation

S: Solutions

V: Valid (feasible) solutions

M: best solutions

s

s

s f(s)

Objective

function

Page 8: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 8

Classification

Search problems

S V

|V| = 0 ?

Find a s V

Optimization problems

S = V

find max(f(s))

Hybrid problems

S V

find max(f(s))

such that s V

Page 9: Search and Optimization Strategies

Exact techniques

A.A. 2012/2013 Tecniche di programmazione 9

Exhaustive generation of all possible solutions

Iteratively

Recursively

Optimizing recursive techniques

Visit order

Generate non-useless solutions: Branch and Bound

Recognize equivalent sub-problems: Dynamic Programming

1 2

3 4

5 6

7 8

Page 10: Search and Optimization Strategies

Approximate Tecniques

A.A. 2012/2013 Tecniche di programmazione 10

Greedy

Pseudo-random

Hill climber

1

2 3

Page 11: Search and Optimization Strategies

Approximate solutions

A.A. 2012/2013 Tecniche di programmazione 11

Optimum solution: the absolute best

Optimal solution: a solution that

approximates the optimum one (might be coincident, but we

don’t know)

can no longer be improved with the chosen optimization

technique

Locally optimum solution: optimum solution in a

continuous domain

Page 12: Search and Optimization Strategies

Intuitively…

A.A. 2012/2013 Tecniche di programmazione 12

x

f(x)

Optimum

solution

Optimal

solution

Locally

optimum

solutions

Page 13: Search and Optimization Strategies

Computational Intelligence

A.A. 2012/2013 Tecniche di programmazione 13

Evolutionary Algorithms

Genetic Algorithms

Genetic Programming

Simulated annealing

Tabu-Search

Page 14: Search and Optimization Strategies

Branch & Bound

Search and Optimization Strategies

Page 15: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 15

Introduction

Branch and Bound is an exact method for exploring all

solutions based on their implicit enumeration

All solutions are considered, but not one-by-one. In fact

B&B:

Considers disjoints subsets of solutions (branching)

Evaluates them according to an estimate of the objective

function (bounding), by eliminating (pruning) those subsets that

may not contain the optimum solution

Page 16: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 16

Definition

z*: a sub-optimal estimate of the final result

Initialized to + for minimization problems

Initialized to - for maximization problems

z(r)E : the exact solution of sub-problem P(r)

z(r)B: a super-optimal estimate of solutions of sub-problem

P(r)

lower bound for minimization problems

upper bound for maximization problems

Page 17: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 17

General algorithm (I)

Branch-and-bound is a divide-et-impera method:

Divide a given problem (and its set of feasible solutions) in sub-

problems to be analyzed separately.

Keep a list P of open sub-problems

At each step, select one current problem P(r)

Page 18: Search and Optimization Strategies

General algorithm (II)

A.A. 2012/2013 Tecniche di programmazione 18

If P(r) has no feasible solutions, it is closed

If P(r) has (at least one) solution, and may be solved up to

the optimum z(r)E

P(r) is closed

Its solution, with value z(r)E, may possibly replace z*, if it

improves it

Page 19: Search and Optimization Strategies

General algorithm (III)

A.A. 2012/2013 Tecniche di programmazione 19

Se P(r) has solutions, but it’s difficult to be solved up to the optimum, we try to show that it may not yield a better solution than the already known ones.

We compute a super-optimal estimate z(r)B of its solutions:

If z(r)B is not better than z*, all solutions in P(r) are dominated

by the best known-solution, and P(r) may be closed

If z(r)B is better than z*, P(r) is broken into sub-problems that

are inserted in the list P. P(r) is closed, and the sub-problems will be opened, eventually.

Page 20: Search and Optimization Strategies

General algorithm (IV)

A.A. 2012/2013 Tecniche di programmazione 20

Proceed until P is empty

When P is empty, then z* is the exact optimum solution for the original problem.

Page 21: Search and Optimization Strategies

The solution tree

A.A. 2012/2013 Tecniche di programmazione 21

P0

P1 P2

P21 P22

P11 P12

P111 P112

P12

Node: sub-problem

Leaf node: closed sub-problem

Page 22: Search and Optimization Strategies

Ingredients of a B&B algorithm

A.A. 2012/2013 Tecniche di programmazione 22

Strategy of visit of the search tree: criteria to choose the

next sub-problem to be analyzed out of the list P

Bounding technique: how to evaluate the super-optimal

estimate z(r)B

Branching rule: how to split the current problem P(r) into

smaller sub-problems.

Page 23: Search and Optimization Strategies

Main features

A.A. 2012/2013 Tecniche di programmazione 23

Advantages:

Finds optimum solution

May limit the number of visited solutions

May give a partial (approximate) solution, if stopped earlier

Disadvantages:

Computation time for visiting the solution tree depends on the strategy

The worst case is to visit all possible nodes, anyway

Time needed to compute z(r)B.

Page 24: Search and Optimization Strategies

Greedy

Search and Optimization Strategies

Page 25: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 55

Introduction

A greedy algorithm searches for a globally optimal

solution, by choosing locally optimum ones.

The adopted technique is shortsighted:

Every choice made at any step is never re-considered again

No back-tracking

Basic principle: define an “attractiveness” for every partial

solution

Attractiveness (it: appetibilità) = estimate of how much, probably,

we are close to the optimum.

Page 26: Search and Optimization Strategies

General structure (I)

A.A. 2012/2013 Tecniche di programmazione 56

If the attractiveness {ai} of partial solutions are known

since the beginning, and may not be modified

Greedy ({a1, a2, …an})

S ø

sort {ai} in decreasing attractiveness order

for each ai do

if ai may be added to S

then S S {ai}

return S

Page 27: Search and Optimization Strategies

General structure (II)

A.A. 2012/2013 Tecniche di programmazione 57

If attractiveness may be modified by the effects of

previous choices

Greedy2 ({a1, a2, …an})

S ø

compute attractiveness of ai

while there are element to choose do

choose the most-attractive ai

if ai may be added to S

then S S {ai}

update the remaining ai

return S

Page 28: Search and Optimization Strategies

Example

A.A. 2012/2013 Tecniche di programmazione 58

Find the minimum number of coins to give change to a

customer.

We assume we have a list of possible coin values, and

their availability is infinite

Page 29: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 59

Example

Available coins

20, 10, 5, 2, 1

Change to give

55

Page 30: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 60

Algorithm

At each step, select the highest-valued coin, whose value

is less than the remaining change

Remaining change Chosen coin

55 20

35 20

15 10

5 5

Page 31: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 61

Features

Advantages

Extremely simple algorithm

Very fast computational time

Disadvantages

The solution is optimal, non necessarily optimum

Page 32: Search and Optimization Strategies

Non-optimum solution

A.A. 2012/2013 Tecniche di programmazione 62

Input:

Coins of 6, 4, 1

Change to give:

9

Greedy solution:

4 coins: 6, 1, 1, 1

Optimum solution :

3 coins: 4, 4, 1

Page 33: Search and Optimization Strategies

Local Search

Search and Optimization Strategies

Page 34: Search and Optimization Strategies

Applicability

A.A. 2012/2013 Tecniche di programmazione 72

Suitable for problems where:

There is an underlying “structure” in the solution space

There is a clear objective function

The search space is too vast

Exact algorithms are not knows

“Similar solutions have similar cost”

Page 35: Search and Optimization Strategies

Iterative improvement

A.A. 2012/2013 Tecniche di programmazione 73

A family of methods

Common basic idea

Start from an initial (random) configuration

Consider various possible moves starting from that configuration

Accept or refuse such moves, depending on the objective function

When you cannot improve anymore, start again

Page 36: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 74

Example

Page 37: Search and Optimization Strategies

Moves

A.A. 2012/2013 Tecniche di programmazione 75

We must define a set of moves to lead from one

solution to another

The set of possible moves defined the neighborhood of

a solution

Moves are often implemented as small variations

(mutation) on the encoded solution

Page 38: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 76

Example: TSP (I)

“2-opt”neighborhood

Page 39: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 77

Example: TSP(II)

3-opt neighborhood

Page 40: Search and Optimization Strategies

Hill Climbing (I)

A.A. 2012/2013 Tecniche di programmazione 78

For every configuration, evaluate all possible moves

(explore the whole neighborhood)

Refuse all moves that worsen the objective function

Accept the move that leads to the highest improvement

of the objective function

If all moves worsen the objective function, quit.

Page 41: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 79

Hill Climbing (II)

X = startinc configuration E = eval(X) do {

N = n_moves(X) for (i=0; i<N; ++i) Ei = eval(move(X,i)) if (all Ei E) return X i* = { i | max(Ei) } X = move(X, i*) E = Ei*

} while(1)

Page 42: Search and Optimization Strategies

Features

A.A. 2012/2013 Tecniche di programmazione 80

Greedy

Simple to implement

No backtracking => no recursion, no memory

Needs “clever” definition of moves

Sometimes, the objective function may be incrementally

computed

Page 43: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 81

Problems (I)

Foothill: getting trapped in local maxima

Hillclimber final point

Start

Real maximum

Page 44: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 82

Problems (II)

Mesa: wide regions with null or negligible variation of the

objective function

Needle in the haystack: isolated peak in a desolated

landscape

Page 45: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 83

Variants

First-ascent

Accept the first move that improves the objective function

Best-ascent

Evaluate all moves and accept the best one

Threshold-accept

Accept the first move that improves the current configuration by an

amount higher that a fixed threshold

…etc…

Page 46: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 84

Example

111 fitness 10

011 fitness 12

101 fitness 20

110 fitness 5

First ascent

Best ascent

011 fitness 12

101 fitness 20

Neighborhood definition:

‘complement one bit’

Page 47: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 85

Random Restart Hill Climbing

Repeat the Hill Climbing procedure starting from many initial

starting points

X = random configuration Best = X do { X’ = HillClimber(X) if (Eval(X’) > Eval(Best)) Best = X’ X = random configuration } while( ! Enough )

Page 48: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 86

Simulated Annealing

Stochastic approach for function minimization

The name is taken from the physical process of

crystallization of a liquid into solid state

The minimum of the cost function corresponds to the

crystal state of the substance (minimum energy)

Simulated Annealing gradually “lowers” the “temperature”

until the system “freezes”

Page 49: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 87

Algorithm (I)

Start with a random solution

Choose a solution in the neighborhood

If the energy of the new solution is less than the current one,

accept the move

If the energy is more than the current one, the move may be

accepted, with a probability

The probability to accept “bad” moves depends on

Amount of worsening (DE)

Temperature (simulated) of the system

Page 50: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 88

Algorithm(II)

current = start state

for time = 1 to forever do

T = schedule[time]

if T = 0 return current

next = a randomly chosen successor of current

dE = value(next) – value(current)

if dE > 0 then current = next

else current = next with probability edE/T

end for

Page 51: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 89

Features

The system may “jump out” of local minima by accepting

worse solutions

At higher temperatures, worsening jumps are easier, at

lower temperature they become unlikely

Temperature is gradually reduced

At T=0, the algorithm converges to the locally optimum

solution (hill climbing behavior)

Page 52: Search and Optimization Strategies

A.A. 2012/2013 Tecniche di programmazione 90

Boltzmann distribution

dE

P(accettazione)

1 T=max

T=0

Page 53: Search and Optimization Strategies

Other local search algorithms

A.A. 2012/2013 Tecniche di programmazione 91

Tabu Search

Ant Colony

Genetic Algorithms

Page 54: Search and Optimization Strategies

Resources

A.A. 2012/2013 Tecniche di programmazione 92

Page 55: Search and Optimization Strategies

Licenza d’uso

A.A. 2012/2013 Tecniche di programmazione 93

Queste diapositive sono distribuite con licenza Creative Commons “Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA)”

Sei libero: di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,

rappresentare, eseguire e recitare quest'opera

di modificare quest'opera

Alle seguenti condizioni: Attribuzione — Devi attribuire la paternità dell'opera agli autori originali

e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera.

Non commerciale — Non puoi usare quest'opera per fini commerciali.

Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa.

http://creativecommons.org/licenses/by-nc-sa/3.0/