【问题标题】:read dot file for graphviz without storing node-id in boost graph读取graphviz的点文件而不在boost图中存储节点ID
【发布时间】:2012-11-30 01:38:56
【问题描述】:

我有一个名为“test.dot”的文件,类似于,

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

我想使用 boost 图形库读取文件。

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

但是,在这个源代码中,我必须附加另一个属性(vertex_color_t)来存储“node_id”。 在我的简单示例中,它与“node_index”相同。

有没有办法可以识别它们以节省内存?我不想引入额外的属性。

【问题讨论】:

  • 代码中的node_index 在哪里?只是更改 node_id 属性的名称(请参阅read_graphviz 文档以了解如何做到这一点)就足够了吗?

标签: c++ boost boost-graph


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 2020-02-29
    • 1970-01-01
    • 2017-05-13
    • 1970-01-01
    相关资源
    最近更新 更多