- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
这个问题是关于 boost::graph 以及如何处理与顶点(和/或边)相关联的属性。我对处理这个问题很困惑,但我怀疑它可能是与模板相关的问题。
假设我有这个图形定义:
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;
据我所知,这种存储顶点属性的方式称为“bundle properties”并且似乎是存储此信息的第三种方式,尽管据说 in the manual那:
There are two kinds of graph properties: interior and exterior.
回到我的主要问题。现在,我可以通过这种方式使用“点”格式实例化并打印出图形:
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);
}
这是基于this answer在类似的问题中,并且编译得很好。
现在我想在一个单独的函数中分离打印,所以我在模板函数中编写了相同代码,只是用模板类型参数替换了具体类型:
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 );
}
但是这个does not compile :
property_map.hpp:361:44: error: assignment of read-only location ...
知道我做错了什么吗?
最佳答案
property_map.hpp:361:44: error: assignment of read-only location ...
是的,可悲的是 g
是 const 的事实使得默认的 property
工厂函数是非法的。如果模型允许,动态属性以可写的方式构造:
Requirements:
PropertyMap
must model Readable Property Map or Read/Write Property Map.
由于属性映射是可写的,所以动态属性也编译写分支。
您必须将参数作为非常量或手动覆盖底层映射的属性特征(示例请参见此处的注释 (Cut set of a graph, Boost Graph Library))。
您可能会考虑将此报告为可用性问题,因为从逻辑上讲,属性应该在那里是常量。
关于c++ - boost::graph 编译问题与 dynamic_properties 和 write_graphviz,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34160290/
我正在学习 boost::graph 并尝试将 name 属性添加到 Vertex。然而,这样做之后,write_graphviz 不会保存任何东西(没有这个属性,它可以工作)。 头文件: struc
我正在尝试使用 Boost Graph Library 生成一个显示水平图的 .dot。 创建图表时我的代码如下所示: struct VertexP { std::string tag; };
以下代码有错误: 无法将‘std::basic_ostream’左值绑定(bind)到‘std::basic_ostream&& #include void foo(int,char*[]) {
我试图让 BGL 输出一个只有边的文件,因为我正在做一个最大连通分量并且我不想删除顶点但如果没有边我也不想绘制它们. 我现在的点文件是: graph G { 0; 1; 2; 3; 4; 5; 6;
我正在努力将图表转储到流中,其中所述图表是 boost::subgraph 的简化版本。 我尝试提供一个 property writer但基本上它失败了,因为它似乎需要一个方法 boost::get(
您好,以下代码中的任何一处,make_edge_writer 函数无法在 gcc4.9 中推断类型。我的代码基于此处找到的以下答案 How to print a graph in graphviz w
是否可以使用 ::boost::write_graphviz 生成 DOT 子图? 例如,如果我在图 G 中创建一个子图 G0,我能否在 DOT 输出中得到如下内容: graph G { subg
这个问题是关于 boost::graph 以及如何处理与顶点(和/或边)相关联的属性。我对处理这个问题很困惑,但我怀疑它可能是与模板相关的问题。 假设我有这个图形定义: struct myVertex
为什么我不能编译以下简单的应用程序。如果我将 listS 更改为 vecS,则一切正常。 (我使用的是 boost 1.46.1 和 gcc 4.4.5) #include #include #i
我是一名优秀的程序员,十分优秀!