提高:: read_graphviz - 如何读出的属性? [英] boost::read_graphviz - how to read out properties?

查看:171
本文介绍了提高:: read_graphviz - 如何读出的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的Graphviz点文件的图形。我感兴趣的两个属性为顶点 - 它的ID和边缘。 A也想加载图形标签。

I am trying to read a graph from Graphviz DOT file. I am interested in two properties for Vertex - its id and peripheries. A also want to load graph labels.

我的code是这样的:

My code looks like this:

struct DotVertex {
    std::string name;
    int peripheries;
};

struct DotEdge {
    std::string label;
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
        DotVertex, DotEdge> graph_t;

    graph_t graphviz;
    boost::dynamic_properties dp;

    dp.property("node_id", boost::get(&DotVertex::name, graphviz));
    dp.property("peripheries", boost::get(&DotVertex::peripheries, graphviz));
    dp.property("edge_id", boost::get(&DotEdge::label, graphviz));

    bool status = boost::read_graphviz(dot, graphviz, dp);

我的样本点文件看起来是这样的:

My sample DOT file looks like this:

digraph G {
  rankdir=LR
  I [label="", style=invis, width=0]
  I -> 0
  0 [label="0", peripheries=2]
  0 -> 0 [label="a"]
  0 -> 1 [label="!a"]
  1 [label="1"]
  1 -> 0 [label="a"]
  1 -> 1 [label="!a"]
}

当我运行它,我得到未找到属性:标签异常。我在做什么错了?

When I run it, I get exception "Property not found: label". What am I doing wrong?

推荐答案

您没有定义标签的(动态)propertymap。

You didn't define the (dynamic) propertymap for "label".

或者使用 ignore_other_properties 或定义它:)

在下面的例子中,使用 ignore_other_properties $ P $需要pvents rankdir (图属性)和宽度风格(顶点属性):

In the sample below, using ignore_other_properties prevents requiring rankdir (graph property) and width, style (vertex properties):

<大骨节病> 住在Coliru

#include <boost/graph/graphviz.hpp>
#include <libs/graph/src/read_graphviz_new.cpp>
#include <iostream>

struct DotVertex {
    std::string name;
    std::string label;
    int peripheries;
};

struct DotEdge {
    std::string label;
};

typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
        DotVertex, DotEdge> graph_t;

int main() {
    graph_t graphviz;
    boost::dynamic_properties dp(boost::ignore_other_properties);

    dp.property("node_id",     boost::get(&DotVertex::name,        graphviz));
    dp.property("label",       boost::get(&DotVertex::label,       graphviz));
    dp.property("peripheries", boost::get(&DotVertex::peripheries, graphviz));
    dp.property("label",       boost::get(&DotEdge::label,         graphviz));

    bool status = boost::read_graphviz(std::cin, graphviz, dp);
    return status? 0 : 255;
}

成功地运行

在这里看到更多的解释关于使用的dynamic_properties :<一href=\"http://stackoverflow.com/questions/29496182/read-graphviz-in-boostgraph-pass-to-constructor/29501850#29501850\">read_graphviz()在升压::图,传递给构造器

See here for more explanations about using dynamic_properties: read_graphviz() in Boost::Graph, pass to constructor

这篇关于提高:: read_graphviz - 如何读出的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