幻灯片 1 - Sun Yat-sen University

Download Report

Transcript 幻灯片 1 - Sun Yat-sen University

Chapter 8. Topics in Graph
Theory
Weiqi Luo (骆伟祺)
School of Software
Sun Yat-Sen University
Email:[email protected] Office:A309
Chapter eight: Topics in Graph Theory






8.1. Graphs
8.2. Euler Paths and Circuits
8.3. Hamiltonian Paths and Circuits
8.4. Transport Networks
8.5. Matching Problems
8.6. Coloring Graphs
2
School of Software
8.1 Graphs
 Graph
A graph G=(V, E, γ) consists of a finite set V of objects
called vertices, a finite set E of objects called edges, and
a function γ that assigns to each edge a subset {v, w},
where v and w are vertices (and may be the same).
 End points
If γ(e)={v, w}, then vertices v and w are called the end
points of e.
3
School of Software
8.1 Graphs
 Example 1 & 2
Let V={1,2,3,4} and E={e1,e2,e3,e4,e5}. Let γ be
defined by γ(e1)= γ(e5)={1,2}, γ(e2)={4,3},
γ(e3)={1,3}, γ(e4)={2,4} .
Then G=(V,E,γ) is a graph.
Isomorphic Graphs
1
2
4
3
G
1
2
3
4
G
1
2
3
G
4
School of Software
4
8.1 Graphs
 Degree
The degree of a vertex is the number of edges having
that vertex as an end point.
 Loop
An edge is referred to as a loop if the edge is from a
vertex to itself.
Note: a loop contributes 2 to the degree of a vertex,
since that vertex serves as both end points of the loop.
 Isolated
A vertex with degree 0 is called an isolated vertex.
5
School of Software
8.1 Graphs
 Example 3
p
A
a
B
q
b
2
s
r
C
t
u
D
A: 2 B:4
C: 1 D: 3 E: 2
3 4
c
E
1
e
d
a: 4 b:2
c: 3 d: 1 e: 0
6
5
6
All edges with
degree 2
School of Software
8.1 Graphs
 Path in a Graph
A path п in a graph G consists of a pair (Vп, Eп) of
sequences: a vertex sequence Vп : v1, v2, …, vk and an
edge sequence E п :e1, e2,…,ek-1 for which
1. Each successive pair vi, vi+1 of vertices is adjacent in G,
and edge ei has vi and vi+1 as end points for i=1, …, k-1;
2. No edge occurs more than once in the edge sequence.
7
School of Software
8.1 Graphs
 Circuit (cycle)
A circuit is a path that begins and ends at the same
vertex.
 Simple
A path is called simple if no vertex appears more than
once in the vertex sequence, except possibly if v1=vk. In
this case, the path is called a simple circuit.
8
School of Software
8.1 Graphs
 Connected, Disconnected & Components
A graph is called connected if there is a path from any
vertex to any other vertex in the graph. Otherwise, the graph
is disconnected. If the graph is disconnected, the various
connected pieces are called the components of the graph.
p
A
2
5
B
q
3 4
s
r
C
E
1
Connected
t
6
Disconnected
Two components
u
D
9
School of Software
8.1 Graphs
Some important special families of graphs will
be useful in our discussions.
1. Un (discrete graph) denote the graph with n vertices
and no edges.
U2
U5
2. Ln (linear graph) denote the graph with n vertices and
with edges {vi,vj} for 1≤ i <n
L2
L5
10
School of Software
8.1 Graphs
3. Kn (complete graph) denote the graph with n vertices
and with an edge {vi, vj} for all i and j.
K2=L2
K3
K4
K5
 Regular
If each vertex of a graph has the same degree as every
other vertex, the graph is called regular.
e.g. Kn and Fig. 8.6
11
School of Software
8.1 Graphs
 Subgraph
Support that G=(V, E, γ) is a graph. Choose a subset E1
of the edges in E and a subset V1 of the vertices in V, so
that V1 contains (at least) all the end points of edges in
E1. Then H=(V1,E1, γ1) is also a graph where γ1 is γ
restricted to edges in E1. Such a graph H is called a
subgraph of G.
12
School of Software
8.1 Graphs
 The subgraph Ge
Deleting one edge and no vertices
a
d
b
i
f
h
g
G
a
d
c
b
i
f
h
g
Ge
c
e={a,b}
13
School of Software
8.1 Graphs
 Example 8
