97

Graphs plugin 20160923-eng

Embed Size (px)

Citation preview

Page 1: Graphs plugin 20160923-eng

a QGIS python plugin for dealing with graphs

Giuliano Curti (giulianc51 at gmail dot com)

Page 2: Graphs plugin 20160923-eng

A mio padre Gaetano

Rev. 0.01

Page 3: Graphs plugin 20160923-eng

Contents

Changelog 4pre-Preface 5

Chapter 1. Preface 61.1. What's a graph? 61.2. What's this plugin 71.3. The GUI 81.4. Bibliography 14

Chapter 2. Recreational / Educational Environment 152.1. Graphic Support 152.2. Hint 262.3. Vertices 282.4. Edges 322.5. Subgraphs 342.6. Trees 352.7. Paths & Cycles 522.8. Connectivity 622.9. Shortest Paths 732.10. Quick Introduction to the directed graphs and to the networks 772.11. Inquiry Report 78

Chapter 3. Analytical Environment 793.1. Cutpoints 813.2. Bridges 833.3. Minimum Spanning Tree 853.4. Shortest Paths 863.5. Vertex Disjoint Paths 883.6. Edge Disjoint Paths 913.7. Connectivity 94

Chapter 4. Conclusions 97

3

Page 4: Graphs plugin 20160923-eng

CHANGELOG 4

Changelog

date issue

2016-08-14 Set up2016-08-25 First publication on Slideshare2016-08-29 Changelog2016-08-29 Maximum Spanning Tree (partial)2016-08-29 Cotrees2016-08-29 Fundamental cycles2016-08-29 Bridges2016-08-29 Cut points2016-08-29 Revision uploading on Slideshare2016-08-30 Clearer explanation of the plugin goal2016-08-30 GUI description2016-08-31 Single Shortest Path (Dijkstra)2016-08-31 All Shortest Paths (Dijkstra)2016-08-31 Simple intro on digraphs & networks2016-09-05 GUI remaking2016-09-13 Vertex Disjoint Paths & Vertex-connectivity2016-09-13 Edge Disjoint Paths & Edge-connectivity2016-09-13 Revision uploading on Slideshare2016-09-15 Melegnano Road Graph Analysis2016-09-15 Melegnano Road Graph Cutpoints & Bridges2016-09-15 Melegnano Road Graph MST2016-09-15 Melegnano Road Graph Shortest Paths2016-09-15 Melegnano Road Graph VDP2016-09-15 Revision uploading on Slideshare2016-09-15 Melegnano Road Graph EDP2016-09-20 Italian Version Forked2016-09-23 Edge-connectivity of the Melegnano's road graph2016-09-23 Rev. 0.01-eng closed

Page 5: Graphs plugin 20160923-eng

PRE-PREFACE 5

pre-Preface

(1) These notes are written as an help for my learning and understanding theGraph theory; they re�ects my present knowledge of the matter, pleaseexcuse any inaccuracy and imperfection contained in the writing.

(2) These notes re�ects my approach to the Graph Theory, so they are NOTin any way, a criticism and/or a competitor of any other available tool onthe subject.

(3) I share these notes in the hope that they can be of help to some otherstudent of graph theory.

(4) Any comments, advices, supports or criticisms are welcome.(5) As I assume all responsibility for the contents of this writing, no warranty,

express or implied, is connected with the use of these notes and/or theplugin, so the user assumes the contents at its own risk and responsibility.

(6) This document is released under CC by SA NC.(7) Sorry for my bad english.

Page 6: Graphs plugin 20160923-eng

CHAPTER 1

Preface

1.1. What's a graph?

AGraph is a very basic structure: a set of Points (here namedVertices) anda set of Lines (here named Edges) connecting a pair of vertices; mathematically agraph is de�ned by the symbol G (V,E) where V is the set of vertices and E = V 2

the set of edges. We don't enter in the details of the graphs, some will be explainedin later chapters: we limit our analysis to simple graphs; moreover, we limit toconnected graphs, that is graphs, all wich pairs of vertices are joined by some setof edges (the curious reader can refers to the bibliography for more info).

This is a graph (really, this is a tree) with the vertices V = {B,C,G,N, S, T, Y,W}and the edges E = {(B, T ) , (T,N) , (C, Y ) , (Y,W ) , (G,W ) , (W,N) , (N,S)}.

What it is interesting to note it's that graphs are independent from the posi-tions, sizes, distances, etc., the only important thing is that the vertex u is connectedor not to the vertex v with u, v ∈ V .

6

Page 7: Graphs plugin 20160923-eng

1.2. WHAT'S THIS PLUGIN 7

1.2. What's this plugin

As you knows, QGIS comes with a Network Analysis Library that implementssome tools for the networks (a Dijkstra algorithm primarily); in recent time manycontributors added some plugin for the same target: so, why a new plugin for

the graphs?

