Programming for Geographical Information Analysis Advanced Skills Online

  • Slides: 26
Download presentation
Programming for Geographical Information Analysis: Advanced Skills Online mini-lecture: Introduction to Networks Dr Andy

Programming for Geographical Information Analysis: Advanced Skills Online mini-lecture: Introduction to Networks Dr Andy Evans

This lecture Introduction. Graph theory. Types of Networks. Path analysis. Flow analysis.

This lecture Introduction. Graph theory. Types of Networks. Path analysis. Flow analysis.

Networks? Vehicle / Distribution: Motorways, rail, electricity grid, water, nerves, circuits. Socio-economic: Trade, politics,

Networks? Vehicle / Distribution: Motorways, rail, electricity grid, water, nerves, circuits. Socio-economic: Trade, politics, friendship. Spatial-temporal: Timetables, zonal maps, chemical structures. Almost any set of complex relationships between variables can be represented as a network in variable space.

Graph Theory The study of networks as graphs. How do we efficiently move around

Graph Theory The study of networks as graphs. How do we efficiently move around networks? How do networks break down? Can we add links to improve networks? How do things spread around networks?

What is a graph? Combination of (potentially disconnected) Vertices and Edges. Can be Directional

What is a graph? Combination of (potentially disconnected) Vertices and Edges. Can be Directional (sometimes called digraphs)

What is a graph? Vertices are the points on a network. Edges are the

What is a graph? Vertices are the points on a network. Edges are the relationships. The degree of a vertex is the number of edges it has connected to it.

Representing networks Note that it is only the connections that matter, not how they’re

Representing networks Note that it is only the connections that matter, not how they’re drawn. 1 2 3 4 5 6 1 1 0 1 1 1 0 0 2 1 0 1 0 3 1 1 0 1 1 1 2 3 4 4 1 0 1 0 5 0 1 1 0 0 1 5 6 6 0 0 1 1 1 0 E. g. contiguousness in maps.

Types of graph Planar graphs can be redrawn without crossing. Tree Complete: each vertex

Types of graph Planar graphs can be redrawn without crossing. Tree Complete: each vertex is connected to all the others. Regular: each vertex has the same number of edges. Simple: no loops or multiple paths.

Walks, Trails and Paths A Walk: any sequence of adjacent edges. A Trail: any

Walks, Trails and Paths A Walk: any sequence of adjacent edges. A Trail: any sequence of unrepeated adjacent edges. A Path: any sequence of adjacent edges that don’t visit the same vertex more than once. A trail, but not a path. A path that ends where it begins is called a Cycle.

Eulerian networks A graph is Eulerian if there is a trail containing every edge

Eulerian networks A graph is Eulerian if there is a trail containing every edge in a graph. Euler solved the Königsberg Bridges problem: can you cross all the bridges and return to your starting point, crossing each once and once only… A B C D

Eulerian networks A graph will contain a cycle if each vertex has a degree

Eulerian networks A graph will contain a cycle if each vertex has a degree of >2. A connected graph is Eulerian if, and only if, the degree of each vertex is even. A semi-Eulerian network is the same but doesn’t end up at its start. A connected graph is semi-Eulerian when only two of its vertices are odd. Uses: Designing one-way systems. Designing diversions / flow alterations.

Fleury’s Algorithm How to construct a Eulerian trail in a Eulerian graph. Start with

Fleury’s Algorithm How to construct a Eulerian trail in a Eulerian graph. Start with any vertex, and travel through the edges, following these rules… 1. As you go through each edge, mark it as taboo. 2. If you create isolated vertices, mark them as taboo. 3. Only use a bridge as a last resort. A bridge is an edge connecting two otherwise disconnected graphs…

Hamiltonian networks A graph is Hamiltonian if there’s a path taking in every vertex

Hamiltonian networks A graph is Hamiltonian if there’s a path taking in every vertex once only, that ends where it began. A graph is semi-Hamiltonian if there’s a trail taking in every vertex once only that doesn’t end where it began. Dirac’s Theorem A simple graph with n vertices (more than two) is Hamiltonian if the degree of each vertex is greater than n/2. Note that there may be more Hamiltonian situations.

Weighted graphs So far we’ve only been interested in connections, but we can add

Weighted graphs So far we’ve only been interested in connections, but we can add strength, capacity, or length of connections. 3 4 1 2 1 3 3 Path length =5 This gives much more realistic networks, and allows us to study real path optimisation problems.

