graph

Maximum Flows

A network is a type of graph that can be used to represent water flow through pipes (or maybe packets through cat5e cables).
MaximumFlows

A network has one vertex (source) with no incoming edges and one vertex (sink) with no outgoing edges. Each edge has a capacity associated with it.

A flow is a real function that assigns a number to each edge of the network that meets these two conditions:
  1. The flow through an edge cannot be greater than it's capacity
  2. The total flow coming to a vertex is the same as the total flow coming out of it
The problem we are trying to solve is to find a flow function so that the summation of the flow at each edge is maximized.

A cut separating s and t is as follows:
  • X = {s, a}
  • X_bar = {b, c, d, t}
  • The cut = {(a,b), (s,c), (s,d)}
In any network, the maximal flow from s to t is equal to the minimal capacity of any cut.

1:  
algorithm
 
findPath(
node 
source, 
node 
sink, 
path)

2:  
 
 
if
(
source 
== 
sink)

3:  
 
 
 
 
return
 
path;

4:  
 
 
foreach 
edge 
in 
source.edges

5:  
 
 
 
 
residual 
edge.capacity 
edge.flow;

6:  
 
 
 
 
if
 
residual 
and 
edge 
is 
not 
in 
path

7:  
 
 
 
 
 
 
new_path 
findPath(
edge.target, 
sink, 
path 
edge)
;

8:  
 
 
 
 
 
 
if
 
new_path 
is 
not 
EMPTY_PATH

9:  
 
 
 
 
 
 
 
 
return
 
new_path;

10: 
 
 
foreach 
edge 
in 
edges 
pointing 
to 
source 
(
reverse 
edge)

11: 
 
 
 
 
flow 
forward 
edge 
flow

12: 
 
 
 
 
if
 
flow 
and 
edge 
is 
not 
in 
path

13: 
 
 
 
 
 
 
new_path 
findPath(
edge.target, 
sink, 
path 
edge)
;

14: 
 
 
 
 
 
 
if
 
new_path 
is 
not 
EMPTY_PATH

15: 
 
 
 
 
 
 
 
 
return
 
new_path;

16: 
 
 
print 
"backtracking at: "
 
source;

17: 
 
 
return
 
EMPTY_PATH;

18: 

19: 
algorithm
 
fordFulkerson(
digraph 
g, 
node 
source, 
node 
sink)

20: 
 
 
path 
findPath(
g, 
source, 
sink, 
NULL)
;

21: 
 
 
printPath(
path)
;

22: 
 
 
while
 
path 
!= 
EMPTY_PATH

23: 
 
 
 
 
foward_flow 
min 
of 
all 
residuals 
for
 
each 
forward 
edge 
in 
path

24: 
 
 
 
 
reverse_flow 
min 
of 
all 
forwards 
flows 
for
 
each 
reverse 
edge 
in 
path

25: 
 
 
 
 
min_flow 
min(
forward_flow, 
reverse_flow)
;

26: 
 
 
 
 

27: 
 
 
 
 
//augment path

28: 
 
 
 
 
foreach 
edge 
in 
path

29: 
 
 
 
 
 
 
if
 
edge 
is 
forward

30: 
 
 
 
 
 
 
 
 
edge.flow 
+= 
min_flow;

31: 
 
 
 
 
 
 
if
 
edge 
is 
reverse

32: 
 
 
 
 
 
 
 
 
fedge 
find 
foward 
edge 
for
 
edge

33: 
 
 
 
 
 
 
 
 
fedge.flow 
-= 
min_flow;
 

34: 
 
 
 
 
path 
findPath(
g, 
source, 
sink, 
NULL)
;

35: 
 
 
 
 
printPath(
path)
;

36: 
 
 
return
 
the 
sum 
of 
edge.flow 
forall 
the 
edges 
in 
source.edges

  1. Start:
    MaxFlow
  2. End:
    MaxFlow

Time Complexity

  • The algorithm is never guarenteed to terminate, but if it does:
  • O(Ef) - E is the number of edges, f is the max flow value
  • Each edge gets incremented a flow value by at least 1 each time until the max is reached
The algorithm may not be able to complete if there are irrational flow values.

Backward Edges

  1. Start: 
    MaxFlowsFixed
  2. Follow forward edges: 
    MaxFlowsFixed
  3. Follow backward edge: 
    MaxFlowsFixed

Maximum Matching

1:  
algorithm
 
