General Purpose Methods For Combinatorial Optimization
General Purpose Methods For Combinatorial Optimization
10/7/2010
31
-41
59
26
-53
58
97
-93
-23
84
= 187
10/7/2010
10/7/2010
10/7/2010
MCS: Algorithm 2
31 -41 59 26 -53 58 97 -93 -23 84
MaxSoFar := 0 for L := 1 to N do sum := 0 for U := L to N do sum := sum + x[U] sum of x[ L ... U ] MaxSoFar := max (MaxSoFar, sum) Faster: one nested for-loop less
10/7/2010
Analysis of Algorithm 2
MaxSoFar := 0 for L := 1 to N do sum := 0 for U := L to N do sum := sum + x[U] sum of x[ L ... U ] MaxSoFar := max (MaxSoFar, sum) Constant time per inner loop iteration Count number of times inner loop is executed
L =1U = L
O(1) = O(N2)
10/7/2010
10/7/2010
10/7/2010
Challenge: Algorithm 3
31
-41
59
26
-53
58
97
-93
-23
84
= 187
10/7/2010
Empty vector gives maximum sum == 0 Scan the array just once Keep track of max sum in first I elements (-> MaxSoFar) And of maximum sum ending in position I (-> MaxEndingHere) MaxSoFar := 0 MaxEndingHere := 0 for I := 1 to N do MaxEndingHere := max (0, MaxEndingHere + x[I]) MaxSoFar := max (MaxSoFar, MaxEndingHere)
ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 6
10/7/2010
10/7/2010
Comparison
1 3 3.4 N 10 3 10 4 10 10 6 10
5 2
10/7/2010
Stirling:
ln n! n log n n
Large n:
n! e n log n n = e log n = n n = o e n
( )
8
10/7/2010
10/7/2010
10/7/2010
10/7/2010
Simulated Annealing
important much applied method for various combinatorial optimalization problems. Idea (thermo dynamics, static mechanics) Growing of crystals by means of Annealing 1. start off with high temperature 2. cool down slowly Theoretical Model matter strives for state with lowest energy movement of atoms small random displacements E < 0 accept displacement E > 0 accept with probability exp(-E/kBT)
10/7/2010
10
10/7/2010
10/7/2010
Algorithm T := T0 X := start configuration while (not satisfied stop criterium) { for (a few times) { Xnew := new configuration if (accept (cost (Xnew) cost (X), T)) X := Xnew } T := update (T) }
accept (cost,T) { if (cost < 0) return TRUE else { if (exp(- cost/cT) > random (0,1)) return TRUE else return FALSE } }
10/7/2010
11
10/7/2010
12
10/7/2010
10/7/2010
Shortest Path
Given: Weighted, directed graph G=(V,E) 1. Single-source shortest path Find shortest path form source vertex sV to each v V 2. Single-destination shortest path equivalent by reducing (reverse direction of edges) 3. Single-pair shortest path route-planning no known algorithm being asymptotically better then 1 4. All-pairs shortest path
10/7/2010
13
1. Find from v1 the shortest path to its neighbors 2. Say u is the closest to v1 3. See if any of the routes from v1 to the neighbors of u becomes shorter if passing through u 4. Continue with step 2, until reaching v2 (target)
10/7/2010
14
10/7/2010
10/7/2010
v1 v4 v5 v6 v2
10/7/2010
15
1. Find from v1 the shortest path to its neighbors 2. Say u is the closest to v1 3. See if any of the routes from v1 to the neighbors of u becomes shorter if passing through u 4. Continue with step 2, until reaching v2 (target)
This is vertex u. Shortest distance to these vertices has just become known
ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 16
10/7/2010
10/7/2010
while end not in T and len (V) > 0: if animate: print "T", T, "\n", "D", D u = closest (D, V) # find closest vertex to start, among those in V T.add (u) V.remove (u) for v in G[u]: www.python.org if D [v] > G[u][v] + D[u]: D [v] = G[u][v] + D[u] return D
ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 17
Optimization
Public Transport: It brings you from a place where you are not, to a place where you dont want to be, at a time that you do not prefer EDA: It provides a solution to a problem that you dont want to solve Why? Because most EDA problems are just too hard to be solved exactly Many optimization problems are NP-hard Therefore, problems are usually replaced by simpler problems that are solved instead.
10/7/2010
18
10/7/2010
10/7/2010
Standard problem Standard Algorithm Mathematics / computer science discipline of science / engineering
Sub-optimal chip
10/7/2010
19
10/7/2010
20
10/7/2010
10
10/7/2010
Discrete Optimization
1 6 5 4 2 3
Optimization algorithms typically go through a sequence of steps Set of choices at each step (Result of) each step is called a configuration Above we see 6 configurations with different cost, 4 choices in config of cost 6.
10/7/2010
21
4 given optimization problem instance of algorithm for set of all possible (legal) configurations (solutions) of p cost of configuration xk a directed graph, the configuration graph the transformation (by the algorithm) of configuration xi in xj set of all steps that algorithm A considers
10/7/2010 22
10/7/2010
11
10/7/2010
2 6
What is the global minimum? Is this example convex? If not: What is/are local minima? Can you change the graph to become convex?
10/7/2010
24
10/7/2010
12
10/7/2010
A 3 5
9 5 4
B 5 3
9 5 4
B 5
F E 1 D
f1 f2 f3 f4 f5 f6 f7 E F A 27 D F E A 31 D E A 33 C
8 C E 2
5 F 7 1 D
B F D E E x D C x A 27 A 20 A 27 B F C F B
2
A E
F F B D D x C B A 31 C D E A 20 B x C D E x C B x D E x E D C B A 27
F E D x
C D E C x
F B C x A 33 C B
B C D x B x
10/7/2010
25
9 5 4
B 5 8 C 2 E 3
5 F 1 D
F 5+15
22+9 21+6
23+8
10/7/2010
13
10/7/2010
Lines (hyperplanes) of constant z Optimum is in cornerpoint LP solver searches for optimum corner point
27
x1
10/7/2010
LP Solvers
Ellipsoid algorithm runs in polynomial time In practice, Simplex algorithm is often faster, but it has exponential worst-case time complexity Simplex algorithm is clever way of enumerating boundary points, it steps from point to point along the outside of the feasible region Based on principles from linear algebra Many on-line sources (e.g. see wikipedia -> linear programming) Also see the book Numerical Recipes in {C/C++/Fortran} Press et al. On-line C version of the book (pdf) via www.nr.com See lp_solve originally by Michel Berkelaar Now at TUD/EWI/CAS
10/7/2010
28
10/7/2010
14
10/7/2010
10/7/2010
29
Genetic Algorithms
First parent: ( f(k)) Second parent: (g(k)) 01011 001 10000 110 First child: 0 1 0 1 1 1 1 0 (f(k 1)) Second child: 1 0 0 0 0 0 0 1 ( g(k 1))
Inspired on biology: survival of the fittest Work with a population P(k) F, set of feasible solutions Each f P(k) is encoded as a chromosome, e.g. a bit-string Cross-over operations between members of P(k) to derive P(k+1) Prefer parents with lower cost for mating Many variations possible (mutation, cloning, )
10/7/2010
30
10/7/2010
15
10/7/2010
Dynamic Programming
Fibonacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, Recursive algorithm is a lot of work: e.g. fib(2), fib(3) computed more then once 5 4 3 2 11 0 1 1 0 2 3 2 1 0
function fib(n) Each number starting from if n 3rd = 0 is orsum n = of 1 return previous n two Write algorithm else return fib(n 1) + fib(n 2) var f := map(0 0, 1 1) function fib(n) if n not in keys(f) f[n] := fib(n 1) + fib(n 2) return f[n]
ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs
Recursive version Time and space O(n) Runs into max recursion depth problems Iterative (bottom-up) version Time O(n), space O(1) Runs easily for n = 100000
def dynfib2 (n): if n == 0 or n prevprev = 0 prev = 1 for i in range fib = prev prevprev = prev = fib return fib
== 1: return n
10/7/2010
32
10/7/2010
16
10/7/2010
Dynamic Programming
Elegant approach Two variants: bottom-up and top-down Several applications in EDA E.g. in channel routing, later lecture. E.g. technology mapping, Dirk-Jan Jongeneel, Optimized boolean equations Library of std cells Timing constraints Gate netlist
[Jongeneel and Otten, Integration, 2000] ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 33
[Jongeneel and Otten, Integration, 2000] ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 34
10/7/2010
17
10/7/2010
[Jongeneel and Otten, Integration, 2000] ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 36
10/7/2010
18
10/7/2010
[Jongeneel and Otten, Integration, 2000] ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 37
Summary
Graph algorithms and optimization very common in EDA Discrete vs continuous optimization
Chip optimization problem Transform problem into similar, known, solvable problem in mathematics world
Standard problem Standard Algorithm Mathematics / computer science discipline of science / engineering
Many different algorithms, with different properties Finding right one depends on transformation from and back into real world
ET 4255 - Electronic Design Automation 10/11 Nick van der Meijs 10/7/2010 38
10/7/2010
19
10/7/2010
Summary
Many different optimization algorithmic techniques
Backtracking, branch and bound ( 5.2) Dynamic programming ( 5.3) Linear programming (LP), integer LP (ILP) ( 5.4) Local Search ( 5.5) Simulated Annealing ( 5.6) Tabu search ( 5.7) Genetic algorithms ( 5.8) Boolean Satisfiability (SAT) Neural networks Simulated evolution Matching, max flow, shortest path, Non-linear programming: Lagrange relaxation, LevenbergMarquardt,
Many applications of optimization in EDA (e.g. techn. mapping) Asymptotic complexity important for effectivity of algorithm Implementation can also count (e.g. recursive vs iterative implementation)
10/7/2010
39
10/7/2010
20