L3 Network Algorithms

Similar documents
L1-Spatial Concepts L1 - Spatial Concepts

CSS 343 Data Structures, Algorithms, and Discrete Math II. Graphs II. Yusuf Pisan

Design and Analysis of Algorithms

Chapter 9 Graph Algorithms

Chapter 9 Graph Algorithms

SPANNING TREES. Lecture 21 CS2110 Spring 2016

CMSC 451: Lecture 22 Approximation Algorithms: Vertex Cover and TSP Tuesday, Dec 5, 2017

Graphs Introduction and Depth first algorithm

ECE 242 HOMEWORK 5. In the figure below, one can go from node B to A but not from A to B.

2 Approximation Algorithms for Metric TSP

10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees

Spanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018

Chapter 9 Graph Algorithms

Spanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017

(Refer Slide Time: 01:00)

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

Algorithm Design (8) Graph Algorithms 1/2

Constrained Minimum Spanning Tree Algorithms

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Class Overview. Introduction to Artificial Intelligence COMP 3501 / COMP Lecture 2. Problem Solving Agents. Problem Solving Agents: Assumptions

val(y, I) α (9.0.2) α (9.0.3)

1 Variations of the Traveling Salesman Problem

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

PBW 654 Applied Statistics - I Urban Operations Research. Unit 3. Network Modelling

Chapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1

Traveling Salesperson Problem (TSP)

Spanning Trees 4/19/17. Prelim 2, assignments. Undirected trees

Module 6 NP-Complete Problems and Heuristics

Spanning Trees. Lecture 22 CS2110 Spring 2017

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

22 Elementary Graph Algorithms. There are two standard ways to represent a

Module 6 NP-Complete Problems and Heuristics

Analysis of Algorithms

Module 6 NP-Complete Problems and Heuristics

Outline. Graphs. Divide and Conquer.

1 The Traveling Salesman Problem

Precept 4: Traveling Salesman Problem, Hierarchical Clustering. Qian Zhu 2/23/2011

1 The Traveling Salesman Problem

Graphs. What is a Graph? Computer Science S-111 Harvard University David G. Sullivan, Ph.D.


We have already seen the transportation problem and the assignment problem. Let us take the transportation problem, first.

Module 6 P, NP, NP-Complete Problems and Approximation Algorithms

22 Elementary Graph Algorithms. There are two standard ways to represent a

Questions... How does one show the first problem is NP-complete? What goes on in a reduction? How hard are NP-complete problems?

Theorem 2.9: nearest addition algorithm

Using a Divide and Conquer Method for Routing in a PC Vehicle Routing Application. Abstract

The Algorithm Design Manual

Construction of Minimum-Weight Spanners Mikkel Sigurd Martin Zachariasen

Algorithm Design Techniques. Hwansoo Han

COMP 355 Advanced Algorithms Approximation Algorithms: VC and TSP Chapter 11 (KT) Section (CLRS)

ME/CS 132: Advanced Robotics: Navigation and Vision

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Computational Geometry

Understand graph terminology Implement graphs using

UNIT Name the different ways of representing a graph? a.adjacencymatrix b. Adjacency list

Minimum Spanning Trees COSC 594: Graph Algorithms Spring By Kevin Chiang and Parker Tooley

2. Optimization problems 6

Review for Midterm Exam

Reference Sheet for CO142.2 Discrete Mathematics II

tree follows. Game Trees

Graphs. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. What is a Graph? b d f h j

Class Overview. Introduction to Artificial Intelligence COMP 3501 / COMP Lecture 2: Search. Problem Solving Agents

CSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach

Lecture 8: The Traveling Salesman Problem

Weighted Graph Algorithms Presented by Jason Yuan

GRAPHS Lecture 19 CS2110 Spring 2013

L21: Putting it together: Tree Search (Ch. 6)!

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

Topic 10 Part 2 [474 marks]

Job Shop Scheduling Problem (JSSP) Genetic Algorithms Critical Block and DG distance Neighbourhood Search

- Logic and Algorithms - Graph Algorithms

ECE250: Algorithms and Data Structures Final Review Course

Review of Graph Theory. Gregory Provan

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