a
b
i
f
i
f
h
g
h
g
b
d
i
f
h
g
d
c
d
c
a
c
G
d
14
b
i
f
h
g
c
School of Software
8.1 Graphs
 Example 9 (Quotient graph GR)
Let G be the graph (without multiple edges) of the
following figure, and let R be the equivalence relation on V
defined by the partition.
{{a, m, i}, {b, f, j}, {c, g, k}, {d, h, l}}
b
a
m
h
[a]
f
i
j
l
k
[b]
[j]
[h]
[k]
=
[d]
g
[c]
GR
d
[m]
GR
c
15
School of Software
8.1 Graphs
 Example 9
If S is also an equivalence relation on V defined by the
partition.
{{i, j, k, l}, {a, m},{f, b, c}, {d}, {g}, {h}}
a
b
m
h
d
[a]
f
i
j
l
k
[b]
[i]
[h]
[g]
g
c
[d]
16
GS
School of Software
8.1 Graphs
 The Quotient graph Ge
If e is an edge between vertex v and w in a graph G={V,E,
γ}, then we consider the equivalence relation whose
partition consists of {v, w} and {vi}, for each vi  v, vi  w.
(merging v and w and leaving others alone)
a
b
m
f
i
j
l
k
G
b
m
f
[i]
l
g
h
d
a
k
g
h
c
e={i, j}
d
17
Ge
School of Software
c
8.1 Graphs
 Homework
Ex. 6, Ex. 16, Ex. 20, Ex. 22, Ex. 23, Ex. 29
18
School of Software
8.2 Euler Paths and Circuits
 Seven Bridges of Königsberg (from Wikipedia)
Question: Is it possible to walk through
the city that would cross each bridge
once and only once?
Vertex: Land
Edge: Bridge
19
School of Software
8.2 Euler Paths and Circuits
 Euler path
A path in a graph G is called an Euler path if it
includes every edge exactly once.
 Euler circuit
An Euler circuit is an Euler path that is a circuit.
About Leonhard Euler:
http://en.wikipedia.org/wiki/Leonhard_Euler
20
School of Software
8.2 Euler Paths and Circuits
 Example 1
21
School of Software
8.2 Euler Paths and Circuits
 Example 2
E
2
4
D
3
B
1
C
5
A
An Euler Path: E, D, B, A, C
An Euler circuit: 5, 3, 2, 1, 3, 4, 5
22
School of Software
8.2 Euler Paths and Circuits
 Example 2
E
D
2
5
3 4
B
C
1
6
A
Q: An Euler Circuit?
Q: An Euler Path?
A: No
A: No
23
School of Software
8.2 Euler Paths and Circuits
 Example 3
Vertex: Room or Outside
Edge: door
Q: Is it possible to begin in a room or outside and take a walk that goes
through each door exactly once?
24
School of Software
8.2 Euler Paths and Circuits
 Two Questions
1. Is it possible to determine whether an Euler path or
Euler circuit exists without actually finding it?
Theorem 1 (Euler circuit) &
Theorem 2 (Euler path)
2. If exists Euler circuit, how to find it effectively?
Fleury’s algorithm
25
School of Software
8.2 Euler Paths and Circuits
 Theorem 1
(a) If a graph G has a vertex of odd degree, there
can be no Euler circuit in G
E
D
1
2 3 …
2n
1
2 3 …
2n
2n+1
B
C
2n+1
V of odd degree
V of odd degree
Begin at v
End at v
A
26
School of Software
8.2 Euler Paths and Circuits
 Theorem 1
(b) If G is a connected graph and every vertex has even
degree, then there is an Euler circuit in G.
The Strategy of this proof (b) :
Support there is a largest (smallest) object and construct
a larger (smaller) object of the same type thereby
creating a contradiction.
27
School of Software
8.2 Euler Paths and Circuits
 Proof (b)