As I said in the pre-Preface, this plugin is primarily intendend as an aid

for learning and understanding the Graph Theory. My actual target is notthe analysis of the global performances of a network nor of a directed graphs norto build powerful library: these tasks are better accomplished by the many tools,inside and outside the QGIS world, available to the user; my present target is toallow the user (me �rst) to learn the basical properties of a graph: paths, cycles,spanning trees, connectivity, etc. My hope is to develop the plugin for bigger tasks,but now my target is that I described.

All the algorithms implemented in the plugin is physically written inside itscode without usage of any external library; obviously this make the plugin extremelysensitive to bugs and failure, but I think more interesting for learning usage as Idescribe later. Generally the algorithms are derived from the technical literature,especially from the bibliography listed in the next paragraph, but the need foranalytical tools of connectivity, normaly taken from a later part of the theory(directed graphs), forced me to write some algorithms from nothing; obviouslythey have to be veri�ed and available for anyone to examine.

In writing it I had in mind two environments:1) a recreational and/or learning ambient2) a more serious, analytical environment;the �rst part of these notes are focused on the �rst topic; I will try, in the

second part, to approach some more interesting situations.The plugin can manage one graph at a time and cannot shift from one graph

to another one; a closed job must be reopen.

Page 8: Graphs plugin 20160923-eng

1.3. THE GUI 8

1.3. The GUI

The plugin is managed by a control panel. The control panel is organized indi�erent tabs (this is a new update so we can see some �gures in the doc with oldfashioned gui).

(1) I/O

Page 9: Graphs plugin 20160923-eng

1.3. THE GUI 9

(2) Properties of the graph

Page 10: Graphs plugin 20160923-eng

1.3. THE GUI 10

(3) Vertex & Edge inquiry

Page 11: Graphs plugin 20160923-eng

1.3. THE GUI 11

(4) Trees & Cycles

Page 12: Graphs plugin 20160923-eng

1.3. THE GUI 12

(5) Connectivity

Page 13: Graphs plugin 20160923-eng

1.3. THE GUI 13

(6) Paths

Page 14: Graphs plugin 20160923-eng

1.4. BIBLIOGRAPHY 14

1.4. Bibliography

The subject of the graphs is a well know topic in many branches of Mathematics,so it's frequent to encounter some usefull documents in areas as Linear Programmingand Optimization, Software Engineering, Networks Analysis, and so on.

I moved my preliminary passes in these books; these allow the timid approach asthe mine, but they can o�er challenging issues to the reader, so they can constitutea complete guide to graphs study:

(1) J.A.Bondy, U.S.R.Murty, Graph Theory, Springer, 2008

(2) Frank Harary, Graph Theory, AddisonWesley, 1969

Page 15: Graphs plugin 20160923-eng

CHAPTER 2

Recreational / Educational Environment

2.1. Graphic Support

As I previously said, a graph is not determined by its sizes, shapes, distances,etc. but neverthless its sketch is very usefull: it allow to the reader to acquire theimmediate knowledge of the graph.

This fact o�ers the �rst useful relation with QGIS: QGIS as a support for thevisualization of the graph.

We now �gure out the simpler form, a clever interaction between QGIS andgraph4qgis will be presented later.

There are three ways of opening �les in the graph4qgis plugin, these are therespective �ow-chart:

(1) load a Graph �le(a) if the plugin �nd a vertex SHP �le related load it with the permission

of the user(b) otherwise create automatically the coordinates and build the SHP

�le of the vertices(c) create the SHP �le of the edges

(2) load a Shapefile �le(a) create the graph structure(b) create the SHP �le of the vertices

(3) load a CSV �le (this way is the same as loading a SHP �le)(4) freehand building of a edge layer(5) there is a �fth way of importing TXT �le, but it is not discussed here.

15

Page 16: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 16

2.1.1. Load a Graph �le. This is the standard way: the user load a Graph�le:

Page 17: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 17

the system recognize if there are shape�les related to the graph �le open; ifthere are, the system give the user the option of loading these �le:

Page 18: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 18

if the user answer �yes� the system load the existing shape�le, otherwise thesystem automatically build and load on the canvas the vertices and edges layer (inmemory):

This is a raw representation of a graph published by Frank Harary.

Page 19: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 19

The user can edit the vertex layer with the usual tools of QGIS as follows

Page 20: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 20

Pressing the update SHP button we rebuild the layout as presented by theAuthor in Graph Theory, Addison Wesley, 1969, �g. 5.1, pag. 44:

Page 21: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 21

2.1.2. Load a Shape�le �le. The second way, the user load a SHP �le (alinestring vector SHP �le):

by pressing the button �Load SHP� the system automatically build the Graphstructure and create & load on the canvas the vertices shape�le �le.

Page 22: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 22

2.1.3. Load a CSV �le. Then the user can start from a text �le as that:

