Breadth first search from multiple sources using Boost Graph Library - c++

I want to be able to use bfs in BGL to find all the trees of a forest, which is basically finding connected components using multiple source vertices. For example, it may be used to find different connected regions of an image to enable image segmentation (this is just one of the cases). How can I use the breadth_first_search in BGL to do this? Any pointers to examples/sources would be greatly appreciated! I have surveyed BGL documentation and have not been successful in finding what I want to do.

Just use the connected components that already exists in boost. There is a useful example. Afterwards all vertices in the graph will have a mapping to their component. If you really want to use BFS on individual parts, just use a visitor and push nodes into a vector.
You can specify your start node with:
breadth_first_search(graph, visitor(vis).root_vertex(root_vertex_descriptor));

Related

C++ packages for graph processing

I am working on a huge graph.
I'm interested to focus on a small part of the graph and make some optimization on it.
All other "not interesting" nodes will be packed to one "supernode".
I am going to make number of iterations, each iteration will focus on another part of a graph. Then, I need to unpack existing supernode and pack another supernode.
I am looking for existing packages/algorithms which can do for me the packing/unpacking jobs.
I am working on C++ and using boost BGL.

Resuming an a-star search in BGL

I am running an astar algorithm on a graph that is partially (?) implicit - it is built from a large paging data source, but the graph is persistent. I need to handle paging in new parts of the graph whenever the astar algorithm gets to an area that is not fully paged in - ideally without starting the astar search over entirely.
I have tried a couple solutions but hit some road blocks, and I'm wondering if I'm missing something obvious or just approaching the problem wrong.
I am currently using boost 1.45 but plan to upgrade to 1.51.
First, I tried to modify the astar visitor such that when it determines it needs to page in new data, it calls a function on the graph and loads it in - however, since the graph is const, this is not possible. I have looked around and found this other question boost implicit graph and astar_search_no_init that references a presentation that suggests someone has done the work to make this possible, but it looks like the actual code is not available.
Second, I thought I might be able to exit the algorithm when I get to a place where I need to page in more data, and save the state of the distance_map, predecessor_map, and color_map so that I could use them to "resume" the search using astar_search_no_init. I am not sure whether this would work, because once I switch over to using astar_search_no_init, I see that while the visitor appears to do the work of pathfinding, the predecessor map is empty - since I am using the predecessor for building the path after the visitor is done, I need to know how the visitor is then building a path.
Here is the definition of my graph and how I am calling astar_search, if that helps at all.
typedef adjacency_list<
vecS,
vecS,
undirectedS,
VertexInfo, //contains geographic location
EdgeInfo, //contains weight information
no_property,
setS>
BoostGraph;
...
ColorMap cmap = get(vertex_color_t, myGraph);
astar_search(
myGraph,
source,
distance_heuristic(myGraph, destination), //geometric distance heuristic
predecessor_map(&srcPredmap[0]).
distance_map(&distMap[0]).
color_map(cmap).
visitor(astar_goal_visitor<vertex_descriptor>(destination, this)). //throws an exception when it finds the goal
weight_map(make_function_property_map<edge_descriptor>( //copied make_function_property_map functionality from boost 1.51 since I can't upgrade just yet
EdgeWeightAdjuster(&myGraph, weightFactors)))); //modifies edge weights based on weightFactors construct
You write: "however, since the graph is const, this is not possible..." And what about a simple CAST (event an old C-cast)? You should give this option at least a try. Modifying the graph may invalidate iterators, etc. This is true. Nevertheless you should still try.
There is a difference between "technical const-ness" and "conceptual const-ness". In your case you will break only the technical, not the conceptual one.

Creating a graph using Boost Graph library