Basic Step: |V|=1, 2 is true (why?)
Induction Step : |V|=1,2…k is true  |V|=k+1 is true
1. Assume G is connected and has more than one vertex, then
there exists a simple path having the longest possible length
(why?). Let its vertex sequence п0: v1 v2,…,vs.
Since vs has even degree and п0 uses only one edge that
has vs as a vertex, there must be an edge e not in п0 that also
has vs as a vertex.
If the other vertex of e is not in п0, then we can construct a
simple path longer than п0(why?), which is a contradiction.
Thus e has some vi as its other vertex, and therefore we
have a simple circuit vi vi+1, … vs, vi in G.
28
School of Software
8.2 Euler Paths and Circuits
2. Choose the longest circuit п in G, and delete all edges in п
(but no vertices).
Assuming there is no Euler circuits in G, then п cannot
contain all edges of G (why?).
Let G1 be the graph formed form G by deleting all edges in
п (but no vertices). Since п is a circuit, deleting its edges will
reduce the degree of every vertex by 0 or 2, so G1 is also a
graph with all vertices of even degree. Choose any connected
component in G1 and call this graph G2 (G2 may be G1).
Then G2 has also a circuit п’ (why?).
29
School of Software
8.2 Euler Paths and Circuits
3. Consider п and п’ in G
case #1: if п and п’ have vertices in common, e.g. v’, then we
can construct a circuit in G that is longer than п by combing п
and п’ at v’ (contradiction!)
case #1
v’
п
П’
Case #2: If there is no common vertex in п and п’. Then
|VG2| < |VG|, then G2 has a Euler Circuit (why? ) , then G
becomes not connected (why?) , which is a contradiction.
Therefore, the assumption is wrong, namely, G has Euler circuit.
30
School of Software
8.2 Euler Paths and Circuits
 Theorem 2
(a) If a graph G has more than two vertices of odd degree,
then there can be no Euler path in G
Proof: Let v1, v2, v3 be vertices of odd degree. Any possible
Euler path must leave (or arrive at) each of v1, v2, v3 with no
way to return (or leave) since each of these vertices has odd
degree. One vertex of these three vertices may be the
beginning of the Euler path and another the end, but this
leaves the third vertex at one end of an untraveled edge. Thus
there is no Euler path.
31
School of Software
8.2 Euler Paths and Circuits
 Theorem 2
(b) If G is connected and has exactly two vertices of odd
degree, there is an Euler path in G. Any Euler path in G
must begin at one vertex of odd degree and end at the other.
Proof: Let u and v be the two vertices of odd degree. Adding
the edge {u, v} to G produces a connected graph G’ all of
whose vertices have even degree. By Theorem 1(b), there is an
Euler circuit п’ in G’. Omitting {u, v} from п’ produces an
Euler path that begins at u (or v) and ends at v (or u).
32
School of Software
8.2 Euler Paths and Circuits
 Example 4
Each of the four vertices has degree 3. No Euler path
and Euler circuit.
There has exactly two vertices of odd degree. There is no
Euler circuit, but there must be an Euler path.
Every vertex has even degree, thus the graph must have
an Euler circuit.
33
School of Software
8.2 Euler Paths and Circuits
 Bridge
An edge is a bridge in a connected graph G if deleting it
would create a disconnected graph.
p
A
B
q
r is a bridge
s
r
C
s is a bridge
E
t is a bridge
t
u
D
34
School of Software
8.2 Euler Paths and Circuits
 Algorithm FLEURY’S ALGORITHM
Let G={V,E,γ} be a connected graph with each vertex of even
degree.
Step 1 Select an edge e1 that is not a bridge in G. Let its vertices be v1, v2. Let
п be specified by Vп: v1, v2 and Eп: e1. Remove e1 from E and let G1 be
the resulting subgraph of G.
Step 2 Suppose that Vп: v1, v2 … vk and Eп: e1 e2 … ek-1 have been
constructed so far, and that all of these edges and any resulting isolated
vertices have been removed from V and E to form Gk-1.
Since vk has even degree, and ek-1 ends there, there must be an edge ek in
Gk-1 that also has vk as a vertex. If there is more than one such edge, select
one that is not a bridge for Gk-1. Denote the vertex of ek other than vk by
vk+1, Extend Vп: v1, v2 … vk vk+1 and Eп: e1 e2 … ek-1 ek.
Step 3 repeat Step 2 until no edges remain in E
35
School of Software
8.2 Euler Paths and Circuits
 Example 6
Use Fleury’s algorithm to construct an Euler circuit for the
following graph.
B
A
F
C
E
G
H
D
36
School of Software
8.2 Euler Paths and Circuits
 Homework
Ex. 6, Ex. 12, Ex. 14, Ex. 15, Ex. 21, Ex. 25
37
School of Software
8.3 Hamiltonian Paths and Circuits
 Hamiltonian path
A Hamiltonian path is a path that contains each vertex
exactly once.
 Hamiltonian circuit
A Hamiltonian circuit is a circuit that contains each vertex
exactly once except for the first vertex.
38
School of Software
8.3 Hamiltonian Paths and Circuits
 Loop and Multiple edges
