Академический Документы
Профессиональный Документы
Культура Документы
Sumrio
Aplicaes
Conceitos
Fluxo em redes
Fluxo mximo
Mtodo de Ford-Fulkerson
Redes residuais
Caminhos de aumento
Cortes
Algoritmos em Grafos
Aplicaes
Considere a seguinte
situao modelada por um
grafo
Cada arco representa uma rua
de mo nica
A capacidade de cada arco
indica o maior fluxo possvel
ao longo da rua (veculos/
hora)
Algoritmos em Grafos
Aplicaes
Outros exemplos
Envio de produtos da fbrica para o
distribuidor
Transporte de peas em linhas de
montagem
Lquidos em redes hidrulicas
Dados em redes de comunicao
Correntes em redes eltricas
Algoritmos em Grafos
Fluxo em Redes
Uma rede G =(V, E) um grafo orientado em
que cada aresta (u, v) E tem uma
capacidade no-negativa c (u, v) 0
Existe sempre um vrtice origem s e um
vrtice destino t
Um fluxo representa o envio de entidades da
origem para o destino, percorrendo alguns dos
arcos da rede
Algoritmos em Grafos
Fluxo em Redes
13
v2
Calgary
14
(a)
20
v4
Regina
Winnipeg
t
16
11/
v1
8/1
3
v2
12/12
11/14
v3
15/
20
t
7/7
v3
16
12
Saskatoon
4/
Vancouver
v1
capacidade
c(s,v1)
1/4
Edmonton
Chapter 26
710
fluxo
f(s,v
Maximum
Flow
1)
Perceba a conservao
de fluxo nos vrtices v1,
v2, v3 e v4.
v4
4/4
(b)
Figure 26.1
(a) A flow network
G D .V; uma
E/ for the
Lucky Puck Companys
trucking problem.
No caso acima,
verifica-se
que existe
capacidade
de 16 unidades
de
The s
Vancouver
sourcequais
s, and the
Winnipeg 11
warehouse
is the
sink t. The
companyno
ships
fluxo do n
para ofactory
n vis1the
, das
apenas
esto
sendo
usadas
pucks through intermediate cities, but only c.u; !/ crates per day can go from city u to city !. Each
momento.edge is labeled with its capacity. (b) A flow f in G with value jf j D 19. Each edge .u; !/ is labeled
by f .u; !/=c.u; !/. The slash notation merely separates the flow and capacity; it does not indicate
division.
Algoritmos em Grafos
6
We call the nonnegative quantity f .u; !/ the flow from vertex u to vertex !. The
Fluxo em Redes
Deve satisfazer trs propriedades
f (u,v) = -f (v,u)
Conservao de fluxo: o fluxo que entra deve
ser igual ao que sai (exceto para s e t )
Algoritmos em Grafos
Fluxo Mximo
o nmero mximo de unidades de fluxo
possvel atravs da rede desde o n
origem at o n destino
Considera-se que h conservao de
fluxo: o que parte da origem chega
totalmente ao destino, sem perdas no
caminho.
Algoritmos em Grafos
Mtodo de Ford-Fulkerson
Depende das ideias de:
Rede residual: formada pelas arestas da
rede que podem admitir mais fluxo (ou seja,
onde existe capacidade residual)
Caminho aumentante: um caminho
simples desde a origem at o destino na
rede residual
Algoritmos em Grafos
Rede Residual
Dado uma rede G = (V, E) e um fluxo f(u,v) em G, a
capacidade residual cf a quantidade de fluxo
adicional que pode passar por (u, v) sem exceder a
capacidade c (u, v):
Algoritmos em Grafos
10
Rede Residual
Exemplo
5-4=1
Rede residual
Algoritmos em Grafos
11
Caminho Aumentante
Dado um caminho aumentante P em uma rede residual
Gf , a quantidade mxima pela qual o fluxo pode ser
aumentado no caminho chamada de capacidade
residual cf (P), e expressa por
12
replace f by f " fp , obtaining a new flow whose value is jf j C jfp j. The following implementation of the method computes the maximum flow in a flow network
G D .V; E/ by updating the flow attribute .u; !/:f for each edge .u; !/ 2 E.1
If .u; !/ 62 E, we assume implicitly that .u; !/:f D 0. We also assume that we
Algoritmo de Ford-Fulkerson
are given the capacities c.u; !/ along with the flow network, and c.u; !/ D 0
if .u; !/ 62 E. We compute the residual capacity cf .u; !/ in accordance with the
formula (26.2). The expression cf .p/ in the code is just a temporary variable that
stores the residual capacity of the path p.
F ORD -F ULKERSON .G; s; t/
1 for each edge .u; !/ 2 G:E
2
.u; !/:f D 0
3 while there exists a path p from s to t in the residual network Gf
4
cf .p/ D min fcf .u; !/ W .u; !/ is in pg
5
for each edge .u; !/ in p
6
if .u; !/ 2 E
7
.u; !/:f D .u; !/:f C cf .p/
8
else .!; u/:f D .!; u/:f ! cf .p/
1 Recall
from Section 22.1 that we represent an attribute f for edge .u; !/ with the same style of
notation.u; !/: f that we use for an attribute of any other object.
Algoritmos em Grafos
14
Exerccio
Fornea os fluxos e a rede residual
obtida a cada iterao do algoritmo de
Ford-Fulkerson para a rede abaixo:
16
B
4
A
13
12
9
14
20
F
7
E
Algoritmos em Grafos
15
Resoluo
13
7
4
v3
7
4
v4
6
8/1
4/1
4/
4
3
16
5
v2
10
4/1
v4
4
9
4
v1
12
s
10
v2
20
v1
v2
v1
v2
4/14
8/12
4/14
8/12
4/14
v4
v3
4/4
4/2
0
t
6
4/1
v3
v4
v3
4/4
8/2
0
t
20
v3
v2
4/
9
v1
13
4/12
14
v4
v2
12
(c)
6
4/1
v1
4/4
13
(b)
20
v3
16
(a)
12
v1
726
v4
4/4
Figure 26.6 The execution of the basic Ford-Fulkerson algorithm. (a)(e) Successive iterations of
with a shaded 16
the while loop. The left side of each part shows the residual network
Gf from line
Algoritmos
em 3Grafos
augmenting path p. The right side of each part shows the new flow f that results from augmenting f
by fp . The residual network in (a) is the input network G.
Resoluo
v2
(f)
s
2
v1
12
11
3
11
12
v2
3
11
v3
5
15
v3
19
12
v2
v1
11/14
12/12
11/
13
v2
11/14
v3
15/
20
7/7
11/
13
/16
v4
v4
v4
8/12
v4
v3
4/4
19/
20
7/7
8
11
6
8/1
v1
(e)
8
9
v1
12
v2
10
v3
8
9
8
9
(d)
v1
727
v4
4/4
t
4
Figure 26.6, continued (f) The residual network at the last while loop test. It has no augmenting
Algoritmos em Grafos
17
paths, and the flow f shown in (e) is therefore a maximum flow. The value of the maximum flow
found is 23.