boost::read_graphviz - 如何读出属性
boost::read_graphviz - how to read out properties?
我正在尝试从Graphviz DOT文件中读取图形。我对顶点的两个属性感兴趣 - 它的 id 和外围。A 还想加载图形标签。
我的代码如下所示:
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);
我的示例 DOT 文件如下所示:
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"]
}
当我运行它时,我收到异常"找不到属性:标签"。我做错了什么?
您没有为"label"定义(动态)属性映射。
使用ignore_other_properties
或定义它:)
在下面的示例中,使用 ignore_other_properties
可以防止需要rankdir
(图形属性)和width
、 style
(顶点属性):
住在科里鲁
#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;
}
哪个成功运行
有关在 Boost::Graph 中使用 dynamic_properties
: read_graphviz() 的更多说明,请参阅此处,传递给构造函数
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 函数何时会在c++中包含stack_Unwind_Resume调用
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- Python中的for循环与C++有何不同
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- C++调用具有 *this 属性的单个帮助程序函数
- boost::read_graphviz - 如何读出属性