user189320
user189320

Reputation:

How to loop over all edges in a directed graph and get source + destination

I've added a bunch of nodes and vertices to my directed graph, created with settings typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, Node, Edge> graph;

Node has a string for the node's name, and Edge has an int for its score. I am trying to loop over all the edges and output the source and target names, as well as the score for that edge.

You can get an iterator over the edges with my_graph.m_edges.begin(), which can be dereferenced to get m_source and m_target.

How do I get the names assigned to the source and target nodes, as well as the score on that edge?

Upvotes: 1

Views: 1154

Answers (1)

Jeremiah Willcock
Jeremiah Willcock

Reputation: 31009

Given an edge_descriptor e, you can use my_graph[source(e, my_graph)].name, my_graph[target(e, my_graph)].name, and my_graph[e].score to get the information you are asking about.

Upvotes: 1

Related Questions