Local search

SCHOOL OF COMPUTING
Design & Analysis of Algorithms
Combinatorial optimization
Pasi Fränti
27.4.2016
Optimization techniques
•
•
•
•
Local search
Stochastic variations of local search
Genetic algorithms
Swarm Intelligence
Knapsack problem
Simplified
Input:
Weight of N items {w1, w2, ..., wn}
Knapsack limit S
Output: Selection for knapsack: {x1,x2,…xn}
where xi {0,1}.
5
3
Sample input:
wi={2,3,5,7,11}
S=15
7
2
11
Max 15
Knapsack as decision tree
Yes
Chooce 2
No
2
No
Yes
Chooce 3
5
Yes
17
3
-
5
7
No Yes
2
3
8
No
5
No
Yes
10 12 5
…
28
No
No Yes
Yes
Chooce 7
Yes
2
No Yes
10
Chooce 5
-
5 14
9
…
12
2
15
8
No
14
13
26 15
10
3
12
5
…
7
-
…
12
-
In context of search tree
Brute force:
search full tree
Heuristics
2
5
-
2
3
-
Greedy
5
10
17
10 12 5
7
5 14
2
9
2
8
15
8
…
28
10 12
5
3
10
3
12
-
5
…
14
13
26 15
Local search
7
-
…
12
-
Local search
Main principle of local search
Select one and move
Structure 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
12
21
best
9
15
12
13
14
9
11
13
17
7
best
Components of local search
Representation of solution
•
•
Bit string (0010111010001…)
Problem-domain data structure
TSP
{1, 3, 5, 2…}
Neighborhood function (move)
•
•
Bits: (0010111010001…)  (0010011010001…)
Application domain: {1, 3, 5, 2…}  {1, 5, 3, 2…}
Search strategy
•
•
Best-improvement: try all, select best
First-improvement: select first that improves.
Movement in neighborhood
Study neighbor solutions
Search strategy
Best improvement:
12
First improvement:
12 first
9 best
21
21
13
14
13
17
Hill-climbing (max!) /
Descendent (min!
15
12
21
9
13
6
11
10
14
dead end
8
7
5
8
4
17
8
7
9
Hill climbing
Accept only better solutions
Local and global maxima
Combining local search
and hill-climbing
Local search for Knapsack
Representation of knapsack
• 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.
Move in knapsack
S=15 W=[2, 3, 5, 7, 11]
01010
10
10010
Single bit change:
01 or 10
9
11010
11110
12
17
11000
5
11011
23
Extended neighborhood
S=15 W=[2, 3, 5, 7, 11]
Two operations:
11110
17
11011
23
01110
12
• 01 or 10
15 • Swap bit location
01011
11010
10110
11001
14
16
10101
10011
18
11100
10
21
Local maximum
S=15 W=[2, 3, 5, 7, 11]
14
01001
00101
16
00011
13
18
11000
10001
10100
10010
9
7
5
Tabu search
S=15 W=[2, 3, 5, 7, 11]
00101
16
10001
13
Tabu!
00011
18
Prevents search to
return previously
visited solutions
11000
14 01001
01100
01010
10
5
8
Select the next best
Tabu search (2nd iteration)
S=15 W=[2, 3, 5, 7, 11]
11010
12
01110
15
01011
10 01010
21
Traveling salesman problem
Permute local changes in given route
...
...
...
...
...
...






pi-1
pi-1
pi
pi
pi+1
pi+1
 pi
 pi+1
 pi-1
 pi+1
 pi
 pi-1
 pi+1
 pi
 pi+1
 pi-1
 pi-1
 pi






...
...
...
...
...
...
Local search 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).
1 2
6
{S ,S ,...,S }  PermutateTriple(i-1 i, I+1).
1 2
6
S  SelectBest(S ,S ,...,S ).
UNTIL no improvement.
TSP example
EF G HA
EF H GA
EG F HA
EG H FA
EH G F A
EH F GA
B
2
2
C
2
4
3
A
4++2+ =
4+3+2+2 =
++3+=
+2+3+ =
3+2++ =
3+3++2 =
D
5
3
G
2
4
E
3
2
4
F
3
H
2 + 6
11 min!
3 + 3
2 + 5
2 + 5
1 + 6
Genetic algorithm
Genetic algorithm (GA)
Main structure of GA
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.
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 ij.
RETURN(i, j)
i
1
1
2
j
4
5
...
Elitist approach using
zigzag scanning among the best
solutions
3
2
3
4
5
...
Chess playing
Minmax technique
Tic-tac-toe example
Optimizing
chess
playing
Evaluation function
Minmax example
Minmax playing: Min’s move
Minmax playing: Max’s move
Minimax maximizes the
worst-case outcome for max
Chess Game tree
Beyond the horizon
Evaluating Chess position
Positional factors
Initial value range
0
1
2
3
4
queen
rook
bishop
knight
pawn
[800-1000]
[440-540]
[300-370]
[290-360]
[85-115]
5
6
7
8
9
1
0
1
1
1
2
1
3
1
4
bishop pair (+)
castling done (+)
castling missed (-)
rook on an open file (+)
rook on a semi-open file (+)
[0-40]
[0-40]
[0-50]
[0-30]
[0-30]
connected rooks (+)
[0-20]
rook(s) on the 7th line (+)
[0-30]
(supported) knight outpost
(+)
(supported) bishop outpost
(+)
knights’ mobility >5 (>6)
(+)
[0-40]
[0-30]
[0-30]
Result of optimization
360
350
Knight
340
330
320
310
300
generation
39
37
35
33
31
29
27
25
23
21
19
17
15
13
11
9
7
5
3
290
1
average generation value
Bishop
Swarm intelligence
Swarm intelligence (SI)
• 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
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.
Ant colony optimization
1st round
Input graph:
B
D
E
4
C
B
23
21
F
A
C
D
E
G
B
F
A
D
E
H
G
H
C
B
C
F
3
3
3
2
5
B
2
3
C
4
4
A
2
2
G
2
H
Additions made:
+1
-1
G
0
-1
D
E
0
-1
0
C
+1
+1
A
-1
0
0
H
26
24
F
A
D
E
G
H
F
A
D
E
G
H
+1
B
F
Ant colony optimization
2nd round
Modified graph:
B
D
E
4
C
B
21
F
A
C
22
D
E
G
B
F
A
D
E
H
G
H
C
B
C
F
4
2
2
3
5
B
1
3
C
5
5
A
1
2
G
2
H
New additions:
0
-1
E
0
+1
-1
G
0
C
-1
D
0
+1
0
0
+1
A
0
B
H
23
22
F
A
D
E
G
H
F
A
D
E
G
H
F
The end