Loops and multiple edges are of no use in finding Hamiltonian circuits, since loops
Could not be used, and only one edge can be used between any two vertices.
Thus we support that any graph in this section has no loops or multiple edges.
39
School of Software
8.3 Hamiltonian Paths and Circuits
 An Example for Hamiltonian circuit
40
School of Software
8.3 Hamiltonian Paths and Circuits
 Example 1
2
5
d
c
3 4
1
e
6
Has Hamiltonian path
But no Hamiltonian circuit
b
B
A
a
A
E
B
Has Hamiltonian path
& Hamiltonian circuit
D
C
A
E
No Hamiltonian Path
41
School of Software
8.3 Hamiltonian Paths and Circuits
 Example 2
Any complete graph Kn has Hamiltonian circuits? In
fact, starting at any vertex, you can visit the other
vertices sequentially in any desired order.
K3
K4
K5
Q: How about K2?
n should be larger than 2
K2
42
School of Software
8.3 Hamiltonian Paths and Circuits
 Two Questions
1. Is it possible to determine whether a Hamiltonian path
or circuit exists?
has not been completely answered
2. If there must be a Hamiltonian path or circuit, it there
an efficient way to find it?
is still unanswered.
43
School of Software
8.3 Hamiltonian Paths and Circuits
 Theorem 1
Let G be a connected graph with n vertices, n>2, and no
loops or multiple edges.
G has a Hamiltonian circuit if for any two vertices u
and v of G that are not adjacent, the degree of u plus the
degree of v is greater than or equal to n.
Corollary 1
G has a Hamiltonian circuit if each vertex has degree
greater than or equal to n/2.
44
School of Software
8.3 Hamiltonian Paths and Circuits
 Theorem 2
Let the number of edges of G be m. Then G has a Hamiltonian
circuit if m ≥ (n2-3n+6)/2, where n is the number of vertices
Proof: Support u & v are non-adjacent vertices in G. Let deg(x)
for the degree of x. Let H be the graph produced by eliminating
u and v from G along with any edges that have u or v as end
points. Then H has n-2 vertices and m- deg(u) –deg(v) edges.
The maximum number of edges that H could possibly have is
Cn2 2 
(n  2)(n  3) 1 2
 (n  5n  6)
2
2
And then we have m – deg(u)-deg(v) <= ½(n2-5n+6 )
thus deg(u) +deg(v) >= n (Theorem 1 holds)
45
School of Software
8.3 Hamiltonian Paths and Circuits
 Example 3
A
|V| = 8
H
B
G
C
F
D
E
For any pair of nonadjacent vertices u and v
deg(u) + deg(v) = 4 < 8
Therefore, the conditions given in Theorem
1 & 2 are sufficient, but not necessary,
for the conclusion.
A Hamiltonian Circuit
46
School of Software
8.3 Hamiltonian Paths and Circuits
 Traveling salesperson problem
Find a Hamiltonian circuit (or path) for which the total
sum of weights in the path is a minimum.
For example, the vertices might represent cities, the
edges, lines of transportation, and the weight of an
edge, the cost of traveling along the edge.
B
D 2
6
3
2
2
A
H
5 E
C
5 4
F
6
3
4
47
G
School of Software
8.3 Hamiltonian Paths and Circuits
 Homework
Ex. 8, Ex. 13, Ex. 18, Ex.20, Ex. 21
48
School of Software
8.4 Transport Networks
 Transport network
A transport network (or network) is a connected diagraph N
with the following properties:
a) There is a unique node, the source, that has in-degree 0,
labeled the source node 1;
b) There is a unique node, the sink, that has out-degree 0.
labeled as the sink node n if N has n nodes;
c) The graph N is labeled. The label, Cij, on edge (i, j) is a
nonnegative number called the capacity of the edge.
4
Here, if (i, j) in N,
then (j, i) is not
1
Source 5
4
5
3
4
2
2
3
2
49
3
3
6
Sink
School of Software
8.4 Transport Networks
 Flows
A flow in a network N is a function that assigns to each edge
(i, j) of N nonnegative number Fij that does not exceed Cij.
Fij denotes the amount of material passing through the edge
(i,j) when the flow is F.
we also require that for each node k must equal to the sum
of the Fkj on edges leaving node k (conservation of flow).
2+1=3
(Cij, Fij )
3+0=3
(3,3)
(4,2)
1
4
(2,1)
(5,3)
2
5
(4,3)
(2,0)
(3,2)
(3,2)
6
Value of the flow (value(F))
The sum of the flows leaving
the source or entering the sink
value(F)=5 in this example
3
50
School of Software
8.4 Transport Networks
 Example 2
