如何在boost::邻接列表中排列节点
How to permute nodes in a boost::adjacency_list?
假设以下类型定义和定义:
#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,但我不知道如何使用它(甚至只包括这个文件的bug,与其他头文件冲突)。
感谢您提供任何关于如何进行此排列的想法/代码。
如果您可以创建图形的排列副本,则可以使用迭代器范围创建新图形:
struct permute_edge {
iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&> g_to_tc_map;
const GraphTC& g;
permute_edge(iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&> g_to_tc_map, const GraphTC& g): g_to_tc_map(g_to_tc_map), g(g) {}
std::pair<tc_vertex, tc_vertex> operator()(graph_traits<Graph>::edge_descriptor e) const {
return std::make_pair(get(g_to_tc_map, source(e, g)), get(g_to_tc_map, target(e, g));
}
};
permute_edge perm(g_to_tc_map, g);
typedef graph_traits<GraphTC>::edge_iterator edge_iterator;
std::pair<edge_iterator, edge_iterator> g_edges = edges(g);
GraphTC g_permuted(
make_transform_iterator(g_edges.first, perm),
make_transform_iterator(g_edges.second, perm),
num_vertices(g), num_edges(g));
PS:在具有vecS
顶点容器的图中,不需要vertex_index_t
属性;它是自动创建(并填充)的。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 为什么不;名字在地图上是按顺序排列的吗
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 在数组中输入 n 个整数的列表,并以类似于钟摆来回移动的方式排列它们. 输入-1 3 2 5 4,输出5 3 1 2 4
- 最大数量.给定一个非负整数列表,排列它们以使它们形成最大的数字
- 添加气泡排序代码以排列列表
- C 生成列表的不同排列
- 获得给定向量的排列索引列表的最佳方法是什么?
- 我可以使用普通的气泡排序来按字母顺序排列列表吗?
- 如何在C++中随机排列指针列表
- 如何在C++上按字母顺序排列列表
- 在用户完成拖放后重新排列多个选定的列表视图项
- 如何在boost::邻接列表中排列节点
- 计算包含某些项的列表集合的唯一排列的算法
- 我正在创建一个双链接列表,它将按字母顺序排列姓名列表,但我不确定在int main()函数中放入什么
- 使函数接受其参数列表的任意排列的规范方法是什么?