Optimization on Graphs
Definition
Graph G is a pair (V,E)
V = set of vertices (or nodes)
E = set of edges (or arcs, A)
Graphs can be used to represent decision
problems:
• problems of path choices
• connectivity problems in networks
1
Example: road network
• Vertices: intersections
• Arcs and edges: road links (directed and
undirected)
2
Example: social network
3
Example: geographical network
Given a map, determine the minimum number
of colors required to color the different regions
so that adjacent ones have different colors
4
Simple and multiple graphs
• Simple: (at most) one edge between two vertices
5
• Multiple Graphs: more edges between two vertices
We will consider only simple graphs:
every multiple graph can be transformed into an
equivalent simple one (by adding 1 edge and 1 vertex)
Undirected Graphs (symmetric)
• G = (V,E) V= n E= m
• Vertices V = v1 , … , vn
• Edges E = e1 , … , em
ek = (vi , vj ) (vj , vi ) vertex pairs
e1
v1 v2
V = v1 , v2 , v3 , v4
e4 e5 e2
E = e1 , e2 , e3 , e4 , e5
v4
e3
v3 = (v1 ,v2), (v2 ,v3), ...
6
Directed Graphs (asymmetric)
• G = (V,A) V= n A= m
• Vertices V = v1 , … , vn
• Arcs A = a1 , … , am
ak = (vi , vj ) (vj , vi ) ordered pairs
vi tail, vj head
a1
v1 v2
V = v1 , v2 , v3 , v4
a4 a6 a5 a2 A = a1 , a2 , a3 , a4 , a5 , a6
= ... (v1 ,v4),..., (v4 ,v1)
v4 v3
a3
7
Weighted graphs
Weighted Graph (directed/undirected) :
each edge (arc) is associated with a
weight (cost, length, ...)
5
vj vk
c(vj , vk ) = c(ai) = cjk = 5
A graph can also have a value associated
with each edge (arc) representing a
capacity, i.e. the maximum amount that
can flow along the edge (arc)
8
Adjacent vertices, edges and arcs
• vi e vj are adjacent if (vi , vj )E ( A )
v1 v2 v3 v1 v2 v3
• two edges are adjacent (consecutive) if they have a
common vertex
• two arcs are adjacent (consecutive) if the head of
the first coincides with the tail of the second
v1 v2 v3
v1 v2 v3 v1 v2 v3
9
Star and degree for undirected graphs
• Star of v (v) = vj :(v , vj ) E
• Degree of v d(v) = (v)
v1 v2 (v2) = v1 , v3
d(v2) = 2
(v3) = v1 , v2 , v4
v4 v3
d(v3) = 3
10
Star and degree for directed graphs
• Forward star of v +(v) = vj :(v,vj )A
• Backward star of v -(v) = vj :(vj ,v)A
• external degree of v d+(v) = + (v)
• internal degree of v d-(v) = - (v)
v1 v2 +(v3) = v4
-(v3) = v1 , v2
d+(v3) = 1
v4 v3 d-(v3) = 2
11
Complete graph
G is complete if vi,vj V, (vi ,vj )E
(with/without loops)
Loops: edges or arcs (vi , vi ) vi
Subgraph G’ = (V’,E’) with V’ V, E’ E
12
Cut for undirected graphs
Given S V, cut associated with S:
(S) = (vi , vj ): S vi , vj = 1
v5
S = v1 , v4 , v5
v4 v2 (S) = (v2 ,v5 ), (v2 ,v4 ), (v1 ,v3)
S
v1 v3
13
Cut for directed graphs
Given SV, directed cut associated with S
+(S) = (vi , vj ) : vi S, vj S
-(S) = (vi , vj ) : vi S, vj S
+(S) -(V \ S)
Internal Arcs (S) = (vi,vj ): viS, vjS
v4 v2 S = v1 , v4 (S) = (v1 , v4 )
+(S) = (v4 ,v2)
v1 v3 -(S) = (v3 ,v4), (v3 ,v1)
14
Path and Cycles
Path:
sequence of consecutive edges (arcs) with no
vertex repetitions
vj1 vj2 vj3 vj4 vj5
(vj1 ,vj2), (vj2 ,vj3), (vj3 ,vj4), (vj4 ,vj5)
Cycle (circuit): path that starts and ends in the
same vertex
15
Acyclic and connected graphs
Acyclic Graph: without cycles
Connected Graph: vi , vj V path from vi to vj
An undirected G is not connected
it is made by separate connected components
16
Tree and Spanning Tree
• A tree is an undirected graph that is connected and does not
contain cycles.
• A tree is an undirected graph that is connected and has n-1
edges.
• For any two distinct vertices u and v of a tree, there exists a
unique path from u to v.
• A spanning tree of 𝐺 = (𝑉, 𝐸) is a subgraph 𝐺’ = (𝑉, 𝐸’) with
𝐸 ′ ⊆ 𝐸 that is a tree.
• Therefore:
a) 𝐺’ is connected
b) 𝐺’ does not contain cycles
c) |𝐸’| = n-1
17
Data structures for graphs
Dense Graphs (m n2)
Unweighted: adjacency Weighted: weight
matrix [aij] (n n) matrix [cij] (n n)
aij = 1 if (vi , vj ) A ( E) cij = c(vi,vj ) if (vi,vj ) A (E)
0 otherwise otherwise
[aij], [cij] are symmetric for undirected graphs
Example
10
v1 v2
31 12
22 6
v4 v3
9
0 1 1 1 10 31 22
0 0 1 0 12
aij = cij =
0 0 0 1 9
1 0 0 0 6
19
Data structures for graphs
Sparse Graphs (m n2)
It is better to store only the exisiting arcs.
Forward star method:
10
v1 v2 c' = 10 31 15 12 9 6
15
31 12
6 u' = 2 3 1 3 4 1
v4 v3
9
p' = 1 3 5 6 7
Data structures for graphs
Sparse Graphs (m n2)
Forward star method for weighted graphs uses:
• vector p(n+1) of pointers: p1=1, pn+1 =m+1
• vector u(m) of indices: indices of the vertices v for which
arc (vi ,v) exists
• vector c(m) of arc weights: ck = weight of the arc
corresponding to uk
For unweighted graphs, the forward star does not contain
the last vector.
Optimization on Graphs
• Optimization problems modelled on graphs
• Three main problems:
• Minimum Spanning Tree (Shortest Spanning
Tree) problem
• Shortest Path problem
• Maximum Flow problem
22