Design & Analysis of Algorithms Combinatory optimization SCHOOL OF COMPUTING Pasi Fränti...

Post on 02-Jan-2016

226 views 0 download

Transcript of Design & Analysis of Algorithms Combinatory optimization SCHOOL OF COMPUTING Pasi Fränti...

Design & Analysis of Algorithms

Combinatory optimization

SCHOOL OF COMPUTING

Pasi Fränti20.10.2014

• Local search• Stochastic variations of local search• Genetic algorithms• Swarm Intelligence

Optimization techniques

Here decision tree picture!!!

Optimization techniques in context

Local search

Select one and move

Main principle of local search

LocalSearch:

Generate initial solution. REPEAT

Generate a set of new solutions. Evaluate the new solutions. Select the best solution.

UNTIL stopping criterion met.

Structure of local search

• Representation of solution• Neighborhood function• Search strategy

Components of local search

Study neighbor solutions

Movement in neighborhood

Accept only better solutions

Hill climbing

Local and global maxima

Combining local search and hill-climbing

• Represent solution as bit string (x1x2,…xn), where xi {0,1}.

• Problem instance: wi= (2,3,5,7,11), S=15.

• Solution with elements 2,3 and 7 is represented as 11010.

Local search for knapsack

0 1 0 1 0

1 0 0 1 0

1 1 1 1 0

1 1 0 0 0

1 1 0 1 1

1 1 0 1 0

12

10

9

5

17

23

Single bit change: 01 or 10

S=15 W=[2, 3, 5, 7, 11]Move in knapsack

1 1 0 1 012

0 11 1 015

0 1 0 11 21

1 0 11 0

14

11 1 1 0 17 11 0 11 23

1 0 1 0 1

1811 1 0 010

11 0 0 1

16

Two operations:

• 01 or 10

• Swap bit location

Extended neighborhoodS=15 W=[2, 3, 5, 7, 11]

10011

1 0 0 0 113 1 1 0 0 0 5

1 0 1 0 0 7

0 1 0 0 114

0 0 1 0 1 16

100109

0 0 0 1 1 18

Getting stuck into local maximumS=15 W=[2, 3, 5, 7, 11]

0 1 0 0 114 11 0 0 0 5

0 11 0 0 8

1 0 0 0 113

0 0 1 0 1 16

0 1 0 1 010

0 0 0 11 18

Prevents search to return previously visited solutions

Select the next best

Tabu!

S=15 W=[2, 3, 5, 7, 11]Tabu search

0 1 0 1 010

0 1 0 1121

11 0 1 0 12

0 11 1 0 15

Tabu search (2nd iteration)S=15 W=[2, 3, 5, 7, 11]

Traveling salesman problem

... pi-1 pi pi+1 ...

... pi-1 pi+1 pi ...

... pi pi-1 pi+1 ...

... pi pi+1 pi-1 ...

... pi+1 pi pi-1 ...

... pi+1 pi-1 pi ...

Permute local changes in given route

Local search algorithm for TSP

LocalSearchTSP(G:graph): solution; S {1,2,...,N}. FOR i:=1 TO N DO

Swap( S[i], S[random(1,N)] ).

REPEAT i Random(2..N-1). {S1,S2,...,S6 } PermutateTriple(i-1 i, I+1). S SelectBest(S1,S2,...,S6).

UNTIL no improvement.

TSP example

E F G H A 4 + + 2 + = 2 + 6

E F H G A 4 + 3 + 2 + 2 = 11 min!

E G F H A + + 3 + = 3 + 3

E G H F A + 2 + 3 + = 2 + 5

E H G F A 3 + 2 + + = 2 + 5

E H F G A 3 + 3 + + 2 = 1 + 6

A

B C

D E F

G H

22

24 4

3 32

23

43 5

Genetic algorithm

Genetic algorithm (GA)

Needs more material!

Generate a set of initial solutions.

REPEAT Generate new solutions by crossover. Mutate the new solutions (optional). Evaluate the candidate solutions. Retain best candidates and delete the rest.

UNTIL stopping criterion met.

Main structure of GA

Permuting pairs for crossover

Select next pair(i, j): REPEAT

IF (i+j) MOD 2 = 0 THEN i max(1, i-1); j j+1; ELSE j max(1, j-1); i i+1;

UNTIL ij. RETURN(i, j)

Elitist approach using zigzag scanning among the best

solutions

Optimizing chess

playing

Revise

Tic-tac-toe example

Evaluation function for tic-tac-toe

Minmax example

Redraw

Minmax playing: Min’s move

Minimax maximizes the worst-case outcome for max

Minmax playing: Max’s move

Chess Game tree

Beyond the horizon

Evaluating Chess position

Positional factors

0 queen [800-1000] 1 rook [440-540] 2 bishop [300-370] 3 knight [290-360] 4 pawn [85-115] 5 bishop pair (+) [0-40] 6 castling done (+) [0-40] 7 castling missed (-) [0-50] 8 rook on an open file (+) [0-30] 9 rook on a semi-open file (+) [0-30] 10

connected rooks (+) [0-20]

11

rook(s) on the 7th line (+) [0-30]

12

(supported) knight outpost (+)

[0-40]

13

(supported) bishop outpost (+)

[0-30]

14

knights’ mobility >5 (>6) (+)

[0-30]

Initial value range

290

300

310

320

330

340

350

360

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39

generation

aver

age

gene

ratio

n va

lue

Bishop

Knight

Result of optimization

Swarm intelligence

• Social intelligence: individual behavior maybe naive but joint effect can be intelligent.

• Decentralized: no central control of the individuals of the colony

• Self-organized: individual adapts to environment and other members of colony

• Robust: Task is completed even if some individuals fail

Swarm intelligence (SI)

Ant colony optimization (ACO)

Main principle:

• Emitting pheromone between nest and food• Joint efforts to carry loads

Solving TSP by ants:

• Sending ants to make randomized tours• Short links chosen more often than long ones• Good tracks are marked by pheromone• Tracks with high pheromone chosen more often

Ant colony optimization

Initialization:

• Generate randomized tours.

• Smaller links chosen more often than longer ones

Simulate pheromone:

• Subtract cost of the links in best solution (-1)

• Increase the ones in the worst solution (+1)

• Tours are evaluated using the original graph.

A F

C

D

H

B

G

E

A F

C

D

H

B

G

EA F

C

D

H

B

G

E

A F

C

D

H

B

G

E2 1 2 3

2 4 2 6

A F

C

D

H

B

G

E

0

-1

+ 1

0

-1

+ 1

000

-1+

1

+1

-1

A F

C

D

H

B

G

E

2

2

2

2

2

3

453

34 4

3

In p u t grap h :

A d d it io n s m ad e:

Ant colony optimization (1st round)

A F

C

D

H

B

G

E

0

0

+ 1

0

-1

+ 1

000

-10 +1

-1

A F

C

D

H

B

G

E

2

1

3

2

1

4453

25 5

2

A F

C

D

H

B

G

E A F

C

D

H

B

G

E

2 1 2 2

A F

C

D

H

B

G

E

2 3A F

C

D

H

B

G

E

2 2

M o d ified grap h :

N ew ad d it io n s :

Ant colony optimization (2nd round)