如何排列 boost::adjacency_list 中的节点?
假设以下 typedef 和定义:
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
int main()
{
typedef adjacency_list<vecS, vecS, directedS, property<vertex_index_t, int> > GraphTC;
GraphTC g;
typedef typename property_map<GraphTC, vertex_index_t>::const_type VertexIndexMap;
VertexIndexMap index_map = get(vertex_index, g);
typedef typename graph_traits<GraphTC>::vertex_descriptor tc_vertex;
std::vector<tc_vertex> to_tc_vec(num_vertices(g));
iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&>
g_to_tc_map(&to_tc_vec[0], index_map);
}
我有一个输出 g 和 g_to_tc_map 的算法(如上所述)。现在,我需要通过 g_to_tc_map (我认为这类似于整数数组或 std::map )来排列节点。
注意:我发现有一个 boost/graph/detail/permutation.hpp,但我不知道如何使用它(甚至出现仅包含此文件的错误,与其他标头冲突)。
感谢您提供如何进行此排列的任何想法/代码。
Pretend the following typedefs and defintiontions:
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
int main()
{
typedef adjacency_list<vecS, vecS, directedS, property<vertex_index_t, int> > GraphTC;
GraphTC g;
typedef typename property_map<GraphTC, vertex_index_t>::const_type VertexIndexMap;
VertexIndexMap index_map = get(vertex_index, g);
typedef typename graph_traits<GraphTC>::vertex_descriptor tc_vertex;
std::vector<tc_vertex> to_tc_vec(num_vertices(g));
iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&>
g_to_tc_map(&to_tc_vec[0], index_map);
}
I have an algorithm that outputs me g and g_to_tc_map (as above). Now, I need to permute the nodes by g_to_tc_map (which is, I think, something like an integer array or a std::map).
Note: I have found that there is a boost/graph/detail/permutation.hpp, but I have no idea how to use it (getting even bugs only including this file, conflicting with other headers).
Thanks for any idea/code how to do this permutation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以接受创建图形的排列副本,则可以使用迭代器范围创建新图形:
PS:使用
vecS< 的图形中不需要
vertex_index_t
属性/code> 顶点容器;它是自动创建(并填写)的。If you can live with creating a permuted copy of the graph, you can create the new graph using an iterator range:
PS: you don't need a
vertex_index_t
property in a graph withvecS
vertex container; it is created (and filled in) automatically.