BGL: Custom Property Writer for Bundled Properties and listS as VertexList/EdgeListHow to use boost make_label_writer to write edge properties?Plus operator in boost qi doesn't work as expectedBGL Bundled Properties add_edge “no matching function”Dijkstra Shortest Path with VertexList = ListS in boost graphcustom properties for edges in the BGLBGL edge bundled propertiesboost graph library adjacency_list: maintain EdgeList sorted by EdgePropertiesBoost graph list or vecset is not member of boost::PolygonSetCandidate template ignored: deduced type does not match adjusted typeUse boost::geometry::svg_mapper with custom polygon

Do predators tend to have vertical slit pupils versus horizontal for prey animals?

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

Why should P.I be willing to write strong LOR even if that means losing a undergraduate from his/her lab?

My father gets angry everytime I pass Salam, that means I should stop saying Salam when he's around?

What is "super" in superphosphate?

Adding things to bunches of things vs multiplication

Why don't politicians push for fossil fuel reduction by pointing out their scarcity?

Repurpose telephone line to ethernet

What is bodily formation? Does it refer to the breath or the body?

Can 'in-' mean both 'in' and 'no'?

Chess software to analyze games

How could Tony Stark wield the Infinity Nano Gauntlet - at all?

Would it be illegal for Facebook to actively promote a political agenda?

Playing a fast but quiet Alberti bass

How do we test and determine if a USB cable+connector is version 2, 3.0 or 3.1?

Is there such a thing as too inconvenient?

The Lucky House

What can I do to keep a threaded bolt from falling out of it’s slot

Quick destruction of a helium filled airship?

Installing the original OS X version onto a Mac?

Why do balloons get cold when they deflate?

Independence of Mean and Variance of Discrete Uniform Distributions

Check disk usage of files returned with spaces

Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?



BGL: Custom Property Writer for Bundled Properties and listS as VertexList/EdgeList


How to use boost make_label_writer to write edge properties?Plus operator in boost qi doesn't work as expectedBGL Bundled Properties add_edge “no matching function”Dijkstra Shortest Path with VertexList = ListS in boost graphcustom properties for edges in the BGLBGL edge bundled propertiesboost graph library adjacency_list: maintain EdgeList sorted by EdgePropertiesBoost graph list or vecset is not member of boost::PolygonSetCandidate template ignored: deduced type does not match adjusted typeUse boost::geometry::svg_mapper with custom polygon






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1

















I take the the following code from this post and changed the VertexList and the EdgeList to listS instead of vecS.


I found out that because of the missing index make_label_writer(get(&VertexProps::name, g)) doesn't work. Could someone tell me how I should change the code to get it work. I would prefer a solution with a custom property writer.


Thank you very much.



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g(3);
g[0].name = "one";
g[1].name = "two";
g[2].name = "three";
add_edge(1, 0, "e1", g);
add_edge(2, 1, "e2", g);
add_edge(1, 2, "e3", g);
add_edge(2, 0, "e4", g);

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)));





For the sake of completeness, here is a modification of the solution by sehe with a custom property writer. Please don't forget to upvote the original answer.



Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

template <class Name>
class my_label_writer
public:
my_label_writer(Name _name) : name(_name)
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const
out << "[label="" << name[v].name << ""]";

private:
Name name;
;


int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

my_label_writer<Graph> w(g);

write_graphviz(std::cout, g,
w,
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));










share|improve this question


























  • See also faq #5

    – sehe
    Mar 27 at 21:05

















1

















I take the the following code from this post and changed the VertexList and the EdgeList to listS instead of vecS.


I found out that because of the missing index make_label_writer(get(&VertexProps::name, g)) doesn't work. Could someone tell me how I should change the code to get it work. I would prefer a solution with a custom property writer.


Thank you very much.



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g(3);
g[0].name = "one";
g[1].name = "two";
g[2].name = "three";
add_edge(1, 0, "e1", g);
add_edge(2, 1, "e2", g);
add_edge(1, 2, "e3", g);
add_edge(2, 0, "e4", g);

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)));





For the sake of completeness, here is a modification of the solution by sehe with a custom property writer. Please don't forget to upvote the original answer.



Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

template <class Name>
class my_label_writer
public:
my_label_writer(Name _name) : name(_name)
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const
out << "[label="" << name[v].name << ""]";

private:
Name name;
;


int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

my_label_writer<Graph> w(g);

write_graphviz(std::cout, g,
w,
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));










share|improve this question


























  • See also faq #5

    – sehe
    Mar 27 at 21:05













1












1








1










I take the the following code from this post and changed the VertexList and the EdgeList to listS instead of vecS.


I found out that because of the missing index make_label_writer(get(&VertexProps::name, g)) doesn't work. Could someone tell me how I should change the code to get it work. I would prefer a solution with a custom property writer.


Thank you very much.



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g(3);
g[0].name = "one";
g[1].name = "two";
g[2].name = "three";
add_edge(1, 0, "e1", g);
add_edge(2, 1, "e2", g);
add_edge(1, 2, "e3", g);
add_edge(2, 0, "e4", g);

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)));





For the sake of completeness, here is a modification of the solution by sehe with a custom property writer. Please don't forget to upvote the original answer.



Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

template <class Name>
class my_label_writer
public:
my_label_writer(Name _name) : name(_name)
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const
out << "[label="" << name[v].name << ""]";

private:
Name name;
;


int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

my_label_writer<Graph> w(g);

write_graphviz(std::cout, g,
w,
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));










share|improve this question


















I take the the following code from this post and changed the VertexList and the EdgeList to listS instead of vecS.


I found out that because of the missing index make_label_writer(get(&VertexProps::name, g)) doesn't work. Could someone tell me how I should change the code to get it work. I would prefer a solution with a custom property writer.


Thank you very much.



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g(3);
g[0].name = "one";
g[1].name = "two";
g[2].name = "three";
add_edge(1, 0, "e1", g);
add_edge(2, 1, "e2", g);
add_edge(1, 2, "e3", g);
add_edge(2, 0, "e4", g);

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)));





For the sake of completeness, here is a modification of the solution by sehe with a custom property writer. Please don't forget to upvote the original answer.



Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

template <class Name>
class my_label_writer
public:
my_label_writer(Name _name) : name(_name)
template <class VertexOrEdge>
void operator()(std::ostream& out, const VertexOrEdge& v) const
out << "[label="" << name[v].name << ""]";

private:
Name name;
;


int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

my_label_writer<Graph> w(g);

write_graphviz(std::cout, g,
w,
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));







boost boost-graph






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 9:07







Aljoscha

















asked Mar 27 at 13:46









AljoschaAljoscha

6976 silver badges9 bronze badges




6976 silver badges9 bronze badges















  • See also faq #5

    – sehe
    Mar 27 at 21:05

















  • See also faq #5

    – sehe
    Mar 27 at 21:05
















See also faq #5

– sehe
Mar 27 at 21:05





See also faq #5

– sehe
Mar 27 at 21:05












1 Answer
1






active

oldest

votes


















2














With listS the vertex descriptor type is not integral, and therefore not suitable as a vertex index.



You need to use the actual descriptors now:



Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);


Also, when writing, you'll have to supply a vertex_index property map. This incidentally requires you to pass a graph_property_writer pro forma:



std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));


DEMO



Live On Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));



Prints



digraph G 
0[label=one];
1[label=two];
2[label=three];
1->0 [label=e1];
1->2 [label=e3];
2->1 [label=e2];
2->0 [label=e4];






share|improve this answer

























  • Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

    – Aljoscha
    Mar 28 at 8:57










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378777%2fbgl-custom-property-writer-for-bundled-properties-and-lists-as-vertexlist-edgel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














With listS the vertex descriptor type is not integral, and therefore not suitable as a vertex index.



You need to use the actual descriptors now:



Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);


Also, when writing, you'll have to supply a vertex_index property map. This incidentally requires you to pass a graph_property_writer pro forma:



std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));


DEMO



Live On Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));



Prints



digraph G 
0[label=one];
1[label=two];
2[label=three];
1->0 [label=e1];
1->2 [label=e3];
2->1 [label=e2];
2->0 [label=e4];






share|improve this answer

























  • Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

    – Aljoscha
    Mar 28 at 8:57















2














With listS the vertex descriptor type is not integral, and therefore not suitable as a vertex index.



You need to use the actual descriptors now:



Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);


Also, when writing, you'll have to supply a vertex_index property map. This incidentally requires you to pass a graph_property_writer pro forma:



std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));


DEMO



Live On Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));



Prints



digraph G 
0[label=one];
1[label=two];
2[label=three];
1->0 [label=e1];
1->2 [label=e3];
2->1 [label=e2];
2->0 [label=e4];






share|improve this answer

























  • Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

    – Aljoscha
    Mar 28 at 8:57













2












2








2







With listS the vertex descriptor type is not integral, and therefore not suitable as a vertex index.



You need to use the actual descriptors now:



Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);


Also, when writing, you'll have to supply a vertex_index property map. This incidentally requires you to pass a graph_property_writer pro forma:



std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));


DEMO



Live On Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));



Prints



digraph G 
0[label=one];
1[label=two];
2[label=three];
1->0 [label=e1];
1->2 [label=e3];
2->1 [label=e2];
2->0 [label=e4];






share|improve this answer













With listS the vertex descriptor type is not integral, and therefore not suitable as a vertex index.



You need to use the actual descriptors now:



Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);


Also, when writing, you'll have to supply a vertex_index property map. This incidentally requires you to pass a graph_property_writer pro forma:



std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));


DEMO



Live On Wandbox



#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

struct VertexProps std::string name; ;
struct EdgeProps std::string name; ;
typedef boost::adjacency_list<boost::listS, boost::listS, boost::directedS, VertexProps, EdgeProps> Graph;

int main()
Graph g;
Graph::vertex_descriptor v0 = add_vertex("one", g);
Graph::vertex_descriptor v1 = add_vertex("two", g);
Graph::vertex_descriptor v2 = add_vertex("three", g);
add_edge(v1, v0, "e1", g);
add_edge(v2, v1, "e2", g);
add_edge(v1, v2, "e3", g);
add_edge(v2, v0, "e4", g);

std::map<Graph::vertex_descriptor, int> vertex_index;
for (auto vd : boost::make_iterator_range(vertices(g)))
vertex_index[vd] = vertex_index.size();

write_graphviz(std::cout, g,
make_label_writer(get(&VertexProps::name, g)),
make_label_writer(get(&EdgeProps::name, g)),
boost::default_writer, // graph_property_writer
boost::make_assoc_property_map(vertex_index));



Prints



digraph G 
0[label=one];
1[label=two];
2[label=three];
1->0 [label=e1];
1->2 [label=e3];
2->1 [label=e2];
2->0 [label=e4];







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 21:04









sehesehe

286k35 gold badges361 silver badges486 bronze badges




286k35 gold badges361 silver badges486 bronze badges















  • Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

    – Aljoscha
    Mar 28 at 8:57

















  • Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

    – Aljoscha
    Mar 28 at 8:57
















Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

– Aljoscha
Mar 28 at 8:57





Awesome ! Thank you very much. The vertex index property map was exactly the hint I needed.

– Aljoscha
Mar 28 at 8:57








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378777%2fbgl-custom-property-writer-for-bundled-properties-and-lists-as-vertexlist-edgel%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript