c++ - 如何访问 boost 子图 'graph' 属性?

标签 c++ boost graph properties boost-graph

我正在使用 adjacency_list 和子图适配器来创建我的图类型。

#include <boost/graph/subgraph.hpp>
#include <boost/graph/adjacency_list.hpp>

struct VertexProperties
{
    bool bIsExpandable;          
    string sId;
    string sCoord_X;
    string sCoord_Y;
    std::size_t order;
};

struct EdgeProperties
{
    string sId;
    bool bBidirectional;
};

//Graph properties
enum graph_index_t {graph_index=111};
namespace boost{
BOOST_INSTALL_PROPERTY(graph,index);
}

typedef boost::property<boost::vertex_index_t, std::size_t , VertexProperties> vertex_prop;
typedef boost::property<boost::edge_index_t, std::size_t , EdgeProperties> edge_prop;
typedef boost::property<graph_index_t, std::size_t> graph_prop;

typedef boost::adjacency_list<
boost::listS,
boost::vecS,
boost::bidirectionalS,
vertex_prop ,
edge_prop,
graph_prop>
Graph;

typedef boost::subgraph<Graph> Subgraph;

我正在为顶点和边使用捆绑属性。我已经尝试将捆绑属性赋予“图形”,因为 adjacency_list 它工作正常但不能用于子图适配器,我发现它不受 boost 子图适配器的支持。所以我将 graph_index_t 添加到图形属性,但我无法访问它。我已经编写了以下属性映射来访问它,但它似乎不是正确的方法。

typedef property_map<Subgraph , graph_index_t>::type GraphIndexPropertyMap;

它在 adjacency_list.hpp 中给出错误

d:\boost_1_53_0\boost\graph\detail\adjacency_list.hpp:2543: error: forming reference to void

我已经查看了 boost 1.53 文档,但找不到与此相关的方法。

所以我有两个问题:

1) 如何获得对 graph_index 属性的读写权限?

2) 我能否以某种方式将“图形”的捆绑属性与 boost 子图一起使用?

有人能帮忙吗?

谢谢,

实践

最佳答案

这个答案来得太晚了!但我刚刚遇到了同样的问题,花了一段时间才弄明白,所以我想分享一下我的解决方案。

捆绑属性不是一种选择。文档中没有任何内容说明为什么以下内容不起作用。然而,子图实现似乎不兼容,因为它无法编译。

Graph = boost::subgraph<boost::adjacency_list<
        boost::vecS,
        boost::vecS,
        boost::directedS,
        boost::property<boost::vertex_index_t, std::size_t>,
        boost::property<boost::edge_index_t, std::size_t>,
        std::string>>;

Graph graph;
graph[boost::graph_bundle] = "Graph bundle value";

但是,以下解决方案确实对我有用。在subgraph docs page的底部他们详细介绍了 get_property 函数,该函数具有只读版本(返回 const ref)和可写版本(返回 ref)。

namespace boost{
enum graph_index_t {graph_index=111};
BOOST_INSTALL_PROPERTY(graph,index);
}

Graph = boost::subgraph<boost::adjacency_list<
        boost::vecS,
        boost::vecS,
        boost::directedS,
        boost::property<boost::vertex_index_t, std::size_t>,
        boost::property<boost::edge_index_t, std::size_t>,
        boost::property<boost::graph_index_t, std::size_t>>>;

Graph graph;
boost::get_property(graph, boost::graph_index) = 69;

关于c++ - 如何访问 boost 子图 'graph' 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19360643/

相关文章:

c++ - 定位涉及线和圆相交的小部件?

c++ - 使用聚合初始化初始化数组成员

c++ - 链接失败,并带有对libboost_thread的 undefined reference

R过渡图

C++/OpenGL VAO 问题

python - C 编译的程序在我的 Windows 10 中无法运行

c++ - boost::threads 程序导致大量竞争条件

c++ - 是否 boost::io_service::post 队列请求?

algorithm - 什么是父节点以及如何存储它?

javascript - jQuery/JS 图表 - 根据条件绘制不同颜色的线条