以下代码有错误:
无法将'std :: basic_ostream'左值绑定到'std :: basic_ostream&&
#include <boost/graph/graphviz.hpp>
void foo(int,char*[])
{
using namespace boost;
typedef boost::adjacency_list<
boost::setS, // outedge list
boost::setS, // vertex list
boost::directedS, // undirected
boost::no_property, // vertex prop
boost::no_property, // edge prop
boost::no_property, // graph prop
boost::setS // edgelistc
> Graph;
Graph g;
std::ostringstream dotname;
dotname << "a.dot";
std::ofstream dot(dotname.str());
write_graphviz(dot, g);
}
它适用于何时 boost :: vecS,//顶点列表
预期吗?
答案 0 :(得分:2)
将顶点容器选择器更改为setS
将顶点描述符更改为不可流化的类型。
与BGL中的许多其他算法一样,您应该传递一个单独的顶点索引:
IN:
VertexAndEdgeListGraph& g
有向图或无向图。图表的类型必须是模型
VertexAndEdgeListGraph
。在大多数情况下,图表必须具有内部vertex_index
属性地图。
<强> Live On Coliru 强>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/random.hpp>
#include <random>
int main(int,char*[])
{
using namespace boost;
typedef boost::adjacency_list<setS, setS, directedS> Graph;
Graph g;
std::mt19937 prng{std::random_device{}()};
generate_random_graph(g, 3, 5, prng);
std::map<Graph::vertex_descriptor, size_t> ids;
for (auto u : make_iterator_range(vertices(g)))
ids[u] = ids.size();
default_writer w;
write_graphviz(std::cout, g, w, w, w, make_assoc_property_map(ids));
}
打印例如
digraph G {
1;
2;
3;
1->2 ;
2->1 ;
2->3 ;
3->1 ;
3->2 ;
}
您可以在内部放置该属性,而无需进行太多更改:
<强> Live On Coliru 强>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/random.hpp>
#include <random>
int main(int,char*[])
{
using namespace boost;
typedef boost::adjacency_list<setS, setS, directedS, property<vertex_index_t, size_t> > Graph;
Graph g;
std::mt19937 prng{std::random_device{}()};
generate_random_graph(g, 3, 5, prng);
auto ids = get(vertex_index, g);
size_t num = 0;
for (auto u : make_iterator_range(vertices(g)))
put(ids, u, num++);
write_graphviz(std::cout, g);
}