Simple point-to-point output for Boost Graph edges indicated by base types
Using bound properties with the Boost Graph library means it's very easy to write code to output a graphviz-compatible dot file:
#include <boost/graph/graphviz.hpp>
struct Edge { int i; };
int main()
{
using namespace boost;
typedef adjacency_list<vecS, vecS, directedS, no_property, Edge> Graph;
Graph g;
add_edge(0, 1, {123}, g);
write_graphviz(std::cout, g, default_writer(),
make_label_writer(boost::get(&Edge::i,g)));
return 0;
}
In the above code, the edge property is defined using a structure named Edge
. This structure contains only one int
; boost::get
then provides the make_label_writer
required PropertyWriter
.
If instead I would like to use a base type, for example int
or double
, for the edge property, what arguments do I now need to pass to make_label_writer
? Can the code remain comparable to the above. For example, it adjacency_list
can be declared as:
typedef adjacency_list<vecS, vecS, directedS, no_property, int> Graph;
source to share
You accessed the boundary set directly.
With bound properties, the non-member-pointer-property tag is implicitly applied to the property value
edge_bundle_t
(orvertex_bundle_t
orgraph_bundle_t
as the case may be; therefore, you don't want to use the same custom type for edge / vertex / graph sets).
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
int main()
{
using namespace boost;
typedef adjacency_list<vecS, vecS, directedS, no_property, int> Graph;
Graph g;
add_edge(0, 1, 123, g);
write_graphviz(std::cout, g, default_writer(),
make_label_writer(boost::get(edge_bundle,g)));
}
Output:
digraph G {
0;
1;
0->1 [label=123];
}
source to share