(6,4)
1
2
(6,6)
(2,2)
(4,4)
(6,6)
1
4
3
value(F)= 4+4 = 6+2 = 8
<
(6,6)
(2,0)
(4,4)
(4,2)
2
4
3
(4,4)
value(F)= 6+4 = 6+4 = 10
In the first figure, there is a mistake for using the edge from node 3 to 2.
Maximum flows problem:
how to determine the maximum value of a flow though the network
and to describe a flow that has the maximum value
51
School of Software
8.4 Transport Networks
 Virtual flow
2
(6,4)
1
(2,2)
(4,4)
(6,4)
1
Symmetric
Closure
(6,6)
1
4
2
(6,6)
(2,2)
(4,4)
(4,2)
3
(6,4)
4
3
(4,2)
2
(2,2)
(2,2)
3
4
(4,2)
If there is a virtual flow of 2 units through edge
(2,3), then we can increase the flows though edge
(1,2) and (3,4) by 2 units.
Virtual Path п: 1 2  3 4
52
School of Software
8.4 Transport Networks
Let N be a network and let G be the symmetric closure
of N. Choose a path in G and an edge (i, j) in this path.
case # 1:
(i, j) is in N, then we say this edge has positive excess
capacity if eij=Cij-Fij>0.
case #2:
(i, j) is not in N, i.e. virtual flow, we say (i, j) has
excess capacity eij= Fji if Fji>0.
Then increasing flow through edge (i, j) will have the
effect of reducing Fji , note (j, i) in N.
53
School of Software
8.4 Transport Networks
 Labeling algorithm
