boost::filtered_graph filtering on vertex color... if I only had a colormap
Lets say I have a graph g (of type graph_t)
and a color map (boy I wish I had a colormap):
typedef boost::property_map
From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Brian Davis via Boost-users Lets say I have a graph g (of type graph_t) and a color map (boy I wish I had a colormap):
There is not one single color_map class, it is a concept. Any object that has the following defined will do as a color map: Color c = get(my_color_map, vertex); // get the color of a vertex put(my_color_map, vertex, c); // set the color of a vertex my_color_map[vertex] = c; // get the color of a vertex (for an LValue property map) c = my_color_map[vertex]; // set the color of a vertex (for an LValue property map)
typedef boost::property_map
::type color_map_t; or is it?
That would only work if your graph type have a vertex_color property embedded in it, which is probably doesn't. If It did you could simply write auto colormap = boost::get(boost::vertex_color, g); The following that you propose look perfectly fine
auto indexmap = boost::get(boost::vertex_index, g); auto colors = boost::make_vector_property_mapboost::default_color_type(indexmap);
This looks good and would the preferred approach if you do not know the number of vertices when you construct the map, why did it not work?
If you do know the number of vertices, use shared_array_property_map instead.
Your code example is a bit garbled, but I think the problem is that you are constructing the filter with only two arguments (graph,vertex predicate), whereas the constructor expects (graph, edge predicate, vertex predicate) or (graph, edge predicate).
It is a pity that BGL does not have the enthusiastic support anymore that it used to have. Once you get used to it, it is very powerful.
The following compiles and runs correctly for me:
#include
Since my graph, g, of type graph_t is:
typedef boost::property
Hello, everybody, I have followed your conversation and since I have a similar problem, I would be happy if you could help me. At the moment I am really lost. The problem is to create the color map that can be used in Depth_First_Search. A special feature that I have is that I want to change the Vertex color of DFS to modify the DFS. For example like this: If I make the color map global and pass it to the visitor, everything works: If the color map is not global but external, I can write the map, but it is not the same as the DFS color map and therefore I cannot manipulate the DFS algorithm: I then tried to create an internal map and work with the get() and put() functions, but I didn't succeed: I'd be so grateful for any hint. Best Juergen -- Sent from: http://boost.2283326.n4.nabble.com/Boost-Users-f2553780.html
Sorry in my last post, the code was not insert...
Hello, everybody,
I have followed your conversation and since I have a similar problem, I
would be happy if you could help me. At the moment I am really lost. The
problem is to create the color map that can be used in Depth_First_Search. A
special feature that I have is that I want to change the Vertex color of DFS
to modify the DFS. For example like this:
template < typename Vertex, typename Graph >
void finish_vertex(Vertex u, const Graph & g)
{
diGraph::vertex_descriptor vertex;
vertex = boost::vertex(u, g);
if (u == m_destination)
{
*m_result = true;
//save current path
m_allPaths->insert(std::make_pair(m_numPaths, m_spath));
m_numPaths++;
}
if (u == m_source)
{
for (auto vd : boost::make_iterator_range(vertices(g)))
{
vertex_coloring[vd] = boost::black_color;
}
}
}
If I make the color map global and pass it to the visitor, everything works:
//global version (working)
typedef boost::property< boost::vertex_name_t, std::string,
boost::property
//not working depth_first_search(ee_archi, vis, boost::make_assoc_property_map(vis.vertex_coloring),0);
The visitor is passed to depth_first_search by value, and hence a copy of vis is made and you are then working on two colormaps.
You need to change your visitor to have reference semantics so that a copy of the visitor still points to the same color_map.
This should work:
struct my_vis : default_dfs_visitor {
using colormap = boost::associative_property_map
participants (4)
-
Alex Hagen-Zanker
-
Alex HighViz
-
Brian Davis
-
Juergen