读取图形可视化的点文件,而无需在提升图中存储节点 ID

read dot file for graphviz without storing node-id in boost graph

本文关键字:ID 节点 存储 可视化 图形 文件 读取      更新时间:2023-10-16

我有一个名为"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);
}

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

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

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