Step 1: Let N1 be the set of all nodes connected to the source by an
edge with positive excess capacity. Label each j in N1 with [Ej, 1]
where Ej is the excess capacity e1j of edge (1, j). The 1 in the label
indicates that j is connected to the source, node 1.
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=5
e21=0
e45=3 e54=0
e56=4
e65=0
5
6
e25=2
e52=0
2
[5, 1]
N1= {2, 4}
e36=3
e63=0
3
e23=3 e32=0
54
School of Software
8.4 Transport Networks
Step 2: Let node j in N1 be the node with smallest node number and let
N2(j) be the set of all unlabeled nodes, other than the source, that are
joined to node j and have positive excess capacity. Suppose that node k
is in N2(j) and (j, k) is the edge with positive excess capacity. Label
node k with [Ek, j] where Ek is the minimum of Ej and the excess
capacity ejk of edge (j,k). When all the nodes in N2(j) are labeled in this
way, repeat this process for the other nodes in N1. Let N2=Uj in N N2(j).
1
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=5
e21=0
e45=3 e54=0
[2, 2]
e56=4
e65=0
5
6
e25=2
e52=0
2
[5, 1]
N2 = {3, 5}
e36=3
e63=0
3
e23=3 e32=0
j=2
[3, 2]
55
School of Software
8.4 Transport Networks
Step 3: Repeat Step 2, labeling all previously unlabeled nodes N3 that
can be reached form a node in N2 by an edge having positive excess
capacity. Continue this process forming sets N4, N5,…, until after a
finite number of steps either
(i) the sink has not been labeled and no other nodes can be labeled. It
can happen that no nodes have been labeled;
(ii) the sink has been labeled.
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=5
e21=0
e45=3 e54=0
[2, 2]
e56=4
e65=0
5
e25=2
e52=0
2
[5, 1]
e36=3
e63=0
3
e23=3 e32=0
[3, 3]
6
[3, 2]
56
School of Software
8.4 Transport Networks
For case (i):
the algorithm terminates and the total flow then is a maximum flow
For case (ii):
the sink has been labeled with [En, m], where En is the amount of extra
flow that can be made to reach the sink though a path п.
Examine п in reverse order.
If edge (i. j) in N, decrease the excess capacity eij by the same amount,
and increase eji (virtual edge) by En.
Return to Step 1.
57
School of Software
8.4 Transport Networks
Case (ii)
П:1236
Update eij & eji in П
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=5
e21=0
e45=3 e54=0
[2, 2]
e56=4
e65=0
5
e25=2
e52=0
2
[5, 1]
e36=3
e63=0
3
e23=3 e32=0
[3, 3]
6
[3, 2]
58
School of Software
8.4 Transport Networks
Case (ii)
П:1236
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=2
e21=3
e45=3 e54=0
[2, 2]
e56=4
e65=0
5
e25=2
e52=0
2
[5, 1]
e36=0
e63=3
3
e23=0 e32=3
[3, 3]
6
[3, 2]
59
School of Software
8.4 Transport Networks
Repeat Step 1
consider node 1
Note: E2 is now only 2 (e12=2)
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=2
e21=3
e45=3 e54=0
e56=4
e65=0
5
6
e25=2
e52=0
2
[2, 1]
e36=0
e63=3
3
e23=0 e32=3
60
School of Software
8.4 Transport Networks
Repeat Step 2:
consider node 2
Node 2 can no longer be used to label node 3, since e23=0
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=2
e21=3
e45=3 e54=0
[2, 2]
e56=4
e65=0
5
6
e25=2
e52=0
2
[2, 1]
e36=0
e63=3
3
e23=0 e32=3
61
School of Software
8.4 Transport Networks
Repeat Step 2:
consider node 5
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=2
e21=3
e45=3 e54=0
[2, 2]
e56=4
e65=0 [2, 5]
5
6
e25=2
e52=0
2
[2, 1]
e36=0
e63=3
3
e23=0 e32=3
62
School of Software
8.4 Transport Networks
Repeat Step 2:
consider node 5
Case (ii) occurs
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=2
e21=3
e45=3 e54=0
[2, 2]
e56=4
e65=0 [2, 5]
5
6
e25=2
e52=0
2
[2, 1]
e36=0
e63=3
3
e23=0 e32=3
63
School of Software
8.4 Transport Networks
Case (ii)
П:1256
Update eij & eji in П
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=0
e21=5
e45=3 e54=0
[2, 2]
e56=2
e65=2 [2, 5]
5
6
e25=0
e52=2
2
[2, 1]
e36=0
e63=3
3
e23=0 e32=3
64
School of Software
8.4 Transport Networks
Repeat Step 1:
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=0
e21=5
e45=3 e54=0
e56=2
e65=2
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
65
School of Software
8.4 Transport Networks
Repeat Step 2:
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=0
e21=5
e45=3 e54=0
[3, 4]
e56=2
e65=2
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
66
School of Software
8.4 Transport Networks
Case (ii)
П:1456
Update eij & eji in П
[4, 1]
e14=4
e41=0
4
e24=2
e42=0
1
e12=0
e21=5
e45=3 e54=0
[3, 4]
e56=2
e65=2 [2, 5]
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
67
School of Software
8.4 Transport Networks
Case (ii)
П:1456
[4, 1]
e14=2
e41=2
4
e24=2
e42=0
1
e12=0
e21=5
e45=1 e54=2
[3, 4]
e56=0
e65=4 [2, 5]
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
68
School of Software
8.4 Transport Networks
Repeat Step 1
[2, 1]
e14=2
e41=2
4
e24=2
e42=0
1
e12=0
e21=5
e45=1 e54=2
E56=0
e65=4
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
69
School of Software
8.4 Transport Networks
Step 2
[2, 1]
e14=2
e41=2
4
e24=2
e42=0
1
e12=0
e21=5
e45=1 e54=2
[1, 4]
E56=0
e65=4
5
6
e25=0
e52=2
2
e36=0
e63=3
3
e23=0 e32=3
70
School of Software
8.4 Transport Networks
Step 3
label node 2 using virtual edge (5, 2)
case (i) occurs
[2, 1]
e14=2
e41=2
4
e24=2
e42=0
1
e12=0
e21=5
e45=1 e54=2
[1, 4]
E56=0
e65=4
5
6
e25=0
e52=2
2
[1, 5]
e36=0
e63=3
3
e23=0 e32=3
71
School of Software
8.4 Transport Networks
Case (i)
e14=2
e41=2
4
e45=1 e54=2
e24=2
e42=0
1
e12=0
e21=5
6
3
e36=0
e63=3
5
4
e23=0 e32=3
4
2
2
0
5
E56=0
e65=4
e25=0
e52=2
2
2
1
5
2
6
3
3
3
72
School of Software
8.4 Transport Networks
 Cut
A cut in a network N as a set K of edges having the
property that every path from the source to the sink
contains at least one edge from K.
Therefore, a cut can “cut” a network into two pieces,
one containing source and one containing the sink.
If the edges of a cut were removed, noting flow from
the source to the sink.
 Capacity of a cut
The capacity of a cut K, c(K) is the sum of the
capacities of all edges in K.
73
School of Software
8.4 Transport Networks
 Example 4
