Karsten Steinhaeuser Aaron Wenger December 09, 2003.

Slides:



Advertisements
Similar presentations
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
PSU CS Algorithms Analysis and Design Graphs.
1 Theory I Algorithm Design and Analysis (10 - Shortest paths in graphs) T. Lauer.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Data Structures Using C++
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
The Shortest Path Problem. Shortest-Path Algorithms Find the “shortest” path from point A to point B “Shortest” in time, distance, cost, … Numerous.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Applied Discrete Mathematics Week 12: Trees
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest path algorithm. Introduction 4 The graphs we have seen so far have edges that are unweighted. 4 Many graph situations involve weighted edges.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Chapter 4 Graphs.
Shortest Path Problems Dijkstra’s Algorithm TAT ’01 Michelle Wang.
Graph. Data Structures Linear data structures: –Array, linked list, stack, queue Non linear data structures: –Tree, binary tree, graph and digraph.
Dijkstra’s Algorithm. 2 Shortest-path Suppose we want to find the shortest path from node X to node Y It turns out that, in order to do this, we need.
CSCI-455/552 Introduction to High Performance Computing Lecture 18.
Computer Science 112 Fundamentals of Programming II Graph Algorithms.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
WAN technologies and routing Packet switches and store and forward Hierarchical addresses, routing and routing tables Routing table computation Example.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Graphs Chapter 12.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Shortest Path Problem Weight of the graph –Nonnegative real number assigned to the edges connecting to vertices Weighted graphs –When a graph.
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
GLOBAL ROUTING Anita Antony PR11EC1011. Approaches for Global Routing Sequential Approach: – Route the nets one at a time. Concurrent Approach: – Consider.
Shortest Path Problems Dijkstra’s Algorithm. Introduction Many problems can be modeled using graphs with weights assigned to their edges: Airline flight.
Data Structures CSCI 132, Spring 2014 Lecture 38 Graphs
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
– Graphs 1 Graph Categories Strong Components Example of Digraph
Graphs Upon completion you will be able to:
1.7 Linear Independence. in R n is said to be linearly independent if has only the trivial solution. in R n is said to be linearly dependent if there.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
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.
Shortest Path Problems
CMSC 341 Lecture 21 Graphs (Introduction)
Graphs Chapter 11 Objectives Upon completion you will be able to:
Graphs.
Walks, Paths, and Circuits
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Shortest Path Problems
Shortest Path Algorithms
Graphs G = (V, E) V are the vertices; E are the edges.
Graphs.
Graphs.
Graphs.
Graph Vocabulary.
Graphs.
GRAPHS.
Presentation transcript:

Karsten Steinhaeuser Aaron Wenger December 09, 2003

Problem Find the best (briefest) flight route between two cities in an airline’s flight network. Solution Model the flight network as a graph, with the cities as vertices and the available flights as edges, and use a graph optimization algorithm to find the best flight route.

Section I: Background Information Graphs Dijkstra’s Algorithm

The Graph Data Structure Definition: A Graph is a collection composed of a non-empty set of vertices, and a set of pairs of vertices called edges There are different types of graphs; our Graph data structure implements non-directed, weighted, cyclic graphs (can be used trivially for non-weighted graphs by setting all edge weights to 1)

Graph Representations I Adjacency List: Represents a graph as a vector of n source vertices, each of which contains a list of pairs of destination vertices and the weight of the edge connecting the two. Example: A C B 2C5B C A5 2 8D A3B 3C 8D AB DC

Graph Representations II Adjacency Matrix: Represents a graph as an n x n matrix (implemented as n vectors of size n). Entry i,j in the matrix contains the weight of the edge connecting vertices i and j if it exists; otherwise, the entry is zero. Example: B C D B 8 D 0 A ABC AB DC

Dijkstra’s Algorithm An O(n 2 ) algorithm for finding the shortest path between two vertices in a weighted graph. Proceeds by building up a set S of vertices such that the shortest path from the source vertex to each vertex in S is known. Initially, S is empty, and in each iteration of the algorithm, the vertex closest to S (that is the vertex not in S with the shortest path from the source to the vertex that contains only vertices in S) is added to the set. The algorithm terminates when the destination vertex is added to S.

Dijkstra’s Algorithm Example: Find shortest path from A to D in the following graph AB DC A: 0 (A) B: 5 C: 7 D: 20 AB DC A: 0 (A) B: 5 (A, B) C: 7 D: 20 AB DC A: 0 (A) B: 5 (A, B) C: 7 (A, C) D: AB DC A: 0 (A) B: 5 (A, B) C: 7 (A, C) D: 15 (A, C, D) 20

Section II: Implementation Graph classes Iterators

The classes The group implemented two versions of the graph data structure, one which stores the graph internally as an adjacency matrix and one which stores the graph internally as an adjacency list. Graph – the graph base class, which defines the interface through which programs access graphs AM_Graph – adjacency matrix implementation of a graph (inherits from Graph) AL_Graph – adjacency list implementation of a graph (inherits from Graph) Vertex – holds information about a vertex in the graph; used especially by graph algorithms Edge – holds information about an edge in the graph

The iterators In order to facilitate moving through a graph, the group implemented iterators for both the AM_Graph and AL_Graph classes. It was necessary to create two types of iterators: vertex_iterator – moves through the vertices of a graph (dereferencing a vertex_iterator gives a Vertex) edge_iterator – moves through the edges from a given vertex (dereferencing an edge_iterator gives an Edge)

Iterator example void AM_Graph::print() { bool first; vertex_iterator v_it;// used to iterate through the vertices edge_iterator e_it;// used to iterate through the edges // Print the edge information for (v_it = vertex_begin(); v_it != vertex_end(); v_it++) { first = true; cout << endl << (*v_it).getName() << ':'; for (e_it = edge_begin (v_it); e_it != edge_end (v_it); e_it++) { if (first) first = false; else cout << ','; cout << (*e_it).getVertex2().getName() << '(' << (*e_it).getWeight() << ')'; } cout << endl; }

Section III: Demonstration