for the input of edges; the �le contains a line for every edge in the graph, givingthe geometry of the endpoints;

Page 23: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 23

the user can load it with the standard tool of QGIS and this is the result:

the CSV �le actually build a vector layer in the QGIS map canvas, next theuser need follow the procedure described in �2.1.2.

Page 24: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 24

2.1.4. Freehand. As a last resort you can use the useful potential of QGISto draw vector layers; in this case the rules to be observed are:

(1) create a vector layer type LineString(2) populate it with line features(3) the vertices of the graph will be de�ned at the end points of the lines(4) the intersections of the lines are not considered (technically it is said that

they are also allowed non-planar graphs); it is your responsibility in thiscase to break the lines at points of interest.

This done, it must follow the procedure described in �2.1.2; this is an example:

Page 25: Graphs plugin 20160923-eng

2.1. GRAPHIC SUPPORT 25

.. and this is the �nal graph:

Page 26: Graphs plugin 20160923-eng

2.2. HINT 26

2.2. Hint

2.2.1. Python Console. It's probably a good thing to open the Pythonconsole in QGIS to look for eventually messages from the system

Page 27: Graphs plugin 20160923-eng

2.2. HINT 27

2.2.2. QGIS Editing Capabilities. A very powerful option can be derivedfrom the editing capabilities of QGIS: the highlighted elements we will see in the

next steps, can be copied with the standard function of QGIS

and duplicated in a di�erent vector layer for future reference or work

Page 28: Graphs plugin 20160923-eng

2.3. VERTICES 28

2.3. Vertices

2.3.1. Vertex List. The application o�ers the list of the vertices:

The total number of vertices is n.

Page 29: Graphs plugin 20160923-eng

2.3. VERTICES 29

2.3.2. Vertex Coordinates. ... the list of the cartesian coordinates of thevertices:

Page 30: Graphs plugin 20160923-eng

2.3. VERTICES 30

2.3.3. Vertex Degrees. ... and the list of the degree of the vertices:

Page 31: Graphs plugin 20160923-eng

2.3. VERTICES 31

2.3.4. Vertex inquiry. The user can inquiry a single vertex selecting it fromthe combo box; the selected vertex are given the cartesian coordinates, thedegree and the adjacents vertices:

Page 32: Graphs plugin 20160923-eng

2.4. EDGES 32

2.4. Edges

2.4.1. Edge List. The user can list all the edges of the graph:

The total number of edges is m.

Page 33: Graphs plugin 20160923-eng

2.4. EDGES 33

2.4.2. Edge Inquiry. .. or inquiry a single edge obtaining their endpoints

Page 34: Graphs plugin 20160923-eng

2.5. SUBGRAPHS 34

2.5. Subgraphs

2.5.1. Subgraphs. Give a graph G = {VG, EG}, the graph H = {VH , EH}such that vH ⊆ VG and EH ⊆ EG is said subgraph of G.

2.5.2. Induced subgraphs. (to do)

Page 35: Graphs plugin 20160923-eng

2.6. TREES 35

2.6. Trees

Some interesting subgraphs of G are the trees T = {VT , ET }; the character-ization of the trees is that they contains the minimum number of edges necessaryto connect all the vertices of the graph.

Particularly important are the spanning trees with the property VT = VG, sothe tree T contains all the vertices of the graphs; the edges ET ⊆ EG are in numberof n− 1; by elementary properties the user can verify that this number is necessaryto connect the vertices (a minor number of edges leaves some vertex disconnected)and enough (a major number connects vertices already connected).

Of the many trees subgraphs of G we analyse the three important ones:

(1) Breath First Search (BFS)(2) Depth First Search (DFS)(3) Minimum Spanning Tree (MST);

later we will see the importance of that tree in the analysis of the graphs.At the end of the chapter we introduce a fourth tree, the Maximum Spanning

Tree, whose meaning is made clear from what follows.

Page 36: Graphs plugin 20160923-eng

2.6. TREES 36

2.6.1. Breath First Search. We have already noticed that in a tree all pairsof vertices are joined, so we can de�ne a base vertex, said root, and we cannavigate the tree from the root to join all other vertices; this can accomplished inmany di�erent ways, one is the Breath First Search; this way we start fromthe root (level 1) and join the adjacent vertices (level 2), then we join the adjacentvertices of the level 2 (level 3), etc; this is very similar to the organisation of thecomputer �le system where we have the root, a level down the folder of �les, onemore level down, other folders and �les, etc.; another familiar example are a familygenealogic tree where the level represents the generations.

This is an example of a BFS with the root v1:

in red are the edges of the BFS tree;

Page 37: Graphs plugin 20160923-eng

2.6. TREES 37

this is an enlargement of the table displayed in the python console of QGIS:

where we can see

(1) the predecessor(2) the level(3) the time

of the vertices traversed by the BSF

Page 38: Graphs plugin 20160923-eng

2.6. TREES 38

or, if you prefer, in this graphics form:

.

Page 39: Graphs plugin 20160923-eng

2.6. TREES 39

2.6.2. Depth First Search. Probably the user think of the BFS as a strati-�cation of the graph and an analysis layer by layer; we can imagine to navigate ourgraph in a di�erent manner, in example by navigating in depth from the root tothe �rst connected vertex, and so on; reached an extremal vertex, we restart fromthe �rst allowable vertex and so on: this way is the Depth First Search; this isan example of a DFS with the root v1:

in red are the edges of the DFS tree;

Page 40: Graphs plugin 20160923-eng

2.6. TREES 40

this is an enlargement of the table displayed in the python console of QGIS:

where we can see:

(1) the predecessor(2) the forward time(3) the backward time

of the vertices traversed by the DSF.

Page 41: Graphs plugin 20160923-eng

2.6. TREES 41

This is an example of the same graph with the root v4:

the DFS tree is coloured in yellow;

Page 42: Graphs plugin 20160923-eng

2.6. TREES 42

the details are displayed in the following table:

The same can be done with the BFS.

Page 43: Graphs plugin 20160923-eng

2.6. TREES 43

2.6.3. Weigths. Before passing to the third and last tree, we need introducea new term: theWeight of the edge. Just to now we have considered all the edgesequals, so the navigation from the vertex A to the vertex B is the same as thenavigation from the vertex C to the vertex D; in many real situations where thegraphs represents a very useful model, the things are di�erent: A can be nearer toB than C to D; in other case the navigation from A to B can be cheaper than fromC to D, etc. So we need introduce a property that characterize the edges of thegraphs, that property is the weight (in technical literature it is also named Cost);selecting an edge in the combobox, among other properties already discussed, wehave the weight of the edge:

(the edge (G,W ) has weight 837).

Page 44: Graphs plugin 20160923-eng

2.6. TREES 44

This is the list of all the weights of graph, in tabular form:

or in graphic form:

Page 45: Graphs plugin 20160923-eng

2.6. TREES 45

Page 46: Graphs plugin 20160923-eng

2.6. TREES 46

2.6.4. Minimum Spanning Tree. Returning to the trees, we can imagineto build the tree of the graph with the minor weight (or cost) among all other trees,it is the Minimum Spanning Tree.

An simple example is the problem of building an expensive network (the termis used here in generic sense) as that presented in J.A.Bondy, U.S.R.Murty, GraphTheory, Springer, 2008, �6.2, �g. 6.5, pag. 165 on the hydro-electric grid of theRepublic of China.

Two algorithms are well noted for this computation:

(1) the Jarnik-Prim algorithm(2) the Boruvka-Kruskal algorithm.

The user is addressed to the technical literature for the details, the plugin executesall two ways.

Page 47: Graphs plugin 20160923-eng

2.6. TREES 47

2.6.4.1. Jarnik-Prim. This is an example of the Jarnik-Prim algorithm:

with the list of weights:or with the weights on the screen:

Page 48: Graphs plugin 20160923-eng

2.6. TREES 48

Page 49: Graphs plugin 20160923-eng

2.6. TREES 49

2.6.4.2. Boruvka-Kruskal. This is an example of the Boruvka-Kruskal algo-rithm:

with the list of weights:

Warning: the MST is unique, so no surprise if the two algorithms give the samesolution, there are no more chances. The execution of the two algorithms can trusteach other.

Page 50: Graphs plugin 20160923-eng

2.6. TREES 50

2.6.5. Maximum Spanning Tree. It's a symmetrical game to think to amaximum spanning tree: inverting the sign of the weights of the tree w → −wthe algorithms performs the search of the Maximum Spanning Tree (the inversew → 1

w can be employed, but the sum of the inverse is not the inverse of the sum,so we prefer use the opposites):

(the MxST is in yellow).

Page 51: Graphs plugin 20160923-eng

2.6. TREES 51

2.6.6. Leaf. Characteristic elements of a tree are the leaf, the end vertices,the vertices with degree 1. Of course, can be present in any graph; despite visibledirectly, the plugin provides you with a command to view the leaf, the set of endvertices

Page 52: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 52

2.7. Paths & Cycles

2.7.1. Generality. As we have seen, the presence of edges among the verticesallow the navigation from point to point; given two vertices p and q, we have manytype of navigation from one to the other: with repeatition of some edges, withrepeatition of some vertex; the navigation without repeated vertices (and thuswithout repeated edges) is the most important, named Path and denoted by pPq.

Rethincking the trees, we can see that between any pair of vertices exists apath; moreover, the path is unique: this is an important characterisation of thetree.

But we have seen that the tree span the vertices, but does not span the edges:why the role of the additional edges? this is the argument of the next paragraph.

Page 53: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 53

