00 - Graph - MM

00 - Graph - MM

Graphs are useful mathematical models for representing urban and transportation networks.

Schermata 2024-10-10 alle 16.09.44.png

Directed graph

directed graph

A directed graph is a set of N nodes and a set of A arcs or links whose elements are ordered pairs of distinct nodes.

It is represented as

G=(N,A)

00 - Graph 2024-10-10 16.12.25.excalidraw.png

For the example graoh above we would have:

N=1,2,3,4,5,6,7A={(1,2),(1,3),(2,3),(2,4),(3,6),(4,5),(4,7),(5,2),(5,3),(5,7),(6,7)}

Graph representation

Incidence matrix

07. Schematizzazione dell'offerta di trasporto#Matrice di incidenza

A graph is a just a diagram. We need to make calculations. We have to define a way to translate the graph into a mathematical instrument we can use.

Each graph can be written as a matrix, called incidence matrix.

00 - Graph 2024-10-10 16.18.33.excalidraw.png

We can represent a graph through a matrix in which every row represents a node, and each column represents a link (links are also numbered).

The graph above gives the following incidence matrix:

[100000010011011010000110000000001110001100001100000000001111]

Elements in a graph

Adjacency and Incidency

Forward star or Adjacency

forward star or adjacency of node $i$ ($e[i]$)

A forward star, or Adjacency of a node i, is the set of head nodes of links emanating from node i. It is designated by E[i].

For example, given the graph below:

00 - Graph 2024-10-10 16.12.25.excalidraw.png

the forward star of node 5 is

E[5]=2,3,7

Forward star - 00 - Graph 2024-10-24 12.48.02.excalidraw.png

By gathering the adjacency of all nodes, the number of links in A can be obtained:

|A|=|E[1]E[2]E[n]|

Incidency

incidency of node $i$

The incidency of node i is the set of tail nodes of links incoming to node i.

Out-degree and In-degree

outdegree of node $i$

The out-degree of node i is the number of elements in the [[#Forward star or Adjacency]] of that same node i.

|E[i]|

Path

A path is a chain of links, starting at node p and ending at a different node q.

Directed path

directed path

A directed path on a graph is a sequence of arcs
a1=(i1,j1),a2=(i2,j2),...,an=(in,jn)
so that
j1=i2,j2=i3,...,jn1=in

Given the following graph

00 - Graph 2024-10-10 16.12.25.excalidraw.png

a possible directed path si:

Directed path - 00 - Graph 2024-10-24 13.00.21.excalidraw.png

path=(1,2)(2,3)(3,6)(6,7)

Undirected path

undirected path

An undirected path on a graph is a sequence of arcs
a1=(i1,j1),a2=(i2,j2),...,an=(in,jn)
so that

j1=i2j1=j2i1=i2j2=i3j2=j3i2=i3jn1=injn1=jnin1=in

Given the graph

00 - Graph 2024-10-10 16.12.25.excalidraw.png

An undirected path can be:

Undirected path - 00 - Graph 2024-10-24 13.08.17.excalidraw.png

Undirected path=(1,2)(2,3)(5,3)(5,7)

Cycle

cycle

A cycle or directed cycle is a [[#Directed path]] with the additional condition
jn=i1

From the graph

00 - Graph 2024-10-10 16.12.25.excalidraw.png

a cycle is

cycle=(2,4)(4,5)(5,2)

There can also be undirected cycles, where the direction of links doesn't matter.

Connected nodes

connected nodes

Node-i is connected to node-j if there exits a [[#Directed path]] starting at i and ending at j.

Tree

tree

A tree is a special type of graph that contains no cycles.

It can be directed or undirected.

Trees have the following characteristic:
#nodes=#links1

observation

A [[#Path]] is always a tree. More specifically, a [[#Directed path]] is always a directed tree.

BUT

A tree is not necesseraly a [[#Path]]

!700
%%🖋 Edit in Excalidraw%%

Spanning tree

spanning tree

A spanning tree is a part of graph G, or subgraph, that contains all the same nodes of G but with only a subset of links, so that they forma an undirected [[#Tree]].

Spanning tree - 00 - Graph - MM 2024-10-28 15.45.05.excalidraw.png

Rooted spanning tree

There exist a node, called the root node, which is connected with any other node in the network.

Also, the undirected path from a root node to any other node in the tree is unique (it's a #Spanning tree).

Storing and retrieving paths

In a directed #Spanning tree, we can store paths in a simple matrix.

Storing and retrieving paths - 00 - Graph - MM 2024-10-30 11.30.32.excalidraw.png

This tree can be stored as an array p of pointers:

[index12345678p05121243]