簡體   English   中英

與dynamic_properties和write_graphviz有關的boost :: graph編譯問題

[英]boost::graph compilation issue with dynamic_properties and write_graphviz

這個問題是關於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;

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 )。

您可能會考慮將其報告為可用性問題,因為從邏輯上講,屬性應該在那里const

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM