BOOST min-cut/max-flow on undirected graph with source and target - c++

Can I use any algorithms from Boost on an undirected graph which must have a source and target (two nodes which must be in separate cuts). The preflow_relabel says it requires a directed graph. Stoer_wagner_min_cut says it works on undirected graphs but I can't find where it asks for a source/target node.
If not, anyone have any recomendations? I setup Lemon to work but I think they do max flow on an undirected graph by treating it as two directed edges one going each way. This causes runtime issues where the runtime is tied to the magnitude of the capacity of some edges.
And this is for University level computational biology research, I say this as I assume people might otherwise ask why we want source/target for undirected graph with max-flow/min-cut.
Thanks in adance.

Related

Visit all nodes exactly once in a directed graph

I have a directed graph and I want to find a path that visits every node exactly one time. I want to do this with a good complexity. Is this possible? And if yes, how?
You are searching for a Hamiltonian path, which is a simple open path that contains each node exactly once.
Finding a Hamiltonian path in a given graph is NP-complete. In fact, determining whether a given (directed or undirected) graph contains a Hamiltonian path is already NP-complete (proven via reduction from e.g. the vertex cover problem).
If you still want to code it, here is an implementation on github. If you want a fast solution, maybe a heuristic is sufficient (for instance inspired by DNA molecules, or a solution that works fast on a subset of graphs. For instance, if you have a DAG, you can do a topological sort and then check if successive vertices are connected. If so, the topological sort gives a Hamiltonian path.

Ford-Falkerson's algorithm for undirected graphs (What am I missing?)

I "found" an algorithm for finding maximum flow in undirected graph which I think isn't correct, but I can't find my mistake. Here is my algorithm:
We construct a new directed graph in the following way: for every edge ${u,v}$ we create edges $(u,v)$ and $(v,u)$ with $c((u,v))=c((v,u))=c({u,v})$. Then we apply Ford-Falkerson's algorithm on new graph. Now we make a flow in our first graph in the following way: Let's $f((u,v))\ge f((v,u))$, than we direct edge ${u,v}$ from $u$ to $v$ and take $f'((u,v))=f((u,v))-f((v,u))$. Now it will be maximum flow for our undirected graph, because otherwise we will construct a flow for corresponding directed graph, which is contradiction.
The reason that I think I have missed something is that there is an article on the Internet about this problem and I don't think anybody would wrote an article about such a trivial problem.
And this is the article: http://www.inf.ufpr.br/pos/techreport/RT_DINF003_2004.pdf
Thanks!
Ford-Fulkerson is not the best algorithm to find maximum flow in a directed graph, and in the undirected case it is possible to do much better (close to linear-time if I recall correctly).
You don't cite the article you are talking about, but it is most likely that it describe an algorithm which is much better than yours.
For many problems in optimization, it is not difficult to find an algorithm that gives an optimal solution; nevertheless there is a lot of work to find the most efficient ones.

Finding all paths of a certain length in a weighted undirected graph

I need to generate all paths that are lesser than or equal to a specified length in a graph (the graph is undirected and it's possible to have cycles). I tried using BFS while keeping track of the distance already traversed but I'm not sure how I would ensure that every path is different.
Note: I know this probably has a very high computational complexity, but I'm not worrying about that for now.
Using BFS is kind of the right way to do so.
But you additionally have to keep track of already found nodes.
There is a simple algorithm from Dijkstra solving this for you

Planarity in graphs

I am implementing a graph library and I want to include some basic graph algorithms to it. I have read about planar graphs and I decided to include to my library a function which checks if a graph is planar. I found in the web many efficient algorithms, but they all had the same drawback; they are very hard to implement. So this is my question: does it exist an algorithm for planarity check which is easy to understand and to implement?
Note: I write in C++
This is a maths question, but anyway from the depths of my memory and from wikipedia
A finite graph is planar if and only if it does not contain a subgraph that is a subdivision of K5 (the complete graph on five vertices) or K3,3 (complete bipartite graph on six vertices, three of which connect to each of the other three).

Distinguish directed and undirected graph

I need to write a graph using C++ and I have a little problem. My graph should be directed or undirected, weighted or unweighted, based on matrix or list all on user's choice. And distinguishing matrix from list graph is not a big deal, since it's two different classes, I got some problem with other parameters. The most obvious way to distinguish them is to make two bool variables and check them on every adding and deleting of vertex. It is quite obvious and easy to understand, but I doubt it's efficiency, because every time I add or delete vertex I have to do additional if. I also could write subclasses for it, but I seriously doubt if it's worth it.
Every library is okay to use, if it's not representing graph itself.
For directed and undirected best case is using bool variable for your graph, however You can assume your graph is weighted and directed, but for undirected edges add one edge from a→b and one edge from b→a. Also if there isn't weight function set its weight to 1.
But if you looking for graph library it depends to your programming language, but I'd suggest graph boost library which implemented fully in c++, and too many other people implement it partially in other languages.