Can there be dead ends in Ford fulkerson based algorithm? - max-flow

Can we remove those edges which don't lead to sink t during DFS in ford fulkerson merhod similar to what we do in dinics algorithm? If not, can you please give an example.

Got it. Because in ford fulkerson, we can use an augmenting path through reverse edge to reduce a forward edge flow, which might make the forward edge usable in next iteration of DFS. So, removing an edge is not a good idea. Whereas in dinic, dead v can't become usable again once it's dead since there is no chance flow of an edge going away from v be reduced due to lack of reverse edges.

Related

Finding shortest path distances from a given node s to ALL the nodes in V in a graph with two negative edges

I have a follow-up question on this:
Finding shortest path distances in a graph containing at most two negative edges
Ranveer's solution looks great, but it is not fast enough because I need O(|E| + |V|*log|V|) fast algorithm.
I guess Dukeling's solution works great. It makes sense and it operates in the same running time of Dijkstra's algorithm.
However, my goal is to find shortest path distances from a given node s to ALL the nodes in V.
If I apply Dukeling's algorithm by setting all the nodes in V as end vertex e, I will need to run it |V| - 1 times. Then, the running time will be O(|V||E| + |V^2|*log|V|).
Any help would be appreciated!
Dijkstra's algorithm, in its original form, finds all the shortest paths from a source node to all other nodes in the graph.
You have (at least) two options for your problem:
Use Bellman - Ford. It's not as slow as its big-oh would suggest, at least not necessarily. Make sure you implement it like you would a BF search: using a FIFO queue. This means you will insert a node into the queue every time the distance to it is updated, and only if it isn't already in the queue. Other optimizations are also possible, but this should already give you a fast algorithm in practice;
Use Dijkstra's, but modified similarly to Bellman - Ford: the default Dijkstra's never inserts a node twice into the priority queue. Make sure you reinsert nodes if you have updated the distance to them. This will deal with negative cost edges. It essentially makes the algorithm closer to the Bellman - Ford described above, but using a priority queue instead of a FIFO queue. This will also get you closer to your desired complexity.

Ford Fulkerson : Backedge condition

I was looking into ford fulkerson and got confused with the backedge.
can somebody clear me out till what time or what should be the flow/capacity condition for considering backedge in the graph? Since I can consider any edge for backedge subtract that much flow and continue and this process can go on and on.
Please help me.
Thanks
Abhinav
You use a "back edge" only if it's a part of a path P from s to t such that all capacities of the edges on the path greater than 0 (note that any path that fulfills this requirements increases the flow from s to t). An edge may be considered as a "back edge" if there's already flow greater than 0 on that edge, so you can "return" this flow. In that case the capacity of the edge will be the existing flow in it, when you do this, consider the edge's direction as opposite to the original direction.
Think about a graph with only vertices s and t and an edge between them with capacity c. at first you'll send c from s to t. now you can allegedly use this edge as a back edge, but note that when using it as a back edge it is directed from t to s and thus not a path from s to t.
Take a look at the wiki example to see how the back edge is being used there (from that example you can understand why the algorithm's running time is dependent on the edge's capacities).

modification of bfs for ford fulkerson algorithm,to find augmenting path

i am using bfs to find augmenting path.but it is producing same path every time.but ford fulkerson algorithm requires that,we choose different path every time from source to sink,so can somebody suggest me how to modify bfs so that it produces different path every time between source and sink.graph is directed and weighted
You need to make sure that the BFS ignores edges where all of the capacity has been used. Usually, the BFS is being run on the so-called residual network, in which each edge capacity tells how much capacity remains on that edge (given the flow you've sent through that edge). You can either maintain a separate residual graph, or you can have an implicit one by making the BFS look at the difference between the original capacity and the current flow for each edge (and treating an edge as absent if its capacity is zero).

How to get Single Source Shortest Path for graphs having a negative weight cycle

Hey i have been studying the bellman ford algorithm for "single source shortest path" problems.
Now i am stuck at one point where i need to find out the solution for a graph having negative weight cycle.
But Bellman ford algorithm does not work here.
Can some one suggest me what to do. How to solve a problem having negative weight cycle?
Thanks for your time.
If there is a negative cycle which is reachable from the origin, which Bellman-Ford can detect, then you have two choices: either allow repeating edges, or do not. If you allow repeating edges, your shortest path could be considered to be infinitely negative. Otherwise, if you do not, the problem is NP complete. From Wikipedia:
One NP-Complete variant of the shortest-path problem asks for the shortest path in G (containing a negative cycle) such that no edge is repeated.
In a paper here discussed here the authors (Wulff-Nilson, Nanongki, Berstein) mention that a graph with negative-weight cycles can be reduced to one without such cycles and then they give a method that finds the shortest path in nearly linear time.

Minimal path - all edges at least once

I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.
I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.
Can anybody help me? Thanks
Edit>> All edges of that graph have the same cost - for instance 1
Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).
If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.
Key quote (the second half for the directed version):
The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.
I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.
what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here
And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here
I think it might be worth while just simply writing which vertices are odd and then find which combo of them will lead to the least amount of extra time (if the weights are for times or distances) then the total length will be every edge weight plus the extra. For example, if the odd order vertices are A,B,C,D try AB&CD then AC&BD and so on. (I'm not sure if this is a specifically named method, it just worked for me).
edit: just realised this mostly only works for undirected graphs.
The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):
When all of the edges of a connected graph are directed and the graph
is symmetric, there is a particularly simple and attractive algorithm for
specifying an Euler tour...
The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at
any node n, except the root r of the arborescence, specify any order for
the edges directed away from n so long as the edge of the arborescence
is last in the ordering. For the root r, specify any order at all for the
edges directed away from r.
This algorithm was used by van Aardenne-Ehrenfest and de Bruin to
enumerate all Euler tours in a certain directed graph [ 1 ].

Resources