- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Boost Graph Library 生成一个显示水平图的 .dot。
创建图表时我的代码如下所示:
struct VertexP {
std::string tag;
};
struct EdgeP {
std::string symbol;
};
struct GraphP{
std::string orientation;
};
typedef boost::adjacency_list<boost::vecS,
boost::vecS, boost::directedS,
VertexP, EdgeP, GraphP> Graph;
GraphP property;
property.orientation = "LR";
Graph graph(property);
// Then fill the graph
我用来生成 .dot 文件的代码是这样的:
Graph g = creator.AutomatonToGraph(&automaton);
ofstream dot_file("automaton.dot");
dynamic_properties dp;
dp.property("node_id", get(&VertexP::tag, g));
dp.property("label", get(&VertexP::tag, g));
dp.property("label", get(&EdgeP::symbol, g));
write_graphviz_dp(dot_file, g, dp);
这会用节点和边标签完美地写入 .dot 文件,但我的问题是我想将 rankdir=LR
图形属性添加到输出文件。我试过:
Graph g = creator.AutomatonToGraph(&automaton);
ofstream dot_file("automaton.dot");
dynamic_properties dp;
dp.property("node_id", get(&VertexP::tag, g));
dp.property("label", get(&VertexP::tag, g));
dp.property("label", get(&EdgeP::symbol, g));
dp.property("rankdir", get(&GraphP::orientation, g));
write_graphviz_dp(dot_file, g, dp);
但是我从这里开始遇到了一大堆错误:
/src/lab2.cc:48:55: required from here
/usr/include/boost/graph/detail/adjacency_list.hpp:2585:29: error: forming reference to void
typedef value_type& reference;
^~~~~~~~~
我真的是 BGL 的新手,我做错了什么?
最佳答案
阅读 dynamic_graph_properties_writer
的实现,我想你可能应该这样做
dp.property("rankdir", boost::make_constant_property<Graph*>(std::string("LR")));
对于动态检索,您可以使用函数属性映射:( map set/get requests into C++ class/structure changes ):
#include <boost/property_map/function_property_map.hpp>
dp.property("rankdir", boost::make_function_property_map<Graph*>([](Graph const* g) { return g->m_property->orientation; }));
#include <boost/graph/adj_list_serialize.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/property_map/function_property_map.hpp>
#include <fstream>
using namespace boost;
struct VertexP { std::string tag; };
struct EdgeP { std::string symbol; };
struct GraphP { std::string orientation; };
typedef adjacency_list<vecS, vecS, directedS, VertexP, EdgeP, GraphP> Graph;
int main() {
Graph g(GraphP{"LR"});
// Then fill the graph
add_edge(
add_vertex(VertexP{ "tag1" }, g),
add_vertex(VertexP{ "tag2" }, g),
EdgeP{ "symbol" }, g
);
{
std::ofstream dot_file("automaton.dot");
dynamic_properties dp;
dp.property("node_id", get(&VertexP::tag, g));
dp.property("label", get(&VertexP::tag, g));
dp.property("label", get(&EdgeP::symbol, g));
dp.property("rankdir", boost::make_constant_property<Graph*>(std::string("LR")));
dp.property("dummy", boost::make_function_property_map<Graph*>([](Graph const* g) { return g->m_property->orientation; }));
write_graphviz_dp(dot_file, g, dp);
}
}
哪个写
digraph G {
dummy=LR;
rankdir=LR;
tag2 [label=tag2];
tag1 [label=tag1];
tag1->tag2 [label=symbol];
}
关于c++ - boost::write_graphviz - 如何水平生成图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45426129/
我正在学习 boost::graph 并尝试将 name 属性添加到 Vertex。然而,这样做之后,write_graphviz 不会保存任何东西(没有这个属性,它可以工作)。 头文件: struc
我正在尝试使用 Boost Graph Library 生成一个显示水平图的 .dot。 创建图表时我的代码如下所示: struct VertexP { std::string tag; };
以下代码有错误: 无法将‘std::basic_ostream’左值绑定(bind)到‘std::basic_ostream&& #include void foo(int,char*[]) {
我试图让 BGL 输出一个只有边的文件,因为我正在做一个最大连通分量并且我不想删除顶点但如果没有边我也不想绘制它们. 我现在的点文件是: graph G { 0; 1; 2; 3; 4; 5; 6;
我正在努力将图表转储到流中,其中所述图表是 boost::subgraph 的简化版本。 我尝试提供一个 property writer但基本上它失败了,因为它似乎需要一个方法 boost::get(
您好,以下代码中的任何一处,make_edge_writer 函数无法在 gcc4.9 中推断类型。我的代码基于此处找到的以下答案 How to print a graph in graphviz w
是否可以使用 ::boost::write_graphviz 生成 DOT 子图? 例如,如果我在图 G 中创建一个子图 G0,我能否在 DOT 输出中得到如下内容: graph G { subg
这个问题是关于 boost::graph 以及如何处理与顶点(和/或边)相关联的属性。我对处理这个问题很困惑,但我怀疑它可能是与模板相关的问题。 假设我有这个图形定义: struct myVertex
为什么我不能编译以下简单的应用程序。如果我将 listS 更改为 vecS,则一切正常。 (我使用的是 boost 1.46.1 和 gcc 4.4.5) #include #include #i
我是一名优秀的程序员,十分优秀!