2.7.2. Cotrees. Given the graph G = (V,EG) and a spanning tree T =(V,ET ), the subgraph complement C = (V,EC) where EC = E −ET is a cotree.

2.7.2.1. BFS cotree. This is the cotree of the BFS tree of �2.6.1

As you can see the edges set of the cotree EC = {e3, e5, e7, e10, e11} are com-plementary with the edge set ET = {e0, e1, e2, e4e6, e8, e9} of the tree.

Page 54: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 54

2.7.2.2. DFS cotree. We can do the same with the DFS tree

Page 55: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 55

2.7.3. Cyclomatic number. We know that the number of the edges of a treeare |ET | = n−1, so the number of the cotree edges is |EC | = |E|−|ET | = m−n+1;this is the cyclomatic number and is displayed in the tab inquiry of the gui:

next we will see the reason of its name.

Page 56: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 56

2.7.4. Cycles. In a tree we have a unique path between any two vertices; ifwe adjoin one edge of the cotree (here we used the BFS tree & cotree) we have acircuit; the edge e3 of the cotree join the vertices v2, v4 of the graph, but betweenthese vertices there is already a path enbedded in the tree, exactly the path v2Pv4 =(v2, v0, v4); the �nal result is the path (v2, v0, v4) + (v4, v2) = (v2, v0, v4, v2); thisspecial path, where we can start from any vertex and rejoindre the same vertex isnamed Cycle.

Page 57: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 57

The same with the edge e5

Page 58: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 58

The same with the edge e7

Page 59: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 59

The same with the edge e10

Page 60: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 60

The same with the edge e11

Page 61: Graphs plugin 20160923-eng

2.7. PATHS & CYCLES 61

2.7.5. Fundamentals cycles. As we have seen, for any edges of the cotreewe have a cycles, this is the reason why the number of the cotree edges m− n+ 1is called cyclomatic number.

Note that the graph can contains more cycles, but it is important to note thatany other cycle can be obtained from the previous ones, justifying their name:Fundamental Cycles.

Combining the cycle �rst and fourth cycles we obtain a new cycle

{e1, e10, e6}+ {e0, e3, e6} = {e1, e10, e3, e0}.

Page 62: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 62

2.8. Connectivity

2.8.1. Generality. We have talk of connectivity as a boolean property of agraph G, actually the connectivity is a rather variable property, for example thefollowing graph presents very di�erent graduation of connection

in the �rst graph it's enough to delete the central edge or one of the centralvertices to disconnect it in two di�erent parts; in the second the elimination ofseveral edges and/or vertices leave the graph connected; we analyse this propertynamed Connectivity.

Page 63: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 63

2.8.2. Bridges. A Bridge is an edge whose deletion disconnect the graph

as the edge (v1, v3) that disconnect the part {v0, v1, v2} from the part {v3, v4, v5}of the graph.

Page 64: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 64

2.8.3. Cutpoints. A vertex whose deletion disconnect the graph is calledCutpoint;

in the previous graph we see that the deletion of the vertex 5 disconnect thegraph, so the vertex 5 is a cutpoint ; the same is for the vertex 6.

Page 65: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 65

2.8.4. Vertex-connectivity & Line-connectivity. The last two graphs arespecial graphs, with a bridge and two cutpoints; not all graphs have a bridge and/ora cutpoint; normally we need delete a certain number of edges and/or vertices todisconnect the graph; maintening this two issues separated, we can talk of Vertex-connectivity and Line-connectivity.

The connectivity is very joined with the disjoint paths, especially the vertex-connectivity with the vertex-disjoint-paths and the edge-connectivity with the edge-disjoints-paths; we can easily prove that the deletion of a vertex (edge) delete avdp (edp), so their number need match; the number k of elements necessary todisconnect the graph gives the level of connectivity and we talk of vertex(edge)-connectivity = k. Obviously the connectivity changes with the pair of verticesconsidered; so we can speak of local connectivity; the minimum value givesthe connectivity of the graph.

Page 66: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 66

2.8.4.1. Vertex-disjoint. In general, in a graph G we have several paths betweentwo vertices; we are interested in the speci�c paths with not shared vertices, theso-called Vertex-Disjoint Paths; in the graph below (from Frank Harary, GraphTheory, Addison Wesley, 1969, p. 44), from the vertex a to the vertex h we havethe path (a, c, l, h):

Page 67: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 67

and the path (a, d, f, h):

Any path can have several variants, for example the last path can be substitutedby the path (a, b, e, d, f, i, g, h), but the number of paths without common verticesare only two, this is an invariant of the graph.

So, the concept can be rephrased: in a graph, the vertex-disjoint paths con-necting two vertices are �xed; the paths displayed are two from several paths.

Page 68: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 68

2.8.4.2. Vertex-connectivity. The mentioned property is an important index ofthe connectivity of the graph; it's evident that the deletion of one vertex for eachpath destroys the connectivity of the graph; in the example below

