2

I am currently studying Ford-Fulkerson algorithm based on this code found in R documentation:

nodes <- 1:6
arcs <- matrix(c(1,2,1, 1,3,7, 2,3,1, 2,4,3, 2,5,2, 3,5,4, 4,5,1, 4,6,6,
                5,6,2), byrow = TRUE, ncol = 3)
# Maximum flow with Ford-Fulkerson algorithm
maxFlowFordFulkerson(nodes, arcs, source.node = 2, sink.node = 6)

& got the following results:

$`s.cut`
[1] 2 3 1 5

$t.cut
[1] 4 6

$max.flow
[1] 6

It is stated in the result that maximum flow of this network is 6.

However, I have been trying to calculate the maximum flow by hand & no matter what I did, the maximum flow I obtained was only 5.

This is the possible graph I was able to map based on the code example: Max flow graph

& some of the possible flows I was able to get:

2 --> 4 --> 5 --> 6....................[Capacity: 1]

2 --> 5 --> 4 --> 6(backflow)...[Capacity: 1]

2 --> 5 --> 6............................[Capacity: 1]

2 --> 4 --> 6............................[Capacity: 2]

[Total capacity: 5]

Or

2 --> 3 --> 5 --> 6....................[Capacity: 1]

2 --> 4 --> 5 --> 6....................[Capacity: 1]

2 --> 5 --> 4 --> 6 (backflow)...[Capacity: 1]

2 --> 4 --> 6.............................[Capacity: 2]

[Total capacity: 5]

Did I misunderstood the process? Can anyone possibly write down the path to get a maximum flow of 6 step-by-step?

user438383
  • 5,716
  • 8
  • 28
  • 43
Agnes Lee
  • 322
  • 1
  • 12

2 Answers2

1

I think yours is correct (the max flow should be 5). Maybe you can try igraph for cross-check, e.g.,

df <- as.data.frame(`colnames<-`(arcs,c("from","to","capacity")))
g <- graph_from_data_frame(df)
res <- max_flow(g,2,6)

which gives

> res
$value
[1] 5

$flow
[1] 0 0 0 3 2 0 0 3 2

$cut
[1] 4 9

$partition1
+ 4/6 vertices, named, from bfc5f42:
[1] 1 2 3 5

$partition2
+ 2/6 vertices, named, from bfc5f42:
[1] 4 6

$stats
$stats$nopush
[1] 4

$stats$norelabel
[1] 3

$stats$nogap
[1] 2

$stats$nogapnodes
[1] 2

$stats$nobfs
[1] 1
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
  • I tried optree's maxFlowFordFulkerson on other online examples & got extra values as well...however, igraph's max_flow worked well for all questions so far. max_flow seems to be a more accurate function to use, thank you! – Agnes Lee May 25 '20 at 08:27
0

the maximum flow of undirected network is 6. ($t.cut [1] 4 6)

the maximum flow of directed network is 5. (the bottleneck is node 5)

command: maxFlowFordFulkerson(nodes, arcs, 1, source.node = 2, sink.node = 6)

justmag
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 13 '22 at 20:42