My code below should return a max_flow
value of 7 for the given network but it returns 2. I am certain my error is confined to generating the paths from s
to t
as I have re-wriiten the program in c which I have more experience in. I have also printed out my residual graph to see whats going on which is obviously also incorrect.
There shouldn't be negative integers within it for one thing.
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 -2 2
0 0 0 2 0 6
0 0 0 -2 -6 0
I have also verified its 7 by hand. Inside my main function in c I have used while (int sent = dfs(s, t, INF))
as the condition for my while loop but in MATLAB I figured the equivalent was
while sent == dfs(s,t,INF)
. I think that this could be the problem but I cant find an alternative and don't know where the hole in my logic is. I know that MATLAB has a built in maxlow
function but I wanted to build my own as a learning experience.
I am using a depth first search to find paths from source to sink in my residual graph Flow
.
I would appreciate any pointers to mending this and also anything else you think should/could be improved
function ff
clear;