Computer Science and Software Engineering University of Wisconsin - Platteville. 3. Search (Part 1) CS 3030 Lecture Notes Yan Shi UW-Platteville

CS521 \ Notes for the Final Exam

TOTAL CREDIT UNITS L T P/ S SW/F W. Course Title: Analysis & Design of Algorithm. Course Level: UG Course Code: CSE303 Credit Units: 5

Chapter S:I. I. Introduction. Examples for Search Problems Search Problem Abstraction

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Introduction to Optimization

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

L20: Putting it together: Tree Search (Ch. 6)!

Module 11: Additional Topics Graph Theory and Applications

L.J. Institute of Engineering & Technology Semester: VIII (2016)

Introduction to Approximation Algorithms

Graphs & Digraphs Tuesday, November 06, 2007

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

( ) 1 B. 1. Suppose f x

CAD Algorithms. Categorizing Algorithms

From Routing to Traffic Engineering

1 Minimum Spanning Trees (MST) b 2 3 a. 10 e h. j m

Graphs. Computer Science E-22 Harvard Extension School David G. Sullivan, Ph.D. What is a Graph? b d f h j

Minimum-weight tree shortcutting for Metric TSP

r=1 The Binomial Theorem. 4 MA095/98G Revision

Notes for Lecture 24

Graphs. The ultimate data structure. graphs 1

CS/COE

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

V 2 Clusters, Dijkstra, and Graph Layout"

Transcription:

L3 Network Algorithms NGEN06(TEK230) Algorithms in Geographical Information Systems by: Irene Rangel, updated Nov. 2015 by Abdulghani Hasan, Nov 2017 by Per-Ola Olsson

Content 1. General issues of networks 2. Shortest path - Dijkstra s algorithm 3. Other shortest path algorithms 4. Neighbourhood graphs and clustering 5. Traveling salesman problem.

Networks in GIS By using the distances between nodes in a network we can e.g. derive the shortest path, minimum number of nodes to pass and study accessibility.

What is a network A network or graph has 2 main constitutes: Nodes Edges Edges give distances between nodes. Distances can e.g. be: - Euclidean distances - Travelling time The network can e.g. be: - street network - airplane routes

What is a network A network or graph has 2 main constitutes: Nodes Edges Many analysis in networks only consider the nodes and the edges. Geometric location of the nodes is uninteresting

General issues of networks Networks can be stored in matrixes. Not a good data storage, especially for sparse networks, since it requires a lot of memory. But a matrix gives fast access to the nodes; O(1) to access a single node. For example fast to check if two nodes are connected. In most cases relational databases or lists and trees are more suitable storage structures. A B C D A 0 2 1 - B 2 0 3 2 C 1 3 0 4 D - 2 4 0 - implies that the nodes are not connected by any edge

Graphic Representation (easy for humans To read) Adjacency matrix representation Adjacency list representation Source: Worboys and Duckham 2004

Sparse network with several zeros stored Graphic representation Adjacency matrix representation Adjacency list representation Source: Worboys and Duckham 2004

a connected to: b, distance 20 and g, distance 15 Graphic representation Adjacency matrix representation Adjacency list representation Source: Worboys and Duckham 2004

Compare to matrix with one row h connected to c, distance 10 Graphic representation Adjacency matrix representation Adjacency list representation Source: Worboys and Duckham 2004

Shortest path The path between two nodes that is shorter than all other possible paths. In the shortest path problem we are not only restricted to Euclidean distances, but all the kind of distances are of interest.

Navigation Start point target point (distance c -> a is 28) Accessibility Many points target point Shortest path

Navigation Start point target point Shortest path Accessibility Many points target point (access e from four points - c,d,f,g)

Shortest path Accessibility to parks and nature in Gothenburg (Viktor Svanerud, master thesis)

Dijkstra s algorithm - one of the most well-known shortest path algorithms. Example of finding the shortest path between Node A and Node D. We need 2 matrixes: Adjacency matrix (static) State matrix (dynamic) A B C D A 0 2 1 - B 2 0 3 2 C 1 3 0 4 D - 2 4 0 We recognise the adjacency matrix from above

