Flow Network

Back to Problem Solutions forum

Moff     2015-01-17 15:00:44
User avatar

I'm using a prepared Ford Fulkerson algorithm (from my own algo-library), it forks fine for coursera tasks, but it fails for this problem.

I'll try check java solution tomorrow.

Rodion (admin)     2015-01-17 15:01:47
User avatar

Feel free to write about any suspicions you may have!

I'm not quite sure about my own code because I have no chance to test it on larger independent datasets :(

Moff     2015-01-17 15:13:39
User avatar

I solved it by making bidirectional edges

v1->v2:w
v2->v1:w

So by searching augmenting paths it needs to doubling edge, so for one line from condition it maked 4 (four) edges at FlowNetwork.

For some cases my solution differs with checker. I'll try to make more analysis later.

Rodion (admin)     2015-01-17 15:29:02
User avatar

Yes, edges are bi-directional (I hope it was mentioned)... But I think for augmented path you need only pair of edges, not four. I.e.:

G: (graph description)
v1->v2:w
v2->v1:w

F: (flow description)
v1->v2:x
v2->v1:-x

Hope we'll be able to find out the truth later :)

nicolas_patrois     2015-01-17 16:50:03
User avatar

I solved it from scratch with a BFS. When the end point is found, I search the minimum flow for the way I found.

Then I substract it to the adjacency matrix (and a full route is removed) and add it to the flow matrix in the right way and remove it on the opposite way.

I was surprised that it worked.

Rodion (admin)     2015-01-17 17:07:03
User avatar

>I was surprised that it worked.

Yes, it is interesting! I suspect your solution may fail if there are edges for which flow direction should be reverted by some of later paths (because you subtract flows from adjacency matrix and could not restore them if necessary).

I've added such example (second) to problem statement - but I'm afraid it is hard to create randomized input data set with such a nice property... Probably your solution will not work for this case...

Please login and solve 5 problems to be able to post at forum