Pergunta

My analysis of the Ford-Fulkerson algorithm is not coming out correctly. For example, take the following graph:

      _____>4___>_
     |            |
0--->1---->3------6
|    |            | 
2--->5--------->---

Node 0 is source, node 6 is the terminal node, and every edge's restriction is 1, except edge from node 0 to 1 's restriction is 2. If the flow goes from 0->1->3->6 and 0->1->4->6 and 0->2->5->6, the flow of the graph is 3. However, if the flow start from 0->1 choose to go from 0->1->3->6, and 0->1->5->6, we cannot go from 0->2->5->6 anymore, since 5->6 has already been occupied. Since 0->1's restriction is 2, we can only start from 0->1 twice, therefore, the flow of the graph is 2. Obviously, the max possible flow of the graph should be 3 not 2. Will the Ford-Fulkerson algorithm handle this problem and always return 3 as the answer?

Foi útil?

Solução

Yes Ford-Fulkerson can. Always solving such problems is actually what it was designed for.

I guess the fact you are missing is that when determining the residual graph you also have to add the back edges. Thus after going 0->1->3->6 and 0->1->5->6 the residual graph actually looks like this:

                1          1
            +-------> 4 ------+
            |                 |
        2   |     1        1  v
  0 <------ 1 <----- 3 <----- 6
  |         ^                 |
  |   1     | 1               | 1
  +-------> 5 <---------------+

The next step Ford-Fulkerson is going to take is adding the route 0->5->1->4->6 thus yielding a flow of 3.

Outras dicas

It will timeout when the maxFlow is too high. (In the worst case Ford fulkerson adds only 1 flow at each step)

Just use BFS instead of DFS in ford fulkerson and it becomes Edmonds carp! Its too fast and widely used compared to Ford-fulkerson.

You can also check out the PFS(Priority first search) which is explained here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top