如何循环有向图中的所有边并获取源代码 +目的地

发布于 2025-01-02 13:27:16 字数 431 浏览 8 评论 0原文

我在有向图中添加了一堆节点和顶点,这些节点和顶点是使用设置 typedef boost::adjacency_list创建的。 graph;

Node 有一个字符串表示节点名称,Edge 有一个 int 表示其分数。我试图循环所有边并输出源名称和目标名称以及该边的分数。

您可以使用 my_graph.m_edges.begin() 获取边缘上的迭代器,可以取消引用以获取 m_sourcem_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平定天下 2025-01-09 13:27:16

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文