C++BOOST库和捆绑属性
C++ BOOST library and bundled properties
我正试图使用Boost制作一个图形挖掘程序,所以我从图形结构开始,下面是我制作的代码:
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
//vertex
struct VertexProperties
{
int id;
int label;
VertexProperties()= default;
VertexProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
//edge
struct EdgeProperties
{
unsigned id;
unsigned label;
EdgeProperties()= default;
EdgeProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
//Graph
struct GraphProperties
{
unsigned id;
unsigned label;
GraphProperties()= default;
GraphProperties(unsigned i, unsigned l) : id(i), label(l) {}
};
//adjency list
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::directedS,
VertexProperties,
EdgeProperties,
GraphProperties
> Graph;
//iterators
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t;
typedef boost::graph_traits<Graph>::edge_descriptor edge_t;
/***********************************************/
int main()
{
Graph g;
vertex_t v1 = boost::add_vertex(VertexProperties(1,10),g);
vertex_t v2 = boost::add_vertex(VertexProperties(2,20),g);
//edge_t e1= boost::add_edge(EdgeProperties(3,55),g);
std::cout << "Vertice: " <<num_vertices(g) << std::endl;
std::cout << "edges: " <<num_edges(g) << std::endl;
return 0;
}
这一行有个问题:
edge_t e1= boost::add_edge(EdgeProperties(3,55),g);
如何创建此边?PS:请告诉我代码是否正确(我指的是vue的概念pont)
注意:我使用的是GCC 4.8(带有-std=c++11标志)和Boost 1.48。
我看到您的代码有两个问题。首先,传递给boost::add_edge(…)的前两个参数应该是与边关联的顶点。所以在你的情况下,电话将是
edge_t e1= boost::add_edge(v1, v2, EdgeProperties(3,55),g);
其次,据我所知,e1的类型应该是
std::pair<edge_descriptor, bool>
所以你的第二个typedef应该是
typedef std::pair<boost::graph_traits<Graph>::edge_descriptor, bool> edge_t;
或者,您可以只使用auto关键字来描述e1的类型。例如,
auto e1= boost::add_edge(v1, v2, EdgeProperties(3,55),g);
相关文章:
- boost::spirit指针属性是用nullptr初始化的吗?
- Boost.Python 列出了所有公开的类和属性
- 如何使用 boost 属性树来解析 boost 中 json 字符串中的数组中的元素?
- boost::log 设置"Channel"通道记录器中的属性
- 如何在Boost Graph库中的Grid_graph的边缘添加自定义属性
- boost :: Spirit :: Karma语法:逗号从结构上划定了带有选件属性的输出
- 如何将Boost属性树的子树序列化为XML
- 如何使用Boost C 属性映射从配置文件中提取值
- 使用自定义的边缘属性 boost::adjacency_list 遍历边缘
- Boost:列出GraphMl中指定的顶点和边缘属性
- boost :: spirit :: x3中的connathesting std ::对属性属性
- 使用Boost ::几何多边形布尔/与线段属性的交叉点
- boost :: Spirit属性分配:struct is_nullary:基本类型无法成为结构或类型
- 如何使用boost::graph dijkstra的算法,如果顶点属性是指针?
- Boost::p tree - 访问列表中包含的属性树节点
- 如何通过 boost::log 打印到具有不同属性的不同日志?
- boost::serialization-序列化从泛型属性/功能容器派生的类
- 如何手动创建带有XML属性的boost ptree
- 如何将多态属性与boost::spirit::qi解析器一起使用
- 具有关联属性的 boost::hash_combine 的替代方案