Shortest Path.

Slides:



Advertisements
Similar presentations
Decision Maths Dijkstra’s Algorithm.
Advertisements

Networks Prim’s Algorithm
Discrete Math for Computer Science. Mathematical Model Real-world Problem Computerized Solution Abstract Model Transformed Model picture of the real worldpicture.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
MINIMAL CONNECTOR PROBLEMS Problem: A cable TV company is installing a system of cables to connect all the towns in a region. The numbers in the network.
Management Science 461 Lecture 2b – Shortest Paths September 16, 2008.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CSC 213 Lecture 23: Shortest Path Algorithms. Weighted Graphs Each edge in weighted graph has numerical weight Weights can be distances, building costs,
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
The Travelling Salesman Algorithm A Salesman has to visit lots of different stores and return to the starting base On a graph this means visiting every.
The Shortest Path Problem
Quickest Route B St Li C La time matrix (minutes) Liskeard Launceston Callington St Austell Bodmin 32 What is the quickest route from.
1 1 Slide © 2000 South-Western College Publishing/ITP Slides Prepared by JOHN LOUCKS.
NetworkModel-1 Network Optimization Models. NetworkModel-2 Network Terminology A network consists of a set of nodes and arcs. The arcs may have some flow.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”
Shortest Path. Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path.
SPANNING TREES Lecture 21 CS2110 – Spring
COSC 2007 Data Structures II Chapter 14 Graphs III.
Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we can find a path that goes over all.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
The travelling Salesman problem involves visiting every town (node) on a graph and returning to the start in the shortest distance. The slides will show.
Minimum spanning trees Aims: To know the terms: tree, spanning tree, minimum spanning tree. To understand that a minimum spanning tree connects a network.
Advance Computer Networks Lecture#08 Instructor: Engr. Muhammad Mateen Yaqoob.
1 1 © 2003 Thomson  /South-Western Slide Slides Prepared by JOHN S. LOUCKS St. Edward’s University.
TSP – Upper Bounds and Lower Bounds Initial problem : Upper Bound A salesman based in Stockton needs to visit shops based in Darlington, Billingham, Middlesbrough,
Liskeard Launceston Callington St Austell Bodmin Starter Find the quickest route from St Austell to Launceston.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Chapter 14 Section 3 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Graphs – Part III CS 367 – Introduction to Data Structures.
Networks Teacher’s guide. Networks 2 Problem 1 – the Link The EMTV Company needs to install a new cable system that links the six major towns in its.
SHORTEST ROUTE PROBLEM A Networking Model Report for DPA 702 QUANTITATIVE METHODS OF RESEARCH By: ALONA M. SALVA Cebu Technological University.
1 1 Slide © 2005 Thomson/South-Western Chapter 9 Network Models n Shortest-Route Problem n Minimal Spanning Tree Problem n Maximal Flow Problem.
Minimum Spanning Trees
St. Edward’s University
Shortest Path Problems
Greedy Technique.
Shortest Path from G to C Using Dijkstra’s Algorithm
Network Flow Problems – Shortest Path Problem
Graph Algorithm.
Party-by-Night Problem
Minimum Spanning Trees
Decision Maths Dijkstra’s Algorithm.
15.082J & 6.855J & ESD.78J Visualizations
Shortest Path.
Minimum spanning trees
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Minimum spanning trees
Route Inspection Which of these can be drawn without taking your pencil off the paper and without going over the same line twice? If we introduce a vertex.
Minimum spanning trees
離散數學 DISCRETE and COMBINATORIAL MATHEMATICS
Shortest Path.
CSC 380: Design and Analysis of Algorithms
and 6.855J Dijkstra’s Algorithm
Visualizations Dijkstra’s Algorithm
Networks Prim’s Algorithm
Implementation of Dijkstra’s Algorithm
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Lecture 12 Shortest Path.
Prim’s algorithm for minimum spanning trees
15.082J & 6.855J & ESD.78J Visualizations
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Shortest Path

What is the shortest route that visits every desk?

What is the shortest route that visits every desk?

What is the shortest route that visits every desk? Is there an optimal solution to reduce the amount of miles I travel in a day?

Minimum Connector Algorithms Kruskal’s algorithm Select the shortest edge in a network Select the next shortest edge which does not create a cycle Repeat step 2 until all vertices have been connected Prim’s algorithm Select any vertex Select the shortest edge connected to that vertex Select the shortest edge connected to any vertex already connected Repeat step 3 until all vertices have been connected

Jan 2013 – Q1

Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path from A to G 4 3 7 1 2 5 B F D A G E C

Dijkstra’s Algorithm Label the start vertex with permanent label 0 and order label 1 Assign temporary labels to all the vertices that can be reached directly from the start Select the vertex with the smallest temporary label and make its label permanent. Add the correct order label. Put temporary labels on each vertex that can be reached directly from the vertex you have just made permanent. The temporary label must be equal to the sum of the permanent label and the direct distance from it. If there is an existing temporary label at a vertex, it should be replaced only if the new sum is smaller. Repeat until the finishing vertex has a permanent label. To find the shortest paths(s), trace back from the end vertex to the start vertex. Write the route forwards and state the length.

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C Order in which vertices are labelled. Distance from A to vertex Working Dijkstra’s Algorithm A C D B F E G 4 3 7 1 2 5 1 0 Label vertex A 1 as it is the first vertex labelled

Dijkstra’s Algorithm We update each vertex adjacent to A with a ‘working value’ for its distance from A. A C D B F E G 4 3 7 1 2 5 4 1 0 7 3

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C 4 1 0 7 1 0 7 Vertex C is closest to A so we give it a permanent label 3. C is the 2nd vertex to be permanently labelled. 2 3 3

Dijkstra’s Algorithm We update each vertex adjacent to C with a ‘working value’ for its total distance from A, by adding its distance from C to C’s permanent label of 3. A C D B F E G 4 3 7 1 2 5 4 6 < 7 so replace the t-label here 1 0 7 6 2 3 8 3

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C The vertex with the smallest temporary label is B, so make this label permanent. B is the 3rd vertex to be permanently labelled. A C D B F E G 4 3 7 1 2 5 3 4 4 1 0 7 6 2 3 8 3

Dijkstra’s Algorithm We update each vertex adjacent to B with a ‘working value’ for its total distance from A, by adding its distance from B to B’s permanent label of 4. A C D B F E G 4 3 7 1 2 5 3 4 4 5 < 6 so replace the t-label here 8 1 0 7 6 5 2 3 8 3

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C The vertex with the smallest temporary label is D, so make this label permanent. D is the 4th vertex to be permanently labelled. A C D B F E G 4 3 7 1 2 5 3 4 4 8 4 5 1 0 7 6 5 2 3 8 3

Dijkstra’s Algorithm We update each vertex adjacent to D with a ‘working value’ for its total distance from A, by adding its distance from D to D’s permanent label of 5. A C D B F E G 4 3 7 1 2 5 3 4 4 8 7 7 < 8 so replace the t-label here 4 5 1 0 7 6 5 7 < 8 so replace the t-label here 12 2 3 8 7 3

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C 3 4 4 8 7 4 5 1 0 7 6 5 3 4 4 8 7 4 5 1 0 7 6 5 12 5 7 2 3 The vertices with the smallest temporary labels are E and F, so choose one and make the label permanent. E is chosen - the 5th vertex to be permanently labelled. 8 7 3

Dijkstra’s Algorithm We update each vertex adjacent to E with a ‘working value’ for its total distance from A, by adding its distance from E to E’s permanent label of 7. A C D B F E G 4 3 7 1 2 5 3 4 4 8 7 4 5 1 0 7 6 5 12 9 5 7 2 3 8 7 3 9 < 12 so replace the t-label here

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C The vertex with the smallest temporary label is F, so make this label permanent.F is the 6th vertex to be permanently labelled. A C D B F E G 4 3 7 1 2 5 3 4 4 6 7 8 7 4 5 1 0 7 6 5 12 9 5 7 2 3 8 7 3

Dijkstra’s Algorithm We update each vertex adjacent to F with a ‘working value’ for its total distance from A, by adding its distance from F to F’s permanent label of 7. A C D B F E G 4 3 7 1 2 5 3 4 4 6 7 8 7 4 5 1 0 7 6 5 12 9 5 7 2 3 8 7 11 > 9 so do not replace the t-label here 3

Dijkstra’s Algorithm 4 1 2 7 3 5 B F D A G E C 3 4 4 6 7 8 7 4 5 1 0 7 3 4 4 6 7 8 7 4 5 1 0 7 6 5 7 9 12 9 5 7 2 3 8 7 3 G is the final vertex to be permanently labelled.

The shortest path is ABDEG, with length 9. Dijkstra’s Algorithm To find the shortest path from A to G, start from G and work backwards, choosing arcs for which the difference between the permanent labels is equal to the arc length. A C D B F E G 4 3 7 1 2 5 3 4 4 6 7 8 7 4 5 1 0 7 6 5 7 9 12 9 5 7 2 3 8 7 3 The shortest path is ABDEG, with length 9.

Jan 2013 – Q1