Graph theory: basic concepts Graphs and networks allow modelling many different decision problems Graphs permit to represent relationships among different kinds of entities: Cities connected by roads Computers connected in a network People linked by family relationships Two persons sharing a room Connections among electronic components Graphs are a formal tool to model problems as Find the shortest path between two cities Determine the cheapest (most effectie) way of connecting a set of computers in a communication network Assign a set of jobs to a set of machines Find the routes for a fleet of ehicle to supply a set of customer in the most effectie way
Undirected graph An undirected graph G=(V, E) is defined by a pair of finite sets: V={ 1,..., n } set of n nodes (ertices) of G E={e 1,..,e m } V V set of m non directed arcs (edges) of G Each edge of G corresponds to an unordered pair of nodes of G e k =( i, j ) Nodes may be associated with entities and an edge denotes a relationship between two of them (e.g., two connected computers) Edges can represent roads, paths, physical connections (water or gas supply pipelines, electrical lines) and nodes can represent junction points (e.g., crossroads)
Example of undirected graph G =(V, E) 1 e 2 2 e 6 e 1 e 3 e 5 3 e 7 e 4 5 4 V = {,,, } E = { e, e, e, e, e, e e } 1 2 3 4, 5 (, ) e ( ) e = 1 = 1 5 2 1, 1 2 3 4 5 6, 2 7
Definitions An edge (,) is a loop Two nodes u, V are adjacent if it exists (u,) E u adjacent u not adjacent k k u h Not adjacent Two edges (u,),(,h) E are adjacent if they share a node An edge (u,) is defined by the pair of linked nodes A graph where more edges exist for a same pair of nodes is a multigraph u multigraph
Definitions (cont.) An edge connecting more than two nodes is an hyperedge Hyperedge (u,,k) u k In general a hyperedge is a subset of V Graphs including hyperedges are hypergraphs A graph without multiple edge, hyperedge and loop is a simple graph An edge f=(u,) E is incident on u and The node set N()={z V: z adjacent to } is the neighbourhood of in G u k s h N()={u,k,s,h}
Definitions (cont.) The set of edges δ()={e E: e incident on } is the star of in G u k e 1 e 2 δ() is the degree of node e 3 s h δ()={(u,),(k,),(,s),(,h)} or e 4 δ()={e 1, e 2, e 3, e 4 }
Subgraphs H=(W, F) is subgraph of G=(V,E) if W V and F E and such that if (u,) F then u, W 1 e 2 2 1 e 2 2 e 3 e 6 e 1 e 5 3 e 1 3 5 e 4 e 7 5 G=(V,E) 4 H=(W,F) subgraph of G
Subgraphs H=(W, F) is subgraph induced by W in G=(V, E) if W V and (u,) F implies that u, W and (u,) E 1 e 2 2 1 e 2 2 e 1 e 3 e 5 e 6 3 e 1 e 3 e 6 3 5 e 4 e 7 5 G=(V,E) 4 H=(W,F) subgraph of G induced by nodes in W
Subgraphs H=(W, F) is subgraph induced by F in G=(V,E) if (u,) F implies that (u,) E and u, W V 1 e 2 2 1 e 2 2 e 1 e 3 e 5 e 6 3 e 3 e 6 3 5 e 4 e 7 5 G=(V,E) 4 H=(W, F) subgraph of G induced by edge in F
Bipartite graph G=(V,E) is a bipartite graph if it exists a partition of V=V 1 V 2 such that: V 1 V 2 = e=(u,) E if u V 1 then V 2 otherwise if u V 2 then V 1 Bipartite graph V 1 V 2 Not Bipartite graph
Complete graph G=(V,E) is complete if it includes all possible edges, that is δ() =n-1 V where n= V Maximum number of edges for a non oriented complete graph n 2 = n( n 1) 2 Complete graph
Directed graph G=(V,A) directed graph is defined by a pair of finite sets: V={ 1,..., n } set of n nodes di G A={a 1,..,a m } V V set of m arcs of G where a j j=1,...,m is defined by an ordered pair of nodes In a directed graph a i =( k, h ) a j =( h, k ) a i, a j A 1 a 3 2 a1 a2 a 4 a 6 a 4 5 3
Directed graphs Arcs (directed links) are represented by arrows Tail u a Arc a=(u,) is incident on nodes u e : exiting from u and entering in Arcs are used when there is a direction in the relationship between nodes (e.g., one way road, direction of flow for a fluid) δ + ()={a A: a exiting from } set of arcs said forward star of δ - ()={a A: a entering in } set of arcs said backward star of Star of δ ()=δ + () δ - () δ + ()={(,s),(,h)} or δ + ()={a 3, a 4 } δ - ()={(u,),(k,)} or δ - ()={a 1, a 2 } u k a 1 a 2 Head a 3 a 4 s h
Directed graphs Definition of subgraph and induced subgraph are analogous to those for undirected graphs G=(V,A) directed graph is complete if it includes all the possible arcs, that is, δ + () = δ - () =n-1 V Maximum number of arcs for a directed complete graph n 2 = n( n 1) 2
Mixed graph G=(V,A E) is a mixed graph if the set of arcs includes both directed and undirected arcs Example: urban road networks are usually mixed graphs A complete (directed or undirected) graph is called clique Also complete subgraphs of a graph are denoted as cliques In a clique each node is adjacent to any other node in the clique Graph density: the ratio between the number of arcs and the maximum number of arcs m For undirected graphs D = n( n 1) / 2 0 D 1
Walks and Paths Gien an undirected graph G=(V, E) a walk in G is an ordered set of nodes W={ 0, 1,..., k } with k 1 ( 0 - k walk in G) if ( i 1, i ) E i=1,...,k Nodes 0 and k are the extremes of walk W Example W={ 0, 1, 2, 3, 4, 2 3, 4, 5 } 3 0 1 4 2 5
For directed G=(V, A) W={ 0, 1,..., k } with k 1 where ( i-1, i ) A i=1,...,k is an directed walk in G Length of W is the number of arcs in W Distance between two nodes u and is the minimum length of a walk from u to Example 1 a1 a2 a 3 a 4 2 a 6 a 5 4 3 W={ 1, 4, 3, 2 } walk W ={ 1, 4, 1, 4, 2, 3 } directed walk
Gien an undirected G=(V, E), simple walk or path in G, P={ 0, 1,..., k } is a walk such that all included nodes and arcs are distinct Example P={ 0, 1, 2, 3, 4, 5 } 3 0 1 4 2 5
For a directed G=(V, A), a directed path in G, P={ 0, 1,..., k } is a directed walk isiting its nodes only once Example 1 a1 a2 a 3 a 4 2 a 6 a 5 4 3 P={ 1, 4, 2, 3 } directed path An apparent property: If a (directed) walk between u and exists, then also a simple (directed) walk between u and exists
A walk W={ 0, 1,..., k, 0 } is said closed walk A simple closed walk is said cycle or circuit Example (closed walk) 6 1 5 4 3 2 Example (cycles) directed
Connected graphs and connected components Gien G=(V, E) a node V is connected to a node z V if a (undirected or directed) walk exist between and z in G Example: mixed graph where connected to z but not connected to h z walk z h A node V is connected to itself (reflectiity) If V is connected to z V then z is connected to (symmetry) If V is connected to z V and z is connected to u V then is connected to u (transitiity)
The set of node V can be partitioned according to the property of connectionin subsets C i C i ={ V: is connected to z, z C i } The sub-graph induced by C i in G is said connected component of G If G includes a single connected component it is a connected graph ( V, z Vis connected to z) Example Non connected graph Connected components Connected graph
In a directed graph G=(V, A), V is strongly connected to z V if two directed walks exist in G, the first from to z and the second from z to Strong connectiity extends connectiity taking into account the direction of arcs Example and z strongly connected z and z not strongly connected z A directed graph can be partitioned in strongly connected components, i.e., subsets C i C i ={ V: is strongly connected to z, z C i } In a strongly connected component, each node is connected to any other node by a directed walk
A graph is strongly connected if it includes a single strongly connected component Example Strongly connected components Strongly connected graph
Graph theory: trees Definition A graph is acyclic if it does not contain any (directed or undirected) cycle Example Acyclic Not acyclic Lemmas: Any connected graph with n nodes contains at least n-1 arcs Any acyclic graph with n nodes includes at most n-1 arcs For any graph if two among the following properties hold, then the third property is implied : The graph is acyclic The graph is connected The graph contains n-1 arcs
Graph theory: trees Definizione A tree is an acyclic connected graph Any node of a tree with δ() =1 is said leaf Example Leaes Non acyclic connected graph Tree
Graph theory: trees Definition A forest is a not connected acyclic graph (each connected component is a tree) Example Connected components = trees Not connected acyclic graph = forest
Graph theory: trees Gien G=(V, E) the following statements are equialent: G is a tree Any pair of nodes in G is connected by a unique path G is acyclic and E = V -1 G is acyclic and connecting two not adjacent nodes a single cycle is closed in the graph G is connected and E = V -1 The number of edges in a forest with k connected components is n-k If in a tree V =n 2 then at least two leaes exist A Spanning Tree (ST) of G=(V, E) is a tree T=(W,F) withw=v and F E, i.e., a sub-graph of G Example A spanning tree A ST always exists for connected graphs
Hamiltonian and Eulerian paths and cycles Defintion Gien G=(V, E) a Hamiltonian path is a path isiting all the nodes in V exactly once A Hamiltonian circuit (also called tour) is a closed Hamiltonian path A graph is said Hamiltonian if it includes a Hamiltonian circuit Example Hamiltonian path 2 3 4 Hamiltonian cycle 1 5
Hamiltonian and Eulerian paths and cycles Related problems: Determine if a graph includes a Hamiltonian path/cycle (hard problem) Gien a complete graph, whose arcs hae an associated length, determine the shortest Hamiltonian circuit: the well-known Traelling Salesman s Problem (TSP): A traelling salesman must isit n customers in n different cities starting and ending the tour at her/his city of residence In which sequence she/he must isit the customers if she/he wants to minimize the total distance coered?
Hamiltonian and Eulerian paths and cycles Problems associated with TSP Transportation problems: determine the best route for a ehicle or a fleet of ehicles in order to sere a demand located in a set of nodes of a graph representing a road network Many operational conditions: Capacity of ehicles and capacity required by demand Time windows (for arrial at nodes) Maximum tour duration (driers shifts) Pick-up and deliery serice Single or multiple depots Multiple ehicles with capacity = Vehicle Routing Problem (VRP) 10 11 1 9 4 6 0 Example of VRP solution 3 5 7 2 12 8
Hamiltonian and Eulerian paths and cycles Why a complete graph is assumed for TSP? For TSP (or VRP) the arcs of the graph do not represent a road network but the possibility to trael from one node to another (through a path) The graph is complete since such possibility in transportation is always true The cost/distance associated with each arc = shortest path between any pair of nodes distances (costs) i h 3 2 (not complete) road network k 2 1 j Shortest paths distances (costs) i h 3 2 3 k 2 1 Associated complete graph j
Hamiltonian and Eulerian paths and cycles Example: a scheduling problem that can be modelled as TSP Find the sequence for a set of manufacturing operations (jobs) on a machine so that it completes as soon as possible The processing times of the jobs are fixed A setup (e.g., cleaning) operation is needed between two successie jobs whose duration depends on the pair of jobs Example: a painting machine Blu painting setup Green painting Minimizing total duration = minimizing the total setup time Model: TSP on a complete graph Arc length = setup time
Hamiltonian and Eulerian paths and cycles Definition Gien G=(V, E) an Eulerian path is a path that isits all the arcs in E exactly once An Eulerian circuit is a closed Eulerian path A graph is Eulerian is it contains an Eulerian circuit Example 8 1 2 5 6 3 7 4
Hamiltonian and Eulerian paths and cycles The problem of finding an Eulerian path was defined by Euler in 1736 and presented at Saint Petersburg Academy as: In the city of Könisberg there is an island called Kneiphof around which flow the two branches of the Pregel Rier. There are seen bridges a, b, c, d, e, f, g which cross the two branches. The question is whether a person can choose a walk that leads to cross each bridge once but no more than once. Königsberg capital of Eastern Prussia Since the end of World War II Königsberg became Russian with the name of Kaliningrad
Hamiltonian and Eulerian paths and cycles A Pregel rier with its 7 bridges Pregel rier B C D A The model is a multigraph B C The problem: Is this graph Eulerian? D Euler found that there is no path with such property and deried the necessary and sufficient conditions for a undirected graph be Eulerian
Hamiltonian and Eulerian paths and cycles Theorem An undirected connected graph G=(V, E) is Eulerian if and only if eery node has een degree Theorem An undirected connected graph G=(V, E) contains an Eulerian path if eery node has een degree with the exception of two nodes s and t. Then the extremes of the Eulerian path are s and t. Exercise: which are the conditions for a directed graph to be Eulerian?
Hamiltonian and Eulerian paths and cycles The Chinese Postman Problem (CPP) CPP is the problem associated with Eulerian circuits as TSP is the one associated with Hamiltonian circuits : A postman has to delier mail to all the houses located on the streets of his neighbourhood. Its objectie is to complete its job coering the shortest distance, i.e., aoiding as much as possible to pass more than once along the same street. If the graph that model the map of the streets is Eulerian the postman does not need to pass more the once on each street Otherwise, the problem consists in finding how to complete the tour passing more then once only on the needed most conenient streets CPP each edge must be isited at least once so that the tour has the minimum length Examples of applications Mail deliery Urban waste collection (power, phone) lines inspection Transport of containers in logistic terminal
Incidence matrix of graphs It allows to represent the graph structure Two cases: undirected and directed graphs Facoltà di Ingegneria Undirected graphs Gien G=(V,E) undirected graph, A G =[a ij ], with i=1,...,n and j=1,...,m is the incidence matrix of G, where n= V and m= E, and such that 1 if e j incident on i aij = 0 otherwise Example e 2 1 e2 e3 e4 e5 1 1 0 0 0 1 e 1 e 2 0 1 1 0 0 e 5 e A 3 G = 1 0 1 1 0 0 1 0 1 1 4 e 4 3 1 2 3 4
Incidence matrix of graphs Gien the incidence matrix A G =[a ij ] the sum of non zero elements in a row gies the degree of the node associated with such row δ ( i ) = a ij Facoltà di Ingegneria The star of a node i can be defined as δ ( i ) = { e j E : aij = 1} Incidence matrices satisfy the necessary conditions for TUM (the elements must be 0, -1 or 1) A sufficient condition for an incidence matrix to be TUM is that the associated graph is bipartite A graph is bipartite if it does not contain odd cycles m j = 1 1 2 e 1 1 2 5 e 5 e 6 2 e 8 e6 e 3 8 e 7 4 e 4 7 3 6 8 3 5 7 4
Incidence matrix of graphs Directed graphs Facoltà di Ingegneria Gien G=(V,A) directed graph, A G =[a ij ], with i=1,...,n and j=1,...,m is the incidence matrix of G, where n= V and m= A, and such that a ij = 1 1 0 Using the incidence matrix we can define: δ + ( i )={a j A: a ij =1} (forward start) δ - ( i )={a j A: a ij =-1} (backward star) e 5 4 1 if i is head of a j (enters in if i is tail of a j (exits from otherwise 2 e 1 e 2 e 3 e 4 3 A G e 1 0 = 1 0 0 1 0 1 0 1 1 0 1 e2 e3 e4 e5 0 0 i i 1 1 ) ) 1 0 0 1 1 2 3 4
Adjacency matrix of graphs An alternatie representation of the graph structure Undirected graphs Facoltà di Ingegneria Gien G=(V,E) undirected graph, D G =[d ij ], with i=1,...,n and j=1,...,n is the adjacency matrix of G, where n= V and such that d ij = 1 if i is adjacent t o j 0 otherwise The matrix has n 2 elements and 2m non zero elements The sum of non zero elements in a row proides the degree of the node For undirected graphs the matrix is symmetric
Adjacency matrix of graphs Directed graphs Facoltà di Ingegneria Gien G=(V,A) directed graph, D G =[d ij ], with i=1,...,n and j=1,...,n is the adjacency matrix of G such that d ij = 1 if ( i, j ) A 0 otherwise The matrix is no more symmetric The sum of non zero elements in a row gies the number of arcs of the forward star of the associated node The sum of non zero elements in a column gies the number of arcs of the backward star of the associated node The number of not null elements of the matrix is m