4
4
1
Cut K1
5
4
6
2
2
5
3
2
3
3
c(K1)=10
3
Cut K2
c(K2)=7
74
School of Software
8.4 Transport Networks
 If F is any flow and K is any cut, then
value(F) ≤ c(K)
since all parts of F must pass though the edges of K.
 If some flow F and some cut K, value(F)=c(K), then the
flow F uses the full capacity of all edges in K.
Then F would be a flow with maximum value, since no
flow can have value bigger then c(K).
Similarly, K must be a minimum capacity cut, since
every cut must have capacity at least equal to value(F).
75
School of Software
8.4 Transport Networks
 Theorem 1: The Max Flow Min Cut Theorem
A maximum flow F in a network has value equal to the
capacity of a minimum cut of the network.
Proof:
Suppose the labeling algorithm has been run and stop at
case (i). Then the sink has not been labeled. Divide the
nodes into two sets,
M1 : the source and all nodes that have been labeled)
M2 : all unlabeled nodes except the source.
Let K consist of all edges of N that connect a node in
M1 with a node in M2
76
School of Software
8.4 Transport Networks
…
Source
Cut K
Labeled M1
Sink
Unlabeled M2
Suppose (i, j) is an edge in K, so that i in M1, j in M2. The
final flow F produced by the algorithm must result in (i,j)
carrying its full capacity; otherwise, we could use node i
and the excess capacity to label j.
Therefore, the value of the final flow of the algorithm is
equal to the capacity c(K), and so F is a maximum flow.
77
School of Software
8.4 Transport Networks
 Example
[2, 1]
e14=2
e41=2
4
e45=1 e54=2
e24=2
e42=0
1
e12=0
e21=5
[1, 4]
5
E56=0
e65=4
6
e25=0
e52=2
2
3
e23=0 e32=3
[1, 5]
e36=0
e63=3
K={e23, e56 } and both edges have their full capacities, 5 and 4, respectively
78
School of Software
8.4 Transport Networks
 Example 5
e14=2
e41=2
4
e45=1 e54=2
e24=2
e42=0
1
e12=0
e21=5
5
E56=0
e65=4
6
e25=0
e52=2
2
3
e23=0 e32=3
e36=0
e63=3
Cut K
Cut K={e56, e36 } with c(K)= 7= value(F)
79
School of Software
8.4 Transport Networks
 Homework
Ex, 4, Ex. 8, Ex. 13, Ex. 18
80
School of Software
8.5 Matching Problems
 Network with multiple sources & sinks
1
2
3
2
4
6
2
2
2
4
5
3
3
7
4
81
School of Software
8.5 Matching Problems
 Example 1
Set the new added edges with the sum of all capacities leaving sources o N
11
1
3
11
a
Super source
2
6
2
2
2
11
2
4
4
5
3
3
11
b
7
11
Super sink
4
N
Then the labeling algorithm can be used in the resulting network N’ to
find a maximal flow for the original one N
82
School of Software
8.5 Matching Problems
 Matching Problem
Let A and B be two finite sets, and R be a relation from A
to B. A matching function M is a one-to-one function from
a subset of A to a subset of B.
We say a is matched with b if M(a)=b.
A matching function M is compatible with R if M ⊆ R,
namely, if M(a)=b, then a R b.
 Maximal matching
Given any relation R from A to B, a matching M that is
compatible with R is called maximal if its domain is as
large as possible and is complete if its domain is A.
83
School of Software
8.5 Matching Problems
 Example 3
Let A be a set of girls and B a set of boys attending a
school dance. Define R by a R b if and only if a knows
b. A matching function M is defined from A to B by
M(a)=b if a and b dance the third dance together. M is
compatible with R if each girl knows her partner for the
third dance.
84
School of Software
8.5 Matching Problems
 Example 4
Let A={s1,s2,s3,s4,s5} be a set of students working on a
research project and B={b1,b2,b3,b4,b5} be a set of
reference books on reserve in the library for the project.
Define R by si R bk if and only if student si wants to
sign out book bk. A matching of students to books
would be compatible with R if each student is matched
with a book that he or she wants to sign out.
85
School of Software
8.5 Matching Problems
 Example 5
s1
b1
s2
b2
s3
b3
s4
b4
s5
b5
M(s1)=b2, M(s2)=b1, M(s3)=b3, M(s4)=b4
86
School of Software
8.5 Matching Problems
 Find a maximal matching
