如何循环有向图中的所有边并获取源代码 +目的地
我在有向图中添加了一堆节点和顶点,这些节点和顶点是使用设置 typedef boost::adjacency_list
Node
有一个字符串表示节点名称,Edge
有一个 int 表示其分数。我试图循环所有边并输出源名称和目标名称以及该边的分数。
您可以使用 my_graph.m_edges.begin()
获取边缘上的迭代器,可以取消引用以获取 m_source
和 m_target
。
如何获取分配给源节点和目标节点的名称以及该边上的分数?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定
edge_descriptor
e
,您可以使用my_graph[source(e, my_graph)].name
,my_graph[target(e, my_graph)].name
和my_graph[e].score
来获取您所询问的信息。Given an
edge_descriptor
e
, you can usemy_graph[source(e, my_graph)].name
,my_graph[target(e, my_graph)].name
, andmy_graph[e].score
to get the information you are asking about.