I am new to graph theory and graph concept.
I am workign on something, that requires me to create a mesh(Undirected graphs) with n number of nodes.
Once the structure is created, I would be running various algorithms on the structure, to find a shortest path from a node to other.
No for this I have decided to use Boost graph librabry.
I read through the online documentation. The online documentation is good but at the same time not sufficient.
I went through various examples online and everywhere, they import the graph from Graphviz.
If i am not wrong, we have to manually draw or write a dot program to get a graph in Graphviz and import in .dot format(Please correct me if i am wrong)
But is there a way in Boost where I could create a graph, instead of importing it from GraphViz?
And I would let user to decide the number of vertices in it, instead of pre-defining it.
Any help would be very much appreciated.
Thanks a ton in advance.
It's maybe not very correct, but I am giving a response a gave before.
https://stackoverflow.com/a/3100220/202083
You can see how to programmaticaly add nodes and edges.
I hope this is enough for you to get started.

analysing graph values

hello every i want to ask that is there any way through which i can pick values from the plotted graph and statistically analyze them using c++ programming and also the graph is moving graph (realtime graph)
thank u kindly help me
i am using c++ and linux and graph is plotted by using qwt and qt
Analyzing doesn't look necessary for what you describe (if I got it well) and would be too costly. You simply need to create an observer system ; when a node value is changed, send a message with the new value. You'll only need to see if the value is zero. Add special events for the extreme nodes and check when their value is changed if they match.

Graph-Drawing / TSP-Route-Drawing in C++ with "known" coordinates: How? Which Library/Tool?

i'm developing some kind of heuristics for a variation of the vehicle-routing-problem in C++.
After generating a solution, i want to plot this solution. The solution is a composite of various tours, all starting and ending at a common depot.
Therefore i have a vertex-set with all the coordinates and edges defined by two vertex-id's each. Furthermore i have all the distances between vertex-pairs of course.
It would be helpful to plot this in an extra-window opening in my program, but writing a plot to a graphics-file should be okay too.
What is an easy way to plot this? How would you tackle this?
First i tried to look for common graph-visualization packages (graphviz, tulip, networkx (python)), but i realized that all of them are specialized at graph-layouting (when there are no coordinates). Correct me when i'm wrong.
I don't know if it is possible to tell these packages that i already have the coordinates, helping the layouting-algorithms.
Next thing i tried is the CGAL library with geomview output -> no luck until now -> ubuntu crashes geomview.
One more question: Is it a better idea to use some non-layouting 2d-plot-libraries risking a plot, which isn't really good to view at (is there more to do than scaling?) or to use some layout-algorithm-based-libraries (e.g. graphviz, tulip, networkx), feed them with the distances between the vertices and hope the layouting-algorithms are keeping the distances while plotting in a good-to-view-at way?
If non-layouting-plotting is the way to do it: which library do you recommend?
If layout-based-plotting is the way to do it: how can i make use of the distances/coordinates in these libraries? And which library do you recommend?
Thanks for all your input!
Sascha
EDIT: I completed a prototype implementation using the PLplot library (http://plplot.sourceforge.net/). The results are nice and should be enough for the moment. I discovered and chosed this library because a related project (VRPH Software Package / Groer) used this plot and the source code was distributed. So the implementation was done in a short amount of time. The API is in my opinion bit awkward and low-level. Maybe there are some more modern (maybe not a c-based library) libraries out there? MathGL? Dislin? Maybe i will try them too.
The nice thing about drawing multiple tours in a vehicle routing problem is that "not so bad" algorithms tend to discover nice non-overlapping and divergent tours which is really good for the eye ;-)
It is not quite clear what you are trying to archive, but if I understand your question correctly, then you could do it using OpenGL. Having vertex coordinates, it should be fairly easy.
You can use Gnuplot with a input text file that contains your solution.
It is convenient to draw the points (vertex) then lines (agents paths) than link them.
To make the plot script easy, you can have a separate file for each vehicle, if the number
of vehicles is known.
check out:
http://www.cleveralgorithms.com/nature-inspired/advanced/visualizing_algorithms.html