heuristic optimization athens 2004 department of architecture and technology universidad...
Post on 19-Dec-2015
217 views
TRANSCRIPT
![Page 1: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/1.jpg)
Heuristic OptimizationAthens 2004
Department of Architecture and Technology
Universidad Politécnica de Madrid
Víctor Robles
![Page 2: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/2.jpg)
Teachers
Universidad Politécnica de Madrid Víctor Robles (coordinator) María S. Pérez Vanessa Herves
Universidad del País Vasco Pedro Larrañaga
![Page 3: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/3.jpg)
Course outline and Class hours
Day 1 / 10:00-14:00 / Víctor Introduction to optimization Some optimization problems About heuristics
Greedy algorithmsHill climbing
Simulated Annealing
![Page 4: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/4.jpg)
Course outline and Class hours
Day 2 / 9:30-13:30 / Víctor, María Learn by practice: Simulated Annealing Genetic Algorithms
Day 3 / 9:30-13:30 / Vanessa Learn by practice: Genetic Algorihtms
Day 4 / 10:00-13:30 / Pedro Estimation of Distribution Algorithms
![Page 5: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/5.jpg)
Introduce yourself
Name University / Country Optimization experience Expectations of the course
![Page 6: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/6.jpg)
Optimization
A optimization problem is a par being the search space (all the possible solutions), and a function,
The solution is optime if,
Combinatorial optimization Systematic search
RXf :
XxoptXxxfxf opt ),()(
),( fX
Xf
![Page 7: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/7.jpg)
State space landscape
Objective function defines state space landscape
![Page 8: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/8.jpg)
Some optimization problems
TSP – Travel Salesman Problem The assignment problem SAT – Satistiability problem The 0-1 knapsack problemImportant tasks Find a representation of possible solutions To be able to evaluate each of the possible
solutions “fitness function” or “objective function”
![Page 9: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/9.jpg)
TSP
A salesman has to find a route which visits each of n cities, and which minimizes the total distance travelled
Given an integer and a n x n matrix
where each is a nonnegative integer. Which cyclic permutation of integers from 1 to n minimizes the sum ?
3n)( ijcC
ijc
n
ii ic
1
![Page 10: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/10.jpg)
TSP representations
Binary representation Each city is encoded as a string of [log2n] bits.
Example 8 cities 3 bits Path representation
A list is represented as a list of n cities. If city i is the j-th element of the list, city i is the j-th city to be visited
Adjancecy representation City j is listed in position i if the tour leads from city i to
city j(3 5 7 6 4 8 2 1) tour: 1-3-7-2-5-4-6-8
![Page 11: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/11.jpg)
The assignment problem
A set of n resources is available to carry out n tasks. If resource i is assigned to task j, it cost
units.
Find an assignment that minimizes
Solution: permutition of the numbers},...,1{ n
ijc},...,{ 1 n
n
ii ic
1
![Page 12: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/12.jpg)
SAT
The satisfiability problem consists on finding a truth assignment that satisfied a well-formed Boolean expression
Many applications: VLSI test and verification, consistency maintenance, fault diagnosis, etc
MAX-SAT: Find an assignment which satisfied the maximum number of clauses
![Page 13: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/13.jpg)
SAT
Data sets in conjunctive normal form (cnf) Example
Literals: Clauses:
Representation? Fitness function?
51,..., xx
351 )( xxx
...
)()( 12351 xxxxx
![Page 14: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/14.jpg)
The 0-1 knapsack problem
A set of n items is available to be packed into a knapsack with capacity C units. Item i has value vi and uses up ci units of capacity. Determine the subset of items which should be packed to maximize the total value without exceding the capacity
Representation? Fitness function?
![Page 15: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/15.jpg)
Heuristics
Faster than mathematical optimization (branch & bound, simplex, etc)
Well developed good solutions for some problems
Special heuristics: Greedy algorithms – systematic Hill-climbing (based on neighbourhood
search) – randomized
![Page 16: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/16.jpg)
Greedy algorithms
Step-by-step algorithms Sometimes works well for optimization problems A greedy algorithm works in phases. At each
phase: You take the best you can get right now, without
regard for future consequences You hope that by choosing a local optimum at each
step, you will end up at a global optimum
![Page 17: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/17.jpg)
Example: Counting money
Suppose you want to count out a certain amount of money, using the fewest possible bills and coins
A greedy algorithm would do this would be:At each step, take the largest possible bill or coin that does not overshoot Example: To make $6.39, you can choose:
a $5 bill a $1 bill, to make $6 a 25¢ coin, to make $6.25 A 10¢ coin, to make $6.35 four 1¢ coins, to make $6.39
For US money, the greedy algorithm always gives the optimum solution
![Page 18: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/18.jpg)
A failure of the greedy algorithm
In some (fictional) monetary system, “krons” come in 1 kron, 7 kron, and 10 kron coins
Using a greedy algorithm to count out 15 krons, you would get
A 10 kron piece Five 1 kron pieces, for a total of 15 krons This requires six coins
A better solution would be to use two 7 kron pieces and one 1 kron piece
This only requires three coins The greedy algorithm results in a solution, but not in an
optimal solution
![Page 19: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/19.jpg)
Practice
Develop a greedy algorithm for the knapsack problem. Groups of 2 persons
![Page 20: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/20.jpg)
Local search algorithms
Based on neighbourhood system Neighbourhood system:
being X the search space, we define the neighbourhood system N in X
Examples: TSP (2-opt), SAT, assignment and knap
)(: xNxN
![Page 21: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/21.jpg)
Local search algorithms
Basic principles: Keep only a single (complete) state in memory Generate only the neighbours of that state Keep one of the neighbours and discard others
Key features: No search paths Neither systematic nor incremental
Key advantages: Use very little memory (constant amount) Find solutions in search spaces too large for systematic
algorithms
![Page 22: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/22.jpg)
TSP – 2 opt
A
B
C
D
New distance = Old dist – dist(A-D) – dist(B-C) + dist(A-B) + dist (C-D)
![Page 23: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/23.jpg)
Neighbourhood search (Reeves93)
1. (Initialization)i. Select a starting solutionii. Current best and
2. (Choice and termination)i. Choice . If choice criteria cannot
be satisfied or if other termination criteria apply, then the method stops
3. (Update)i. Re-set , and if ,
perform step 1.ii. Return to Step 2
Xxnownowbest xx )( bestxfbest_cost
)( nownext xNx
nextnow xx best_cost)f(xnow
![Page 24: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/24.jpg)
Hill climbing
Diferent procedures depending on choice criteria and termination criteria
Hill climbing: only permit moves to neighbours that improve the current
2. (Choice and termination)i. Choose such that and terminate if no such can be found
)( nowxf
)( nownext xNx )()( nownext xcxc
nextx
![Page 25: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/25.jpg)
Hill-climbing: 8-Queens problem
Complete state formulation: All 8 queens on the board,one per column Neighbourhood: move one queen to a
different place in the same column Fitness function: number of pairs of queens
that are attacking each other
![Page 26: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/26.jpg)
8-Queens problem:fitness values of neighbourhood
![Page 27: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/27.jpg)
8-Queens problem:Local minimun
![Page 28: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/28.jpg)
Problematic landscapes
Local maximum: a peek that is higher than all its neighbours, but not a global maximum
Plateau: an area where the elevation is constant Local maximum Shoulder
Ridge: a long, narrow, almost plateau-like landscape
![Page 29: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/29.jpg)
Random-Restart Hill-Climbing
Method: Conduct a series of hill-climbing searches
from randomly generated initial states Stop when a goal is found
Analysis: Requires 1/p restarts where p is the
probability of success(1 success + 1/p failures)
![Page 30: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/30.jpg)
Hill-Climbing: Performance on the 8-Queen Problem
From randomly generated start state Success rate:
86% - gets stuck 14% - solves problem
Average cost: 4 steps to success 3 steps to get stuck
![Page 31: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/31.jpg)
Hill-Climbing with Sideways Moves
Sideways moves: moves at same fitness Must limit number of sideways moves! Performance on the 8-Queen problem:
Success rate: 6% - get stucks 94% - solves problem
Average cost: 21 steps to succeed 64 steps to get stuck
![Page 32: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/32.jpg)
Hill-climbing: Further variants
Stochastic hill-climbing: Choose at random from among uphill moves
First-choice hill-climbing: Generate neighbourhood in random order Move to first generated that represents an
uphill move
![Page 33: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/33.jpg)
Practice
Develop a hill-climbing algorithm for the knapsack problem. Groups of 2 persons
![Page 34: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/34.jpg)
Shape of State Space Landscape
Success of hill-climbing depends on shape of landscape
Shape of landscape depends on problem formulation and fitness function
Landscapes for realistic problems often look like a worst-case scenario
NP-hard problems typically have exponential number of local-maxima
Despite the above, hill-climbers tend to have good performance
![Page 35: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/35.jpg)
Simulated annealing
Failing on neighbourhood search Propensity to deliver solutions which are only local
optima Solutions depend on the initial solution
Reduce the chance of getting stuck in a local optimum by allowing moves to inferior solutions
Developed by Kirkpatrick ’83: Simulation of the cooling of material in a heat bath could be used to search the feasible solutions of an optimization problem
![Page 36: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/36.jpg)
Simulated annealing
If a move from one solution to another neighbouring but inferior solution results in a change in value , the move to is still accepted if
T (temperature) – control parameter – uniform random number
bestx
nowx 0fnowx
Re Tf
]1,0[R
![Page 37: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/37.jpg)
Simulated annealing: Intuition
Minimization problem; imagine a state space landscape on table
Let ping-pong ball from random point local minimum
Shake table ball tends to find different minimum
Shake hard at first (high temperature) but gradually reduce intensity (lower temperature)
![Page 38: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/38.jpg)
Simulated annealing: Algorithm
current = problem.initialSatefor t=1 to
T = schedule(t)if T=0 then return = a random neighbour of
if thenelse with probability
bestxnowx bestx
)()( nownext xfxff 0f nowbest xx
nowbest xx e Tf
![Page 39: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/39.jpg)
Simulated annealing: Simple example
Maximize
x coded as a 5-bit binary integer in [0,31]
maximum (01010) f=4100 With ‘greedy’ we can find 3 local maxima
10090060)( 23 xxxxf
![Page 40: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/40.jpg)
Simulated annealing: Simple example
T bit string f move? new string100 1 0 0 0 1 1 2287 112 N 1 0 0 1 190 3 1 0 1 1 1 1227 1172 N 1 0 0 1 181 5 1 0 0 1 0 2692 < 0 Y 1 0 0 1 0
72,9 2 1 1 0 1 0 516 2176 N 1 0 0 1 065,6 4 1 0 0 0 0 3236 < 0 Y 1 0 0 0 0
59 3 1 0 1 0 0 2100 1136 N 1 0 0 0 0
f
The temperature is not high enough to move out of thislocal optimum
![Page 41: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/41.jpg)
Simulated annealing: Simple example
T bit string f move? new string500 1 0 0 0 1 1 2287 112 Y 0 0 0 1 1450 3 0 0 1 1 1 3803 < 0 Y 0 0 1 1 1405 5 0 0 1 1 0 3556 247 Y 0 0 1 1 0
364,5 2 0 1 1 1 0 3684 < 0 Y 0 1 1 1 0328 4 0 1 1 0 0 3988 < 0 Y 0 1 1 0 0
295,2 3 0 1 0 0 0 3972 16 Y 0 1 0 0 0265,7 4 0 1 0 1 0 4100 < 0 Y 0 1 0 1 0239,1 5 0 1 0 1 1 4071 29 Y 0 1 0 1 1215,2 1 1 1 0 1 1 343 3728 N 0 1 0 1 1
Optimum found!!!
f
![Page 42: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/42.jpg)
Simulated annealing: Generic decisions
Initial temperature
Should be ‘suitable high’. Most of the initial moves must be accepted (> 60%)
Cooling schedule
Temperature is reduced after every move
Two methods:
TT T
TT
1
close to 1 close to 0
![Page 43: Heuristic Optimization Athens 2004 Department of Architecture and Technology Universidad Politécnica de Madrid Víctor Robles vrobles@fi.upm.es](https://reader036.vdocuments.site/reader036/viewer/2022062421/56649d385503460f94a11228/html5/thumbnails/43.jpg)
Simulated annealing: Generic decisions
Number of iterations
Other factors: Reannealing Restricted neighbourhoods Order of searching
log
loglog 0TTN
fit
f
fit
TT
TTN
0
0