Dijkstra s algorithm Example of finding the shortest path between Node A and Node D. We need 2 matrixes: Adjacency matrix (static) State matrix (dynamic) Node Distance Path Visited A 0 - Yes B 2 A No C 1 A No D - No Distance a -> b is 2 The state matrix is dynamic and changes when a node is visited.

Dijkstra s algorithm State matrix: Node is the ID of the nodes. Distance keeps track of the current shortest distance from the starting node to this node. Path stores the previous node along the shortest path (found so far) to this node. Visited states if the node has been visited in the computations of the shortest path (explained later). Node Distance Path Visited A 0 - Yes B 2 A No C 1 A No D - No Start point is A

Dijkstra s algorithm First initialize the state matrix: The start node is marked as visited. All nodes that can be reached from the start are updated in the columns distance and path based on Adjacency matrix (row-wise). Distance values are set to the distances between the start node and the respective node (derived from the adjacency matrix). Path values are set to the start node (the starting node is the current shortest path to this particular node) If there is no path to a node, the distance is set to infinity and the path value is undefined. Node Distance Path Visited A 0 - Yes B 2 A No C 1 A No D - No The state matrix is initialized for start point A

Dijkstra s algorithm After the state matrix is initialized: 1. Find the node with the shortest distance that is not yet visited. Denote this as the current node. 2. Mark the current node as visited. 3. For each node (m) that is not yet visited do: If the node m and the current node has a common edge AND if the sum of the distance from the start node to the current node and the distance from the current node to the node m (found in the adjacency matrix) is shorter than the current distance from the starting node to node m (stored in the state matrix) DO State matrix update the distance and the path for node m. 4. Proceed from (1) again until the end node is visited.

1. Find the node with the shortest distance that is not yet visited. Denote this as the current node. 2. Mark the current node as visited. 3. For each node (m) that is not yet visited do: If the node m and the current node has a common edge AND if the sum of the distance from the start node to the current node and the distance from the current node to the node m (found in the adjacency matrix) is shorter than the current distance from the starting node to node m (stored in the state matrix) DO update the distance and the path for node m. 4. Proceed from (1) again until the end node is visited. Adjacency matrix A B C D Adjacency matrix: If nodes have a common edge and for distances between current node and node m A 0 2 1 - B 2 0 3 2 C 1 3 0 4 D - 2 4 0

Result of the shortest path algorithm Distance from start to end node (Distance) Path? Node Distance Path Visited A 0 - Yes B 2 A Yes C 1 A Yes D 4 B Yes

Result of the shortest path algorithm Distance from start to end node (Distance) Path from end backwards to start. Node Distance Path Visited A 0 - Yes B 2 A Yes C 1 A Yes D 4 B Yes

Does Dijkstra s algorithm always give a correct answer? Yes, no heuristics are involved BUT all types of distances are not allowed. L3-Network Algorithms Conditions for a metric: 1. d(p,q)>=0, d(p,q)=0 p=q 2. d(p,q)=d(q,p) (symmetry) 3. d(p,q)<=d(p,r)+d(r,q) (triangle inequality) Preparation for the network algorithm exercise.

What s the computational complexity of Dijkstra s algorithm? 1. Find the node with the shortest distance and that is not yet visited. 2. Mark the current node as visited. For each node (m) that is not yet visited do: 4. Proceed from (1) again until the end node is visited.

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and b to V 3. Add a (first in Q) to visited and add nodes connected to a LAST in Q. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited and add nodes connected to d LAST in Q. 6....

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and b to V 3. Add a (first in Q) to visited and add nodes connected to a LAST in Q. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited and add nodes connected to d LAST in Q. 6....

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and b to V 3. Add a (first in Q) to visited and add nodes connected to a LAST in Q. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited and add nodes connected to d LAST in Q. 6....

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and b to V 3. Add a (first in Q) to visited and add nodes connected to a LAST in Q. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited. No new nodes connected to d. 6....

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 3. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited. No new nodes connected to d. 6. Add g (first in Q) to visited. No new nodes connected to g.

Breadth-first traversal Q is a queu property is first-in-first-out b is the starting point Source: Worboys and Duckham 2004 3. 4. Add c (first in Q) to visited and add nodes connected to c LAST in Q. 5. Add d (first in Q) to visited. No new nodes connected to d. 6. Add g (first in Q) to visited. No new nodes connected to g. 7. Add e (first in Q) to visited and add nodes connected to e LAST in Q. 8.

Depth-first traversal Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add c (first in Q) to visited and add nodes connected to c FIRST in Q. 5. Add d (first in Q) to visited and add nodes connected to d FIRST in Q. 6....

Depth-first traversal Now g is added FIRST Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add c (first in Q) to visited and add nodes connected to c FIRST in Q. 5. Add d (first in Q) to visited and add nodes connected to d FIRST in Q. 6....

Depth-first traversal Now we follow the path a -> g deeper and add e FIRST in Q Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add g (first in Q) to visited and add nodes connected to g FIRST in Q. 5. Add d (first in Q) to visited and add nodes connected to d FIRST in Q. 6....

Depth-first traversal Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add g (first in Q) to visited and add nodes connected to g FIRST in Q. 5. Add e (first in Q) to visited and add nodes connected to e FIRST in Q. 6....

Depth-first traversal Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004 1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add g (first in Q) to visited and add nodes connected to g FIRST in Q. 5. Add e (first in Q) to visited and add nodes connected to e FIRST in Q. 6. Add f (first in Q) to visited. No new nodes connected to f.

1. Start point b 2. Add nodes connected to b to Q and add b to V 3. Add a (first in Q) to visited and add nodes connected to a FIRST in Q. 4. Add g (first in Q) to visited and add nodes connected to g FIRST in Q. 5. Add e (first in Q) to visited and add nodes connected to e FIRST in Q. 6. Add f (first in Q) to visited. No new nodes connected to f. 7. Add c (first in Q) to visited and add nodes connected to c FIRST in Q. L3-Network Algorithms Depth-first traversal Q is a stack property is last-in-first-out b is the starting point Source: Worboys and Duckham 2004

Breadth-first, depth-first traversal L3-Network Algorithms

Dijkstra s algorithm Breadth-first or Depth-first algorithm?

Dijkstra s algorithm - breadth first algorithm Dijkstra s algorithm search in all directions for the shortest path. It is an breadth-first algorithm

Other shortest path algorithms Algorithms with heuristics do not always give the best answer (only a reasonably good answer is guaranteed). Heuristic 1 Direction limitation (nodes closer to the end node) A* algorithm Euclidean distances, depth-first & breadth-first More likely that the shortest path is towards the end node

Other shortest path algorithms Algorithms with heuristics do not always give the best answer (only a reasonably good answer is guaranteed). Heuristic 2 Hierarchical algorithm Minor roads and major roads Minor roads only the last and first part of the route. Major roads (highways) for the main part of the route.

Other shortest path algorithms Algorithms with heuristics do not always give the best answer (only a reasonably good answer is guaranteed). Heuristic 3 super nodes (transit nodes) Stored distances between super nodes (transit nodes)

Neighbourhood graphs minimum spanning tree (MST) Minimum Spanning Tree (MST) 1. No isolated node 2.

Kruskal s algorithm for computing MST L3-Network Algorithms Original Edges Ordered Sort the edges in ascending order after distance. While there are isolated nodes in the ordered list add the currently shortest node to the MST. Do NOT add nodes that create a closed circle Source: Sedgewick 2002

Neighbourhood graphs and Clustering Visually easy to identify clusters, but how to compute?

Neighbourhood graphs and Clustering Minimum Spanning Tree (MST) 1. No isolated node Threshold distance 2.

Neighbourhood graphs and Clustering Minimum Spanning Tree (MST) 1. No isolated node Threshold distance 2.

Traveling salesman problem (TSP) 1. Begin and end in the same node (or in different nodes) 2. Visit all nodes. 3. Minimize total length of the route.

Traveling salesman problem (TSP) How to solve the TSP problems? To compute all possible combinations and chose the shortest one is too computational demanding. It is NP-complete Use the minimum spanning tree: The maximum length of the TSP is at most 2 times the total length of the MST

Traveling salesman problem (TSP) How to solve the TSP problems? Compute the MST e.g. with Kruskal s algorithm. Do iterative improvements until no further improvements are possible. A local optimum of the TSP is found.