提高::编译图形与问题和dynamic_properties的write_graphviz [英] boost::graph compilation issue with dynamic_properties and write_graphviz

查看:403
本文介绍了提高::编译图形与问题和dynamic_properties的write_graphviz的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这问题是有关的boost ::图,以及如何处理相关联的顶点(和/或边缘)的属性。我很困惑怎样处理这个,但我怀疑它可能是一个模板相关的问题。

让我们说我有这个图的定义:

 结构myVertex_t {
    INT色;
};TYPEDEF提振::的adjacency_list<
    促进血管内皮细胞:: //边缘集装箱
    促进血管内皮细胞:: //顶点容器
    提高:: undirectedS,//图的类型
    myVertex_t,//顶点属性
    提高::财产< //边缘性质
        提高:: edge_color_t,//?
        提高:: default_color_type //枚举,拥有5种颜色
    >
> myGraph_t;

AFAIK,存储用于顶点属性的这种方式被称为
包属性
似乎是一个第三存储这些信息的方式,虽然有人说
在手动
即:


  

有两种图形性能:内部和外部。


回到我的主要问题。现在,我可以实例化和打印输出使用点的图形格式是这样的:

  INT的main()
 {
    myGraph_t克;
    升压::的add_edge(0,1,G);    提高:: dynamic_properties的DP;
    dp.property(色,助推::得到(安培; myVertex_t ::色,G));
    dp.property(NODE_ID,助推::得到(的boost ::的vertex_index,g)条);
    提高:: write_graphviz_dp(标准::法院,G DP);
 }

在线这里

这是基于这个答案
在一个类似的问题,并编译罚款。

现在我想打印在一个单独的功能分开,所以我写的相同 code在模板功能,只需用模板类型参数代替具体的类型:

 模板< typename的graph_t,类型名vertex_t>
无效RenderGraph(常量graph_t&放大器; G)
{
    提高:: dynamic_properties的DP;
    dp.property(色,助推::得到(安培; vertex_t ::色,G));
    dp.property(NODE_ID,助推::得到(的boost ::的vertex_index,g)条);
    提高:: write_graphviz_dp(标准::法院,G DP);
}诠释的main()
{
    myGraph_t克;
    升压::的add_edge(0,1,G);    RenderGraph< myGraph_t,myVertex_t>(七);
}

但是,这不会编译


  

property_map.hpp:361:44:错误:只读位置分配...


任何想法,我做错了什么?


解决方案

  

property_map.hpp:361:44:错误:只读位置分配...


呀,可悲的事实是先按g 是const的存在使得默认属性工厂函数是非法的。动态属性在一个可写的方式构成,如果模型允许它:


  

要求: PropertyMap 必须符合可读Property Map或读/写属性映射


由于属性映射是可写的,动态特性编译写作的分支了。

您不得不采取的参数作为非const或手动覆盖物业性状的基本地图(见这里的评论(<一个href=\"http://stackoverflow.com/questions/26697477/cut-set-of-a-graph-boost-graph-library/26699982#26699982\">Cut图的设置,Boost图库)的例子)。

你可能会考虑报告这是一个可用性问题,在逻辑上,该属性应该是const有

This question is about boost::graph and how to handle properties associated to vertices (and/or edges). I am quite confused about handling this, but I suspect it could be a template-related issue.

Let's say I have this graph definition:

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, this way of storing properties for vertices is called "bundle properties" and seems to be a third way of storing this information, although it is said in the manual that:

There are two kinds of graph properties: interior and exterior.

Back to my main question. Now, I can instanciate and printout a graph using the "dot" format this way:

 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);
 }

Online here

This is based on this answer in a similar question, and compiles fine.

Now I want to separate the printing in a separate function, so I write the same code in a templated function, just replacing concrete types with template type arguments:

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 );
}

But this does not compile:

property_map.hpp:361:44: error: assignment of read-only location ...

Any ideas what I did wrong ?

解决方案

property_map.hpp:361:44: error: assignment of read-only location ...

Yeah, sadly the fact that g is const there makes the default property factory function illegal. Dynamic properties are constructed in a writable way if the model allows it:

Requirements: PropertyMap must model Readable Property Map or Read/Write Property Map.

Because the property map is writable, the dynamic property compiles the writing branch too.

You'd have to take the argument as non-const or manually override the Property traits for the underlying maps (see the comments here (Cut set of a graph, Boost Graph Library) for an example).

You might consider reporting this as a usability issue, as logically, the properties should be const there.

这篇关于提高::编译图形与问题和dynamic_properties的write_graphviz的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