Design and Analysis of Algorithms - PowerPoint PPT Presentation

About This Presentation
Title:

Design and Analysis of Algorithms

Description:

Shortest path in trellis graph; Optimal allocation of constrained resource; ... Trellis graph. Distance (weight) from point i1 at stage (j 1) to point i2. at stage j: ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 42
Provided by: Jus6
Category:

less

Transcript and Presenter's Notes

Title: Design and Analysis of Algorithms


1
DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF
JOENSUU JOENSUU, FINLAND
  • Design and Analysis of Algorithms
  • Lecture
  • Dynamic programming
  • Alexander Kolesnikov
  • 17.10.205

2
List of sample problems
  • Shortest path in trellis graph
  • Optimal allocation of constrained resource
  • Optimal sequence partition (k-link shortest
    path).
  • to be continued ...

3
Shortest path in trellis graph
4
Stagecoach problem

A traveler wishes to minimize the length of a
journey from town A to J.
5
Greedy algorithm

The length of the route A-B-F-I-J 243413.
Can we find shorter route?
6
Exhaustive search try all

Route A-D-F-I-J 313411 The total number
of routes to be tested 3?3?2?118 Can
we avoid exhaustive search?
7
Shortest path construction 1st stage (B)

?
8
Shortest path construction 1st stage

S(A,B)2 S(A,C)4 S(A,D)3
9
Shortest path construction 2nd stage (E)

1. (A..B)-E 279 2. (A..C)-E 437 3.
(A..D)-E 347 ----------------------
(A..C)-E 7
?
10
Shortest path construction 2nd stage (E)

1. (A..B)-E 279 2. (A..C)-E 437 ) 3.
(A..D)-E 347 ----------------------
(A..C)-E 7
11
Shortest path construction 2nd stage (F)

1. (A..B)-F 246 2. (A..C)-F 426 3.
(A..D)-F 314 ) ----------------------
(A..C)-F 4
?
12
Shortest path construction 2nd stage (F)

1. (A..B)-F 246 2. (A..C)-F 426 3.
(A..D)-F 314 ) ----------------------
(A..D)-F 4
13
Shortest path construction 2nd stage (G)

1. (A..B)-G 268 ) 2. (A..C)-G 4610 3.
(A..D)-G 358 ----------------------
(A..B)-G 8
?
14
Shortest path construction 2nd stage (G)

1. (A..B)-G 268 ) 2. (A..C)-G 4610 3.
(A..D)-G 358 ----------------------
(A..B)-G 8
15
Shortest path construction 3rd stage (H)

1. (A..E)-H 718 ) 2. (A..F)-H 4610 3.
(A..G)-H 538 ----------------------
(A..E)-H 5
16
Shortest path construction 3rd stage (H)

1. (A..E)-H 718 ) 2. (A..F)-H 4610 3.
(A..G)-H 538 ----------------------
(A..E)-H 5
17
Shortest path construction 3rd stage (I)

1. (A..E)-I 7411 2. (A..F)-I 437 ) 3.
(A..G)-I 538 ----------------------
(A..F)-I 7
18
Shortest path construction 3rd stage (I)

1. (A..E)-I 7411 2. (A..F)-I 437 ) 3.
(A..G)-I 538 ----------------------
(A..F)-I 7
19
Shortest path construction 4th stage (J)

1. (A..H)-J 8311 ) 2. (A..I) -J
7411 ---------------------- (A..H)-J 11
20
Shortest path construction 4th stage (J)

1. (A..H)-J 8311 ) 2. (A..I) -J
7411 ---------------------- (A..H)-J 11
21
Backtrack the shortest path

7
2
8
11
4
4
0
7
3
8
22
The shortest path

7
2
8
11
4
4
0
7
3
8
Route A-C-E-H-J 431311
23
Trellis graph
1 2 3 4
K-1 K
24
Trellis graph
  • Distance (weight) from point i1 at stage (j?1)
    to point i2
  • at stage j
  • The total value of cost function

25
Principle of optimality of Bellman
An optimal path has the property that whatever
the initial conditions and control variables
(choices) over some initial period, the control
(or decision variables) chosen over the remaining
period must be optimal for the remaining problem,
with the state resulting from the early decisions
taken to be the initial condition.
26
Dynamic programming
  • Cost function
  • Recursive eqution
  • Initialization

27
Complexity
  • Exhaustive search O(nK)
  • Dynamic programming algorithm O(Kn2)
  • where K is the number of stages,
  • n is the number of points in a stage

28
Optimal allocation of constrained resource
29
Problem formulation
  • N units of a resource
  • This resource must be distributed among K
    activities
  • Functions fk(x) - profit for allocated resource
  • Allocate N units of resource to K activities
    with given
  • return functions so that the total profit is
    maximal

subject to
30
Dynamic programming formulation

Optimal value function
Recursive equation
Initialization
31
Allocate 3 mln euros into four projects
Profit fk(x), K3, N3.
32
Trellis graph
33
Solution
)
1 2 f1(2)8 2 1 f2(1)5 3 0
f3(0)0 4 0 f4(0)0 ----------------------
N3 G4(3)13
34
Search in the state space
GK(N)
K
Gk(n)
fk(n-j)
k
k-1

Gk-1(j)
1
0
j
N
0
n
Start state
Gk(n) maxGk(0) fk(n),
Gk(1) fk(n-1), . . .
Gk(j-1) fk(j), . . .
Gk(n) fk(0)
Ak(n)jopt
35
Optimal partition of data sequence
36
Problem formulation
  • Given a sequence of data Xx1, x2, ,xN
  • Do partition of the sequence X into to K groups
    with
  • given cost functions f(xi,xj) so that the total
    value of
  • the cost function is minimal

37
Partition into groups Example
  • Data x 0 ?? lt x1 lt... lt xj lt ... lt xN
  • Partition indices i0 0 lt i1 lt... lt ij lt ... lt
    iM N.
  • Groups

1
2
3
(
(
(
















...
(x0??) x1 x2 x3 x4
x5 x6 x7x8 x9 x10 x11 x12 x13
x14 xN
(i00) i14
i210
iK N15
K3
38
Problem formulation
Cost function
Recursive equation
Initialization
39
Search in the state space ?
GK(N)
K
b
State space ?
Gk (n)
f(j,n)
k
k-1

Gk-1(j)
0
j
N
1
n
Start state
Gk(n) minGk(k) f(k, n,
Gk(k) f(k1,n, . . .
Gk(j-1) f(j, n), . .
. Gk(n-1) f(n, n
Ak(n)jopt
40
Scheme of the DP algorithm
  • // Initialization
  • FOR n 1 TO N DO G1(n) f(1,n
  • // Minimum search
  • FOR k 2 TO K DO
  • FOR n k TO N DO
  • dmin ? ?
  • FOR j k-1 TO n-1 DO
  • c ? Gk-1(j) f(j,n
  • IF(c lt cmin)
  • cmin ? c
  • jmin ? j
  • ENDIF
  • ENDFOR
  • Gk (n) ? dmin
  • Ak (n) ? jmin
  • ENDFOR
  • ENDFOR

Complexity O(KN2)
41
Backtrack in the state space ?
AK(N)
K
b
State space ?
0
N
1
n
j
Start state
S(M1) N FOR m K1 TO 2 DO S(m?1)
A(S(m), m)) P GK(N)
N22, K8 S22,18,14,12,9,6,4,3,1 (x0,x3,
(x3,x4, (x4,x6, (x6,x9, (x9,x12, (x12,x14,
(x14,x18, (x18,x22
Write a Comment
User Comments (0)
About PowerShow.com