谁能给我一个例子,使用smallst_last_vertex_ordering在boost::graph
Can anybody give me an example of use the smallest_last_vertex_ordering in boost::graph?
我是boost编程的新手,但我希望在顶点着色上使用boost图库。
我已经在boost/graph/smallest_last_ordering.hpp中阅读了帮助文档和smallst_last_vertex_ordering的源代码。但是我不知道如何构造函数smallst_last_vertex_ordering的参数。
下面是smallst_last_vertex_ordering的定义:
template <class VertexListGraph, class Order, class Degree, class Marker>
void
smallest_last_vertex_ordering(const VertexListGraph& G, Order order,
Degree degree, Marker marker) {
typedef typename boost::graph_traits<VertexListGraph> GraphTraits;
typedef typename GraphTraits::vertex_descriptor Vertex;
//typedef typename GraphTraits::size_type size_type;
typedef std::size_t size_type;
const size_type num = num_vertices(G);
typedef typename boost::property_map<VertexListGraph, vertex_index_t>::type ID;
typedef bucket_sorter<size_type, Vertex, Degree, ID> BucketSorter;
BucketSorter degree_bucket_sorter(num, num, degree,
get(vertex_index,G));
smallest_last_vertex_ordering(G, order, degree, marker, degree_bucket_sorter);
}
你能告诉我如何创建正确的Order, degree和Marker类吗?
查看Order
的实现似乎是一个属性映射,它具有std::size_t作为键和vertex_descriptor作为value_type。Degree
和Marker
是以vertex_descriptor为key, std::size_t为value_type的属性映射。这最后两个映射只在内部需要,这就是为什么只有两个参数(graph和order property map)的重载的原因。
下面是一个使用重载和有向版本(为了避免这个算法显然不支持的循环)的图的例子:
#include <iostream>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/shared_array_property_map.hpp> //this should be included from smallest_last_ordering.hpp
#include <boost/graph/smallest_last_ordering.hpp>
int main()
{
typedef boost::adjacency_list<boost::vecS,boost::vecS,boost::directedS> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDesc;
Graph g;
VertexDesc A=add_vertex(g);
VertexDesc B=add_vertex(g);
VertexDesc C=add_vertex(g);
VertexDesc D=add_vertex(g);
VertexDesc E=add_vertex(g);
add_edge(A,C,g);
add_edge(A,E,g);
add_edge(C,B,g);
add_edge(E,B,g);
add_edge(C,D,g);
add_edge(B,D,g);
add_edge(E,D,g);
boost::vector_property_map<VertexDesc> order;
smallest_last_vertex_ordering(g, order);
std::string names[]={"A","B","C","D","E"};
for(std::size_t index=0; index<num_vertices(g); ++index)
{
std::cout << names[order[index]] << " ";
}
std::cout << std::endl;
}
,这是一个使用四个参数重载的版本,所以你可以看到另一种定义属性映射的方式:
#include <iostream>
#include <string>
#include <map>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map/shared_array_property_map.hpp> //this should be included from smallest_last_ordering.hpp
#include <boost/graph/smallest_last_ordering.hpp>
int main()
{
typedef boost::adjacency_list<boost::vecS,boost::vecS,boost::directedS> Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor VertexDesc;
Graph g;
VertexDesc A=add_vertex(g);
VertexDesc B=add_vertex(g);
VertexDesc C=add_vertex(g);
VertexDesc D=add_vertex(g);
VertexDesc E=add_vertex(g);
add_edge(A,C,g);
add_edge(A,E,g);
add_edge(C,B,g);
add_edge(E,B,g);
add_edge(C,D,g);
add_edge(B,D,g);
add_edge(E,D,g);
typedef std::map<std::size_t,VertexDesc> OrderMap;
OrderMap order;
boost::associative_property_map<OrderMap> order_prop_map(order);
typedef std::map<VertexDesc,std::size_t> Map;
Map degree;
Map marker;
boost::associative_property_map<Map> degree_prop_map(degree);
boost::associative_property_map<Map> marker_prop_map(marker);
smallest_last_vertex_ordering(g, order_prop_map, degree_prop_map, marker_prop_map);
//another alternative
// std::vector<VertexDesc> order(num_vertices(g));
// std::vector<std::size_t> degree(num_vertices(g));
// std::vector<std::size_t> marker(num_vertices(g));
// smallest_last_vertex_ordering(g, make_iterator_property_map(&order[0],boost::identity_property_map()), make_iterator_property_map(°ree[0],get(boost::vertex_index,g)), make_iterator_property_map(&marker[0],get(boost::vertex_index,g)));
std::string names[]={"A","B","C","D","E"};
for(std::size_t index=0; index<num_vertices(g); ++index)
{
std::cout << names[order[index]] << "(" << degree[order[index]] << "," << marker[order[index]] << ") ";
}
std::cout << std::endl;
}
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- C++:TypeDef使用元组
- 使用std::multimap迭代器创建std::list
- 从不同线程使用int64的不同字节安全吗
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么在全局范围内使用"extern int a"似乎不行?
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用Google Mock来模拟gettimeofday()
- 如何使用默认参数等选择模板专业化
- 为什么使用 "this" 指针调用派生成员函数?
- 使用新行和不使用新行读取文件
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 如何确定我已使用非编码文件到达 EOF?
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 使用CMake创建QML插件
- 使用strcpy将char数组的元素复制到另一个数组
- 如何使用一对迭代器[first, last]在模板中创建容器
- 仅使用"last"参数来提升范围
- 使用 boost::d ate,如何计算"last Monday"?