gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:17:13 26 4
gpt4 key购买 nike

我正在使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com