Path optimisation problems Three major problems Shortest Path Problem What is the shortest path

Path optimisation problems Three major problems Shortest Path Problem What is the shortest path between two points? Chinese Postman Problem What is the shortest way around a network back to the start taking in each edge (imagining the edges to be roads of houses)? Travelling Salesman Problem What is the shortest way around a network back to the start taking in each vertex (imagining each to be a city)?

Shortest Path Problem Find the shortest path across a weighted graph. 5 9 5

Shortest Path Problem Find the shortest path across a weighted graph. 5 9 5 5 3 A 2 2 B 1 1 9

Shortest Path Problem algorithm Move from A to B, treating all the vertices at

Shortest Path Problem algorithm Move from A to B, treating all the vertices at each distance from the start in turn. Attribute the value of the shortest path to each vertex to that vertex, then reassess each of its neighbours to see if the path is now shorter to them. Continue until at the destination and follow back shortest path. 9 9 8 9 5 3 A 0 2 14 1 2 5 3 A 0 2 3 1 2

Chinese Postman Problem Suggested by Mei-Ku Kwan Find the shortest walk taking in all

Chinese Postman Problem Suggested by Mei-Ku Kwan Find the shortest walk taking in all the weighted edges and coming back to the start. If the graph is Eulerian we can use Fleury’s method. If not we find a semi-Eulerian trail using Fleury’s to take in all the edges. We then use the Shortest Path algorithm to find our way back to the start.

Travelling Salesman Problem Find the shortest weighted path needed to visit a number of

Travelling Salesman Problem Find the shortest weighted path needed to visit a number of cities once (i. e. the shortest Hamiltonian path). No efficient accurate algorithm. Could calculate all the possible Hamiltonians and pick the shortest. However, for 20 cities on a Hamiltonian graph, there about 6 x 1016 such possible paths. One solution is to use a Minimum Connector.

The Minimum Connector Problem Work out the smallest sub-network to connect a set of

The Minimum Connector Problem Work out the smallest sub-network to connect a set of vertices on a weighted network – a spanning tree. 1) Choose the smallest weighted edge. 2) Continue picking the next smallest connected edges but not using edges that form cycles with the ones already picked. 3 1 2 3 6 5 1 2 5 3 6 1 2 5 6

The Travelling Salesman revisited If we remove a vertex from a Hamiltonian path, we

The Travelling Salesman revisited If we remove a vertex from a Hamiltonian path, we end up with a spanning tree. To get an good approximation for the Travelling Salesman path, we… 1) 2) 3) Remove a vertex from the graph, and its associated edges. Form the minimum connector for the rest of the graph. Add in the vertex and the two of its edges with the minimum weights. This will give us a semi-Hamiltonian which the solution can’t be better than, and which the solution will be close to. Alternatively use AI to search the solution space.

Network flows: strong connection Strongly connected graphs are those digraphs where every vertex can

Network flows: strong connection Strongly connected graphs are those digraphs where every vertex can be reach from every other. Strongly connected Not strongly connected A graph can be made into a strongly connected one if each edge is in a cycle. I. e. you can’t make a purely one-way system in a town split by a single bridge.

Maximum Flow – Minimum Cut Given each part of a network has a capacity,

Maximum Flow – Minimum Cut Given each part of a network has a capacity, what is the maximum capacity of the network? It equals the minimum capacity “cut” of the graph. A cut is a set of edges which a flow must pass through one of. 1 5 A Cut 1 7 1 4 1 Maximum flow 6 9 2 3 Cut 2 B

Other things Graph Theory can help with Finding the distribution of flow in interconnected

Other things Graph Theory can help with Finding the distribution of flow in interconnected networks with resistances and inputs/outputs. Calculating whether graph lines, e. g. railways, need to cross. Calculating the number of rearrangements possible between vertices on a graph. The maximum number of different paths between two places. Timetabling (using rooms and people as components). How many colours it takes to colour a zonal map. How long it takes to do a number of parallel tasks. Magic squares. Arranged marriages.

Summary Graph theory encapsulates the mathematics of networks. Eulerian graphs are those where you

Summary Graph theory encapsulates the mathematics of networks. Eulerian graphs are those where you can visit all the edges one and end up at the start. Hamiltonian graphs are those where you can visit all the vertices once and end up at the start. The rules for these graphs help us design network systems.

Summary By giving weights to edges we can model real dynamic systems. We can

Summary By giving weights to edges we can model real dynamic systems. We can find out optimal paths. We can work out transport loads.