the deletion of the vertex c in one path and of d in the other (or the deletion ofthe vertices f and l) disconnect the graph; so the number of vertex-disjoint pathsequate the number of vertices whose deletion disconnects the graph; the minimumnumber for all pairs of vertices, is called Vertex-connectivity of the graph G;its value is reported in the inquiry report.

Page 69: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 69

2.8.4.3. Edge-disjoint. In this chapter we are interested in the speci�c pathwith not shared edges, the so-called Edge-Disjoint Paths; in the graph below(from Frank Harary, Graph Theory, Addison Wesley, 1969, p. 44), from the vertexa to the vertex h we have the path (a, d, l, h):

Page 70: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 70

the path (a, e, d, f, h):

Page 71: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 71

and the path (a, c, l, i, h):

As in the case of VDP, any path can have several variants, but the number ofpaths without common edges are only three, this is an invariant of the graph.

Page 72: Graphs plugin 20160923-eng

2.8. CONNECTIVITY 72

2.8.4.4. Line-connectivity. The mentioned property is an important index ofthe connectivity of the graph; it's evident that the deletion of one edge for eachpath destroys the connectivity of the graph; in the example below

the deletion of the edge d− l in the �rst path, of the edge d− f in the secondand of the edge c − l in the third, disconnect the graph; so the number of edge-disjoint paths equate the number of edges whose deletion disconnects the graph;the minimum number for all pairs of vertices, is called Edge-connectivity of thegraph G; its value is reported in the inquiry report.

Page 73: Graphs plugin 20160923-eng

2.9. SHORTEST PATHS 73

2.9. Shortest Paths

2.9.1. Generality. As already said, in a connected graph G we can reach,from a vertex p, any vertex of the graph; this can be accomplished generally inmany ways, so we can ask: what the shorter way from p to q? Obviously, thecriteria to meets can be many: distance (the shorter way from p to q), cost (thecheaper way from p to q) and so on. We unify all the criteria in the already notedproperty weight, so we use the word shorter as synonymous of lighter, exactly as wesee for theMinimum Spanning Tree, the di�erence being that now we are interestedonly in the path from p to q.

Page 74: Graphs plugin 20160923-eng

2.9. SHORTEST PATHS 74

2.9.1.1. Single Shortest Path (Dijkstra). The Dijkstra algorithm accomplishthis task; below is the shortest path from the vertex 1 to the vertex 9 of the graphpublished by J.A.Bondy, U.S.R.Murty, Graph Theory, Springer, 2008, �g. 6.7, pag.150:

the path navigate across the vertices (1, 3, 9); its weight is 2.00: among all thepaths from 1 to 9, the displayed path is the shorter.

Page 75: Graphs plugin 20160923-eng

2.9. SHORTEST PATHS 75

2.9.1.2. All Shortest Paths SP (Dijkstra). The same Dijkstra algorithm canbe used to know all the shortest paths from one vertex to any other; belowis displayed a path between the vertex 6 and the vertex 9: (6, 12, 7, 3, 9) of totalweight 7.00:

Page 76: Graphs plugin 20160923-eng

2.9. SHORTEST PATHS 76

and here the path between the vertices 6 and 10: (6, 12, 7, 3, 1, 4, 10) of totalweight 10:

Page 77: Graphs plugin 20160923-eng

2.10. QUICK INTRODUCTION TO THE DIRECTED GRAPHS AND TO THE NETWORKS77

2.10. Quick Introduction to the directed graphs and to the networks

As we already said, the graphs are a mathematical model to apply in manybranches of the Science or in the industrial applications; nevertheless their gen-erality need to be constrained to adapt the model to speci�c situations; here weintroduce brie�y the principal developments of the graphs; this only for completionof the informational frame to the user, without entering in details; this work islimited to graphs: our emphasis on graphs is because of their importance for thefurther developments.

2.10.1. Directed Graphs. In the graph theory, the edge connecting the ver-tex p to vertex q, connects at the same time the vertex q to vertex p, that is, it issymmetric; this is not always so, the are situations when the edge connect p withq, but not the reverse; we can thinck for example to one way tra�c road ; probablythe same is for electronic schemas; or to the blood veins and arteries of our body.

In this cases, the direction is important, so we need to consider graphs withorientation or directed graphs, brie�y said Digraphs.

2.10.2. Networks. In speci�c applications the direction is not enough; forexample: in the analysis of tra�c and transportation, the knowledge of directions isnecessary to know if from the vertex p we can reach the vertex q; also, the introducedalgorithms for �nding the shortest paths can be a great help for economic reasons;well, but this is not enough: we probably want to know how many vehicles cannavigate on the route, how many products can be transported, and so on. Forthis necessity we need to introduce two other properties of the arcs (this is theusual name of the edges in the digraphs): the capacity c and the �ow f with theconstraint f ≤ c.

