编译图形与问题和dynamic

编译图形与问题和dynamic

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

问题描述

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

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

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

AFAIK,存储用于顶点属性的这种方式被称为

似乎是一个第三存储这些信息的方式,虽然有人说
在手动
即:

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 answerin 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:

Any ideas what I did wrong ?

解决方案

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:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 04:25