s1
b1
1
1
x
1
s2
s3
1
b2
1
s4
b3
s5
1
1
y
1
b4
1
1
1
b5
87
School of Software
8.5 Matching Problems
 A simplified version
[1,1]
(1,0 )
(1,0 )
2
[1,2]
4
(1,0 )
6
(1,0 )
1
(1,0 )
[1,4]
(1,0 )
(1,0 )
3
5
[1,1]
[1,2]
88
School of Software
8.5 Matching Problems
 A simplified version
(1,0 )
(1,0 )
2
4
(1,0 )
6
(1,0 )
1
(1,0 )
(1,0 )
(1,0 )
5
3
89
School of Software
8.5 Matching Problems
 A simplified version
(0,1 )
(0,1 )
2
4
(0,1 )
6
(1,0 )
1
(1,0 )
(1,0 )
(1,0 )
5
3
90
School of Software
8.5 Matching Problems
 A simplified version
Virtual Flow
[1,4]
(0,1 )
(0,1 )
2
[1,3]
4
(0,1 )
6
(1,0 )
1
(1,0 )
(1,0 )
(1,0 )
3
5
[1,1]
[1,2]
91
[1,5]
School of Software
8.5 Matching Problems
 A simplified version
(0,1 )
(0,1 )
2
4
(0,1 )
6
(1,0 )
1
(1,0 )
(1,0 )
(1,0 )
5
3
92
School of Software
8.5 Matching Problems
 A simplified version
(1,0 )
(0,1 )
2
4
(0,1 )
6
(0,1 )
1
(0,1 )
(0,1 )
(0,1 )
5
3
93
School of Software
8.5 Matching Problems
 A simplified version
(1,0 )
(0,1 )
2
4
(0,1 )
6
(0,1 )
1
(0,1 )
(0,1 )
(0,1 )
5
3
M(2)=5, M(3)=4
94
School of Software
8.5 Matching Problems
 Theorem 1 (Hall’s Marriage Theorem)
Let R be a relation from A to B. Then there exists a
complete matching M if and only if for each
X⊆A, |X|≤|R(X)|
We omit the proof of the result.
95
School of Software
8.5 Matching Problems
 Example 6
Let MR be the matrix of a marriage suitability relation
between five men and five woman. Can each man
marry a suitable woman?
w1 w2 w3 w4 w5
m1
m2
M R m3
m4
m5
11000 
 00011 


10100 


 00101 

 01010 

Way one: Use the enlarged network to find
a maximum flow
Way two: Use the Theorem 1
Let S be any subset of the men and E be the
set of edges that begin in S, then |E|=2|S|.
Each edge in E must terminate in a node of R(S).
But we know the number of edges terminating at
elements of R(S) is exactly 2|R(S)|.
Thus, 2|S| ≤2|R(S)| , and so |S| ≤ |R(S)|.
By theorem 1, there is a complete match.
96
School of Software
8.5 Matching Problems
 Homework
Ex. 7, Ex. 13, Ex. 16
97
School of Software
8.6 Coloring Graphs
 Coloring of the graph G
Suppose that G=(V,E,γ) is a graph with no multiple edges,
and C={c1,c2,…,cn} is any set of n “colors”. Any function f:
VC is called a coloring of the graph G using n colors. For
each vertex v, f(v) is the color of v.
 Proper coloring
A coloring is proper if any two adjacent vertices v and w
have different colors.
 Chromatic number of G ( χ (G) )
The smallest number of colors needed to produce a proper
coloring of a graph G is called the chromatic number of G
98
School of Software
8.6 Coloring Graphs
 Example 1
w
r
r
b
r
b
w
w
r
Solution 1 (3 colors)
Q: using two of fewer colors?
y
Solution 2 (4 colors)
Impossible in this example.
χ (G)=3
99
School of Software
8.6 Coloring Graphs
 The chromatic number of Kn
K3
K4
K5
χ(K3)=3
χ(K4)=4
100
χ(K5)=5
School of Software
8.6 Coloring Graphs
 Planar graph
The graph can be drawn in a plane so that no
edges cross except at vertices.
For example:
A
101
B
D
C
E
School of Software
F
8.6 Coloring Graphs
 Some examples of Planar graph
102
School of Software
8.6 Coloring Graphs
 Example for a non-planar graph
K5
103
School of Software
8.6 Coloring Graphs
 Four color theorem
 Refer to
http://en.wikipedia.org/wiki/Four_color_theorem
104
School of Software
8.6 Coloring Graphs
 Homework
Ex. 2, Ex. 4, Ex. 8
105
School of Software