Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Math 2 Shortest Paths Using Matrix

Similar presentations


Presentation on theme: "Discrete Math 2 Shortest Paths Using Matrix"— Presentation transcript:

1 Discrete Math 2 Shortest Paths Using Matrix
2001 Discrete Math 2 Shortest Paths Using Matrix CIS112 February 12, 2007 Daniel L. Silver

2 Overview Previously: In weighted graph . .
Shortest path from #7 to #12 Search matrix method Now: Same problem Find shortest path from #7 to all others 2007 Kutztown University

3 Strategy Proceed with matrix as before Do :: prune duplicate nodes
Do not :: mark dead ends 2007 Kutztown University

4 Matrix for Weighted Graph
vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 17 16 19 15 24 20 14 21 25 22 2007 Kutztown University

5 Step #0 Same as before . . . Create a search matrix
Layout same as weighted graph matrix Entries will hold path information Vertices along path Total cost of path Path info built up step by step 2007 Kutztown University

6 Search Matrix vtx 1 2 3 4 5 6 7 8 9 10 11 12 2007 Kutztown University

7 Step #1 Enter information for first path segment
Initial entry goes in row #7 . . Since #7 is starting vertex I.e., expand #7 2007 Kutztown University

8 Search Matrix – Step #1 vtx 1 2 3 4 5 6 7 8 9 10 11 12 15 25 2007
Kutztown University

9 Step #2 Expand node #3 2007 Kutztown University

10 Search Matrix – Step #2 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25
2007 Kutztown University

11 Step #3 Expand node #10 2007 Kutztown University

12 Search Matrix – Step #3 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 2007 Kutztown University

13 Search Matrix – Step #3b vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 2007 Kutztown University

14 Step #4 Expand node #11 2007 Kutztown University

15 Search Matrix – Step #4 vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 44 43 26 2007 Kutztown University

16 Search Matrix – Step #4b vtx 1 2 3 4 5 6 7 8 9 10 11 12 23 34 15 25 24
21 44 43 26 2007 Kutztown University

17 Comment Want paths to more than #12 So no nodes are dead ends
Keep expanding Q: How long? 2007 Kutztown University

18 Step #5 Expand node #1 2007 Kutztown University

19 Search Matrix – Step #5 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 23 34 15
25 24 21 44 43 26 2007 Kutztown University

20 Step #6 Expand node #8 2007 Kutztown University

21 Search Matrix – Step #6 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 23 34 15
25 35 48 47 24 21 44 43 26 2007 Kutztown University

22 Step #7 Expand node #12 2007 Kutztown University

23 Search Matrix – Step #7 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 23 34 15
25 35 48 47 24 21 44 43 26 2007 Kutztown University

24 Step #8 Expand node #4 2007 Kutztown University

25 Search Matrix – Step #8 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 23 34 47
39 15 25 35 48 24 21 44 43 26 2007 Kutztown University

26 Step #9 Expand node #9 2007 Kutztown University

27 Search Matrix – Step #9 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 23 34 47
39 15 25 35 48 63 57 24 21 44 43 26 2007 Kutztown University

28 Step #10 Expand node #2 2007 Kutztown University

29 Search Matrix – Step #10 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 63 62 23
34 47 39 15 25 35 48 57 24 21 44 43 26 2007 Kutztown University

30 Step #11 Expand node #6 2007 Kutztown University

31 Search Matrix – Step #11 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 63 62 23
34 47 39 61 15 25 35 48 57 24 21 44 43 26 2007 Kutztown University

32 Step #12 Expand node #5 2007 Kutztown University

33 Search Matrix – Step #12 vtx 1 2 3 4 5 6 7 8 9 10 11 12 46 28 63 62 23
34 47 39 65 68 61 15 25 35 48 57 24 21 44 43 26 2007 Kutztown University

34 We Are Finished All open nodes have either . .
been expanded {yellow} or marked for deletion {blue} All vertices have been tried rows have 1+ entries All vertices (except 7) reached columns have 1+ entries How do we get information we seek? 2007 Kutztown University

35 Path Costs . . Given by open (yellow) column entry 7  1 :: 23
7  2 :: 46 7  3 :: 15 7  4 :: 28 7  5 :: 48 7  6 :: 47 7  8 :: 24 7  9 :: 43 7  10 :: 15 7  11 :: 21 7  12 :: 26 2007 Kutztown University

36 Paths from #7 Start at row 7 Follow open values
Record values Continue to rows of open columns 2007 Kutztown University

37 Shortest Paths from 7 7  3 :: 15 7  10 :: 15 7  3  1 :: 23
7  10  8:: 24 7  10  11 :: 21 7  3  1  2 :: 46 7  3  1  4 :: 28 2007 Kutztown University

38 Shortest Paths from 7 7  10  8  5 :: 48 7  10  11  9 :: 43
7  10  11  12 :: 26 7  10  11  12  6 :: 47 2007 Kutztown University

39 Final Comments We see how the 1-many search tree can be implemented as a matrix What about finding the least cost path from every vertex to all others? 2007 Kutztown University


Download ppt "Discrete Math 2 Shortest Paths Using Matrix"

Similar presentations


Ads by Google