Getting the flow of c++
If you have a bipartite graph and want to get a maximum matching - you can reduce the problem by building a flow graph and calculate its maximum flow. Ford and Fulkerson are the inventors behind the method Ford-Fulkerson which calculates the maximal flow through a directed graph. When implemented using breadth-first search you get the Edmonds-Karp algorithm. You have to keep an adjacency list of vertices as well as edge-information for forward edges and backward edges. Using c++ I was able to effectively search, save paths and update the flow. First off we need a good way to store the data for each edge. This is done with a struct called edgeflow and a global vector edge_list that is an adjacency list (of edges).
For each edge we create an edgeflow pointer, allocate memory, set all the variables and insert the pointer into edge_list. For each edge we also create a backwards-edge which is linked together with the forward-edge using the reverse pointer. This edge is also added to edge_list.
Now we can start calculating the max flow from the node start to the node sink. While a possible path is found from start to sink we continue to increase flow along this path:
Here we can really utilize the pointers. The path built by BFS is a list with pointers to each edge. We get instant access to these objects and can update their values. Let us see how the path is found using BFS:
Since path is a list type it is implicitly declared as a pointer. This means that we receive its address as the argument in BFS. All operations done to the path inside BFS can be accessed outside BFS aswell. Looking at time efficency we see that the method of finding the maximum flow is only bound by the speed of breadth first search times the number of possible paths in the graph.