简体   繁体   English

如何遍历有向图的所有边并获取源+目标

[英]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; 我在有向图上添加了一堆节点和顶点,这些图和设置是通过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. Node的节点名称为字符串, Edge的分数为int。 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 . 您可以使用my_graph.m_edges.begin()在边缘获得迭代器,可以将其取消引用以获取m_sourcem_target

How do I get the names assigned to the source and target nodes, as well as the score on that edge? 如何获得分配给源节点和目标节点的名称以及该边缘的分数?

给定edge_descriptor e ,您可以使用my_graph[source(e, my_graph)].namemy_graph[target(e, my_graph)].namemy_graph[e].score来获取您要的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM