2

「test.dot」という名前のファイルがあります。

graph {
    0;
    1;
    0 -- 1;
}
//EOF

ブースト グラフ ライブラリを使用してファイルを読み込みたい。

#include <boost/graph/graphviz.hpp>

using namespace std;
using namespace boost;

int main(int,char*[])
{
    typedef adjacency_list< vecS, vecS, undirectedS, property<vertex_color_t,int> > Graph;
    Graph g(0);

    dynamic_properties dp;
    auto index = get(vertex_color, g);
    dp.property("node_id", index);

    ifstream fin("test.dot");
    read_graphviz(fin, g, dp);
}

ただし、このソース コードでは、"node_id" を格納するために別のプロパティ (vertex_color_t) を追加する必要がありました。私の簡単な例では、「node_index」と同じです。

メモリを節約するためにそれらを識別する方法はありますか?? 追加のプロパティを導入したくありません。

4

1 に答える 1

1

dynamic_propertiesには、デフォルトのケースを処理するファンクタを受け入れるコンストラクタがあり、1 つの実装はboost::ignore_other_propertiesです。これは機能します:

#include <boost/graph/graphviz.hpp>

using namespace std;
using namespace boost;

int main(int,char*[])
{
    typedef adjacency_list< vecS, vecS, undirectedS > Graph;
    Graph g(0);

    dynamic_properties dp(ignore_other_properties);
    ifstream fin("test.dot");
    read_graphviz(fin, g, dp);
}
于 2014-08-11T21:44:29.323 に答える