2

I have a file named "test.dot" something like,

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

I want to read a file using boost graph library.

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

However, in this source code, I had to attach another property(vertex_color_t) to store "node_id". In my simple example, it is just the same as "node_index".

Is there a way that I can identify them to save memory?? I don't want to introduce additional property.

4

1 回答 1

1

dynamic_properties有一个构造函数,它接受一个函子来处理默认情况,一种实现是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 回答