I hope in the near future to be able to deal with these problems, but now Imust leave here.

Page 78: Graphs plugin 20160923-eng

2.11. INQUIRY REPORT 78

2.11. Inquiry Report

Many of the properties so far examined, are summarized in an inquiry reportdisplayed at the opening on the graph data:

Page 79: Graphs plugin 20160923-eng

CHAPTER 3

Analytical Environment

As a further explanation of my plugin performances, I will apply it to an actualcase, the road graph of my town, Melegnano, near Milan, Italy:

This is the simpli�ed road graph extracted from a SHP �le and converted to agraph structure understandable by my plugin.

Caution: As I said, we analyze here the network as a graph, without consid-eration of the way direction of the roads. If we admit an analogy: the (graph) roadis hardware and the way direction is software (being possible to change the way inany time), the present study can be viewd as an hardware analysis; we leave thesoftware analysis for future developments of my work.

79

Page 80: Graphs plugin 20160923-eng

3. ANALYTICAL ENVIRONMENT 80

The report says

• 179 vertices• 237 edges• total w(e)ight 28537m (we used the length in meters of the roads as aweight of the graph)

• the graph is connected so there are no components• minimum degree 1 (there are many �cul de sac� ways)• maximum degrees 4• mean degrees 2.6• the graph is

� not even� not odd� not bipartite

• cyclomatic number 59• 49 cutpoints (we use two experimental algorithms and the report say thatthe vers. A of algorithm gives a di�erent number of cupoints: to beinvestigated)

• 50 bridges;

for the connectivity we will say something below.

Page 81: Graphs plugin 20160923-eng

3.1. CUTPOINTS 81

3.1. Cutpoints

Analyzing some detail, we can highlight the cutpoints, all togheter:

Page 82: Graphs plugin 20160923-eng

3.1. CUTPOINTS 82

or one by one:

This case is very important: the deletion (or failure) of vertex v108 disconnectthe graph, so the vertex v109, a civic utility center (school, swimming pool, soccercamp, etc.), cannot be reached, but also the vertex v111, the connection withregional network, is prevented to be.

Page 83: Graphs plugin 20160923-eng

3.2. BRIDGES 83

3.2. Bridges

One more detail are the bridges, all togheter:

Page 84: Graphs plugin 20160923-eng

3.2. BRIDGES 84

or one by one:

many bridges represents �cul de sac� ways, so they are relative important; moreimportant is the bridge v108− v111, not visualized in the �gure, but present in theprevious one: ist failure or deletion cause the same disconnection as the cutpointv108.

Page 85: Graphs plugin 20160923-eng

3.3. MINIMUM SPANNING TREE 85

3.3. Minimum Spanning Tree

A very interesting detail is the Minimum Spanning Tree, �gured in the imagebelow:

the total weight (length) of the tree is 28km, the total lenght of the MST is17km.

There is an old discussion in my town about the cycling and hiking trails; asoften it happens in Italy, the discussions are long, cycle and pedestrian tracks a bitless .....

Anyway, I suppose that the budget of a network infrastructure is costly andthe need to equip the entire city of runs would mean equipping over 28km of roads.

If we consider the bike paths as a valuable resource of the kind analyzed byJ.A.Bondy, U.S.R.Murty, Graph Theory, Springer, 2008, 6.2, g. 6.5, p. 165, alreadycited in �2.6.4, we can think of the MST as a possible solution: it would be enoughto equip 17km of runs to make crossed the entire city and make accessible all thecrucial points.

Caution: the cost of the road or its lesser or greater length is not the onlycriterion; if I let my momentary role of amateur mathematician and I take thearchitect clothes that I dressed until recently, certainly I would analyze many otherelements; what I believe, however, returning quickly in the most comfortable shoesof mathematics, is that the information is a very useful tool for decision makers, ananchor to put together with others to build the right planning and decision-makingpuzzle: I will you know what think my fellow citizens.

Page 86: Graphs plugin 20160923-eng

3.4. SHORTEST PATHS 86

3.4. Shortest Paths

We can analyze the Shortest Paths, the Single Shortest Paths from, for example,vertex v86 to vertex v173:

Page 87: Graphs plugin 20160923-eng

3.4. SHORTEST PATHS 87

of the All Shortest Paths from, for example, the vertex v86:

the paths can be visualized one at time, in the �gure is shown the path fromv86 to v153.

Caution: this analysis is the same as that available in Network Analysis Li-brary of QGIS and the plugins already cited; probably the latters gives betterperformances and are more robust than mine; as I noted, the duplication of thealgorithms in my plugin is for learning purposes.

Page 88: Graphs plugin 20160923-eng

3.5. VERTEX DISJOINT PATHS 88

3.5. Vertex Disjoint Paths

An interesting aspect are the Vertex Disjoint Paths; we have computed the VDPbetween the vertex v89, the center of the town, and the vertex v44, the connectionwith the north (Milan); as we can see from the �gures below, there are three suchpaths, the �rst:

Page 89: Graphs plugin 20160923-eng

3.5. VERTEX DISJOINT PATHS 89

the second:

Page 90: Graphs plugin 20160923-eng

3.5. VERTEX DISJOINT PATHS 90

and the third:

The edges are two-way roads, so in this case the hardware analysis match withthe software analysis.

What is important to note is the notion of local connectivity: the connectionbetween the city center and the north regional network is strong enough: threevertices need to be deleted for destroy this connection.

Page 91: Graphs plugin 20160923-eng

3.6. EDGE DISJOINT PATHS 91

3.6. Edge Disjoint Paths

Analogous to vertex-disjoint are the Edge Disjoint Paths, the di�erence beingthat this way we can navigate across a vertex already visited but the edges can beall di�erent across the paths; using the vertices v89 and v44, we have three paths,the �rst:

Page 92: Graphs plugin 20160923-eng

3.6. EDGE DISJOINT PATHS 92

the second:

Page 93: Graphs plugin 20160923-eng

3.6. EDGE DISJOINT PATHS 93

and the third:

Mathematical note: let κ (G) the local vertex-connectivity, λ (G) the localedge-connectivity and δ (G) the minimum degree, we have the theorem of Whitneyκ (G) ≤ λ (G) ≤ δ (G) (F.Harary, Graph Theory, Addison Wesley, 1969, th. 5.1 pag.43); in the present case with κ (G) = 3, λ (G) = 3 and δ (G) = min (dv044, dv089) =3, we have κ (G) = λ (G) = δ (G) verifying the Whitney theorem.

Page 94: Graphs plugin 20160923-eng

3.7. CONNECTIVITY 94

3.7. Connectivity

3.7.1. A Suggestion. We have seen the importance of the vertex- and edge-connectivity on the structure of the graph; often the graphs contains many end-points, so the are many cutpoints & bridges; obviously these cutpoints & bridgesare well known and not very important because their failure disconnect a small partof the graphs; but this multitude hides eventually important cutpoints & bridges,so we have recovered a previous result from the paragraph �2.6.6: the leaf of thegraph. Applying the cancellation of the endpoints up to exhaustion, we reach asubgraph I named core; this is the core of the Melegnano's road graph:

Page 95: Graphs plugin 20160923-eng

3.7. CONNECTIVITY 95

Applying the known analysis to this subgraph we can discover more interestingaspects:

(1) there are four cutpoints (v6, v21, v22, v158)(2) there is one bridge (v21-v22).

Page 96: Graphs plugin 20160923-eng

3.7. CONNECTIVITY 96

3.7.2. Vertex Connectivity. We have just seen at paragraph �2.8.4 the im-portance of the vertex-connectivity of a graph; this is the statistics for the roadgraph of my town:

number of pairs 8197minimum 1 at pair ['v 0', 'v 12']average 1.73maximum 4 at pair ['v 1', 'v 4']

sqm 0.66

I confess that the average �gure (1.73) worries me because here we are dealingwith the subgraph puri�ed from terminal nodes and I confess I would have expectedat least a value greater than 2.

(Note 1: the new version of the plugin allow the statistics distribution of thevertex-connectivity; this table is done with a previous version; I will next updatethe data).

(Note 2: The table were accomplished with a batch version of the app becausethe computing the VDP is too long for an interactive session as the plugin).

3.7.3. Edge Connectivity. This is the statistics for the road graph of mytown:

number of pairs 8385minimum 1 at pair ['v 0', 'v 12']average 2.10maximum 4 at pair ['v 1', 'v 4']

sqm 0.68the distribution of the connectivity by degree is below:degree times %

0 0 01 1510 182 4554 543 2288 274 33 <1

totale 8385 100

.

I advance an hypothesis: we have seen the presence of the bridge (v20, v21);this bridge partitions the graph in two block of approximately 10 ÷ 12 vertices atnorth-east and the remainings 130− 10÷ 12 = 118÷ 120 (we are dealing with thecore of the road graph) for a total of 118 ÷ 120 × 10 ÷ 12 = 1200 ÷ 1416 pairs,therefore the pairs with edge-connection = 1 are probably linked with that bridge;we can think that the graph is substantially strong).

(This table too were accomplished with a standalone version of the app becausethe computing the EDP is too long for an interactive session as the plugin).

Page 97: Graphs plugin 20160923-eng

CHAPTER 4

Conclusions

There are not many thinks to tell, I written all what I had in mind; I hope togive you a clear information on my plugin and I hope this can be of help to someonelearning the Graph Theory.

I wait your suggestions, contributions and criticisms, in the meantime I will tryto develop something on the directed graphs and the networks.

Thank you.

97