Distinguish directed and undirected graph - c++

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.

Related

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

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.

Boost Graph library. Implement visitor that can revisit vertices multiple times

I am pretty knew to the boost graph library. I need to implement a visitor that would be able to revisit the same vertices multiple times. For the undirectedS graphs (or directed with 2 edges) this would result in the infinite search depth, however I am planning to put a finite constraint on the maximum depth.
I am considering to use breadth_first_search(), and I think what I need to do is to un-mark visited vertices in vis.black_target()? Would you know how to do it?
Thanks!
EDIT: Technically I would like to explore all possible paths of a constant depth from a starting vertex. (even if some of them revisit the same vertices several times)

Removing edges and splitting a connected component if necessary (C++, Boost)

I have a large graph (the number of vertices can be in the range of 50,000-100,000, the adjacency matrix need not be sparse). Edges in the graph can be removed/added, and I want to update the resulting connected components structure after such changes. I have implemented this in a straightforward fashion with a BFS search myself in C++ (keeping track of unordered_maps of vertices to connected component ids and updating them), but I am wondering if there is a more efficient way to do this using Boost's graph library.
I was able to find some questions similar to this here in Stackoverflow, and came to know of filtered_graph (and the connected_components function) but I am worried about the overhead involved in creating such filtered instances, every time we add or remove an edge. (Or should this be a concern at all?!)
I believe your solution is essentially the best possible. If you are only allowed to add edges, then I believe the algorithm can be improved by keeping track of connected components in terms of vertices included, and then when an edge is included you check to see if the two vertices belong to different connected components, in which case you merge the two connected components. This will reduce the complexity from quadratic to best-case per edge added. However, if you are allowed to insert and delete edges, I don't see any asymptotically faster way to solve the problem other that what you described.
There are algorithms for maintaining connectivity under edge insertions and deletions that are faster than recalculating. This is called "dynamic graph connectivity". Here is a paper on experimental evaluations (some newer theoretical results have been found since, but it is unclear whether they have practical relevance).

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).

Can I implement potential field/depth first method for obstacle avoidance using boost graph?

I implemented an obstacle avoidance algorithm in Matlab which assigns every node in a graph a potential and tries to descend this potential (the goal of the pathplanning is in the global minimum). Now there might appear local minima, so the (global) planning needs a way to get out of these. I used the strategy to have a list of open nodes which are reachable from the already visited nodes. I visit the open node which has the smallest potential next.
I want to implement this in C++ and I am wondering if Boost Graph has such algorithms already. If not - is there any benefit from using this library if I have to write the algorithm myself and I will also have to create my own graph class because the graph is too big to be stored as adjacency list/edge list in memory.
Any advice appreciated!
boost::graph provides a list of Shortest Paths / Cost Minimization Algorithms. You might be interested in the followings: Dijkstra Shortest path, A*.
The algorithms can be easily customized. If that doesn't exactly fit your needs, take a look at the visitor concepts. It allows you to customize your algorithm at some predefined event point.
Finally Distributed BGL handles huge graph (potentially millions of nodes). It will work for you if your graph does not fit in memory.
You can find good overview of the Boost Graph Library here.
And of course, do not hesitate to ask more specific question about BGL on stackoverflow.
To my mind, boost::graph is really awesome for implementing new algorithms, because it provides various data holders, adaptors and commonly used stuff (which can obviously be used as parts of the newly constructed algorithms).
Last ones are also customizable due to usage of visitors and other smart patterns.
Actually, boost::graph may take some time to get used to, but in my opinion it's really worth it.