boost::dynamic.properties和write_graphviz的图形编译问题
boost::graph compilation issue with dynamic_properties and write_graphviz
这个问题是关于boost::图以及如何处理与顶点(和/或边)关联的属性。我对处理这个问题很困惑,但我怀疑这可能是一个与模板有关的问题。
假设我有这个图形定义:
struct myVertex_t {
int color;
};
typedef boost::adjacency_list<
boost::vecS, // edge container
boost::vecS, // vertex container
boost::undirectedS, // type of graph
myVertex_t, // vertex properties
boost::property< // edge properties
boost::edge_color_t, // ???
boost::default_color_type // enum, holds 5 colors
>
> myGraph_t;
AFAIK,这种存储顶点属性的方法称为"捆绑包属性"并且似乎是存储这些信息的第三种方式,尽管据说在手册中即:
图的属性有两种:内部和外部。
回到我的主要问题。现在,我可以通过以下方式使用"点"格式安装和打印图形:
int main()
{
myGraph_t g;
boost::add_edge(0, 1, g);
boost::dynamic_properties dp;
dp.property("color", boost::get( &myVertex_t::color, g ) );
dp.property("node_id", boost::get( boost::vertex_index, g ) );
boost::write_graphviz_dp( std::cout , g, dp);
}
在线此处
这是基于这个答案在一个类似的问题上,并且编译得很好。
现在我想在一个单独的函数中分离打印,所以我在模板化函数中编写相同的代码,只是用模板类型参数替换具体类型:
template<typename graph_t, typename vertex_t>
void RenderGraph( const graph_t& g )
{
boost::dynamic_properties dp;
dp.property( "color", boost::get( &vertex_t::color, g ) );
dp.property( "node_id", boost::get( boost::vertex_index, g ) );
boost::write_graphviz_dp( std::cout, g, dp );
}
int main()
{
myGraph_t g;
boost::add_edge(0, 1, g);
RenderGraph<myGraph_t,myVertex_t>( g );
}
但这并不能编译:
property_map.hpp:361:44:错误:分配只读位置。。。
你知道我做错了什么吗?
property_map.hpp:361:44:错误:分配只读位置。。。
是的,遗憾的是,g
在那里是常量,这使得默认的property
工厂函数是非法的。如果模型允许,动态属性将以可写的方式构建:
要求:
PropertyMap
必须为可读属性映射或读/写属性映射建模。
因为属性映射是可写的,所以动态属性也编译写入分支。
您必须将参数设为非常数,或者手动覆盖底层映射的属性特征(请参阅此处的注释(例如图的剪切集,Boost graph Library))。
您可能会考虑将其报告为可用性问题,因为从逻辑上讲,属性应该是常量。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- 替代在python中制作邻接列表与图形问题的字典?(如 C++ 中的 vector<vector<int&g
- 使用 scanf 读取文件中的图形时出现问题
- 图形视图缩小比例问题
- 在C++中实现图形 DFS,指针问题
- 绘制非常大的 2D 图形时出现问题
- 在C++中实现图形类时遇到问题
- 声明在 Linux 上存在有关 X11 图形库的问题
- boost::dynamic.properties和write_graphviz的图形编译问题
- turbo Borland C++v3.0图形问题
- 巨大的图形存储问题
- 从类中访问结构和实现图形的其他问题
- C++图形构建问题
- 图形遍历问题