findMaximumMatching(
bipartite 
graph)
{

2:  
 
 
for
(
all 
unmatched 
vertices 
v)
{

3:  
 
 
 
 
set 
level 
of 
all 
vertices 
to 
0;

4:  
 
 
 
 
set 
parent 
of 
all 
vertices 
to 
null;

5:  
 
 
 
 
level(
v)
 
1;

6:  
 
 
 
 
last 
null;

7:  
 
 
 
 
clear 
queue;

8:  
 
 
 
 
enqueue(
v)
;

9:  
 
 
 
 
while
(
queue 
is 
not 
empty 
and 
last 
is 
null)
{

10: 
 
 
 
 
 
 
dequeue(
)
;

11: 
 
 
 
 
 
 
if
(
level(
v)
 
is 
an 
odd 
number)
{

12: 
 
 
 
 
 
 
 
 
for
(
all 
vertices 
adjacent 
to 
such 
that 
level(
u)
 
is 
0)
{

13: 
 
 
 
 
 
 
 
 
 
 
if
(
is 
unmatched)
{

14: 
 
 
 
 
 
 
 
 
 
 
 
 
parent(
u)
 
v;

15: 
 
 
 
 
 
 
 
 
 
 
 
 
last 
u;

16: 
 
 
 
 
 
 
 
 
 
 
 
 
break
;

17: 
 
 
 
 
 
 
 
 
 
 
}
 
else
 
if
(
is 
matched 
but 
not 
with 
v)
{

18: 
 
 
 
 
 
 
 
 
 
 
 
 
parent(
u)
 
v;

19: 
 
 
 
 
 
 
 
 
 
 
 
 
level(
u)
 
level(
v)
 
1;

20: 
 
 
 
 
 
 
 
 
 
 
 
 
enqueue(
u)
;

21: 
 
 
 
 
 
 
 
 
 
 
}
 

22: 
 
 
 
 
 
 
 
 
}

23: 
 
 
 
 
 
 
}
 
else
 
{
 
//if level(v) is an even number

24: 
 
 
 
 
 
 
 
 
enqueue(
vertex 
matched 
with 
v)
;

25: 
 
 
 
 
 
 
 
 
parent(
u)
 
v;

26: 
 
 
 
 
 
 
 
 
level(
u)
 
level(
v)
 
1;

27: 
 
 
 
 
 
 
}

28: 
 
 
 
 
}

29: 
 
 
 
 
if
(
last 
is 
not 
null)
{
 
//augment matching by updating the augmenting path;

30: 
 
 
 
 
 
 
for
(
last;
 
is 
not 
null;
 
parent(
parent(
u)
)
)
{

31: 
 
 
 
 
 
 
 
 
matchedWith(
u)
 
parent(
u)
;

32: 
 
 
 
 
 
 
 
 
matchedWith(
parent(
u)
)
 
u;

33: 
 
 
 
 
 
 
}

34: 
 
 
 
 
}

35: 
 
 
}

36: 
}

MaximumMatching

MaximumMatching

Steps of the algorithm:
vlevelumatchingqueuepath
a1dd is unmatched. d aempty[d a]
b1cc is unmatched. c bempty[c b]
e1jj is unmatched. j eempty[j e]
f1bb is matched but not with f[b][b f]
f1cc is matched but not with f[b c][b f] [c f]
b2 match = c. parent[c] = b[c c][c b f]
c3aa is matched but not with c[c a][a c b f]
c3blevel[b] != 0[c a][a c b f]
c3flevel[f] != 0[c a][a c b f]
c3gg is unmatched. g c. b f.[c a][a c b f] [g c b f]
h1gg is matched but not with v[g][g h]
h1jj is matched but not with h[g j][j h] [g h]
h1ii is unmatched. i h[g j][j h] [i h] [g h]

K-Core Graph Clustering

1:  
algorithm
 
kcoreCreation(
Graph 
g)

2:  
 
 
compute 
the 
degrees 
of 
vertices

3:  
 
 
sort 
vertices 
in 
increasing 
order 
by 
degrees

4:  
 
 
foreach(
vertex 
in 
in 
order)

5:  
 
 
 
 
core[
v]
 
:
degree[
v]
;

6:  
 
 
 
 
foreach(
in 
neighbors(
v)
)

7:  
 
 
 
 
 
 
if
(
degree[
u]
 
degree[
v]
)

8:  
 
 
 
 
 
 
 
 
degree[
u]
 
:
degree[
u]
 
1;

9:  
 
 
 
 
 
 
 
 
reorder 
accordingly

KCoreAssign

NodeDegreeK NumberNodeDegreeK Number
A11I43
B11J33
C42K33
D33L53
E53M42
F33N22
G33O11
H63
1:  
algorithm
 
kcoreCluster(
Graph 
g)

2:  
 
 
:
V;

3:  
 
 
foreach(
vertex 
in 
V)
{

4:  
 
 
 
 
p[
v]
 
:
degree(
v)
;

5:  
 
 
}

6:  
 
 
build_min_heap(
v, 
p)
;

7:  
 
 
while
(
heap.size(
)
 
>
 
0)
{

8:  
 
 
 
 
:
C\{
top}
 
 
//remove top from C

9:  
 
 
 
 
core[
top]
 
:
p[
top]
;

10: 
 
 
 
 
foreach(
vertex 
in 
neighbors(
top, 
C)
{

11: 
 
 
 
 
 
 
p[
v]
 
:
max(
p[
top]
p(
v, 
N(
v, 
C)
)
)
;

12: 
 
 
 
 
 
 
update_heap(
v, 
p)

13: 
 
 
 
 
}
 
 

14: 
 
 
}

k_core
(image from [7])

Time complexity:
  1. O(m): cores decomposition
  2. O(m * max(deg, lgn)): finding cores
m: number of edges.
deg: maximum degree.
n: number of vertices.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值