彩色地图升压图breadth_first_visit [英] Color map in boost graph breadth_first_visit
问题描述
我想用提升 breadth_first_visit
方法,我想为它提供我自己的外部彩色地图。
我所定义的图形如下:
I want to use boosts breadth_first_visit
method and i'd like to provide it with my own "external" color map.
I defined the graph as follows
typedef boost::adjacency_list<boost::setS, boost::listS, boost::undirectedS,
boost::property<boost::vertex_index_t, int,
boost::property<boost::vertex_color_t, boost::default_color_type,
Node_t>>> GraphType;
其中, Node_t
是一个结构,定义了顶点的属性。但是,我不能找出如何我可以提供BFS用我自己的彩色地图。我想顶点颜色存储在一个矢量,所以我的定义看起来像
where Node_t
is a struct, defining the properties for the vertices. However, i can't find out how i can provide the BFS with my own color map. I'd like to store the vertex colors in a vector, so my definition looks like
std::vector<boost::default_color_type> colors;
但我不能弄清楚,如何使用这个的BFS。
but i can't figure it out, how to use this for the bfs.
无论
boost::breadth_first_search(g, *boost::vertices(g).first,
boost::color_map(colors));
也没有
boost::breadth_first_search(g, *boost::vertices(g).first,
boost::color_map(&colors[0]));
在工作。虽然第一次给了我一堆不同的编译器错误(不支持如默认int的boost :: color_traits使用类类型的需要类型参数列表)第二编译只有C2664中止:提振::把'不能从'无效*'到'ptrdiff_t的转换参数2
is working. While the first gives me a bunch of different compiler errors (e.g. default-int is not supported, "boost::color_traits" use of class type requires type argument list) the second compile aborts with only C2664 : 'boost::put' cannot convert parameter 2 from 'void*' to 'ptrdiff_t'.
所以,问题是:我如何使用我自己的色彩映射结构。另外一个问题是:我怎样才能得到一个特定的顶点描述的颜色值
So the question is: How can i use my own color-mapping-structure. An additional question would be: How can i get the color-value for a specific vertex_descriptor?
推荐答案
好吧,我用另一种方法,但解决我的问题。对于那些谁是一样困惑,因为我是关于升压或彩色地图那些有兴趣谁:
Ok, i used another approach but solved my problem. For those who are as confused as i was about color maps in boost or those who are interested:
色彩映射的类型,如BFS使用它是:
The Type of the color map, as bfs uses it is:
typedef boost::property_map<GraphType, boost::vertex_color_t>::type color_map_t;
color_map_t colorMap; //Create a color map
本 vertex_descriptor的
映射到(对我来说) default_color_type
。要提升的BFS相应的呼叫会
This maps vertex_descriptor
to (in my case) default_color_type
. The appropriate call to boost's bfs would be
boost::breadth_first_visit(g, *boost::vertices(g).first, boost::color_map(colorMap));
给定一个color_names结构色号映射像
Given a color_names structure that maps the color number like
const char* color_names[] = {"white", "gray", "green", "red", "black"};
人们可以通过遍历图中的所有顶点并使用当前顶点的顶点描述作为一个参数通过颜色迭代[] - 运算符中的彩色地图:
one could iterate through the colors by iterating over all vertices in the graph and using the vertex_descriptor of the current vertex as an argument for the []-operator in the color map:
GraphType::vertex_iterator it, itEnd;
for (boost::tie(it, itEnd) = boost::vertices(g); it != itEnd; it++)
{
std::cout << "Color of node " << *it << " is " << color_names[colorMap[*it]] << std::endl;
}
这篇关于彩色地图升压图breadth_first_visit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!