的boost :: Dijkstra算法最短路径,如何让顶点从路径迭代指数?

编程入门 行业动态 更新时间:2024-10-11 21:20:19
本文介绍了的boost :: Dijkstra算法最短路径,如何让顶点从路径迭代指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您开始阅读之前,帮助你理解我的问题,我告诉我从这个链接复制code:Dijkstra在提升图形VertexList时=列出最短路径

Before you start reading, to help you understand my issue, I am telling that I have copied the code from this link: Dijkstra Shortest Path with VertexList = ListS in boost graph

所以..我重写我的程序code使用升压,但现在,当99%的准备我坚持我的GPS(一场比赛)。我有节点的列表,这是我的方式所幸很容易转换为升压方法添加。我需要做的事情只是创建这样一个顶点变量:

So.. I am rewriting my program code to use boost, but now when 99% is ready I am stuck with my GPS (for a game). I have a list of nodes, which I added in a way which fortunately was easy to convert to the boost method. The thing I needed to do was just create a vertice variable like this:

Vertex Vx[MAX_NODES];

我从我所提供的链接复制的类型定义。

I copied the typedefs from the link I have given.

我添加顶点的方式是这样的:

The way I add vertices is this:

stringstream s; s << i; Vx[i] = add_vertex(s.str(),dgraph);

其中的i等于一个整数。 (例如int i = 9)

Where "i" equals an integer number. (eg int i = 9)

和eges也很容易添加。现在,我有一个名为xNode我自己的结构化数组。和例如:xNode [I]适用于X Y Z轴位置的节点的所有信息(xNode [I] .X xNode [I] .Y等)。

And eges are also easy to add. Now, I have my own structured array called "xNode". and eg : xNode[i] holds all the information for X Y Z positions (xNode[i].X xNode[i].Y etc) of the nodes.

现在使用从链接code片段时,我已经这样做了:

Now when using the code snippet from the link I have done this:

// Write shortest path std::cout << "Shortest path from " << startid << " to " << endid << ":" << std::endl; float totalDistance = 0; for(PathType::reverse_iterator pathIterator = path.rbegin(); pathIterator != path.rend(); ++pathIterator) { std::cout << source(*pathIterator, dgraph) << " -> " << target(*pathIterator, dgraph) << " = " << get( boost::edge_weight, dgraph, *pathIterator ) << std::endl; }

这是我在哪里卡住了,为源(*的PathIterator,DGraph组件)和目标(*的PathIterator,DGraph组件)获取地址,但我需要的顶点索引访问xNode [I],i为节点ID(或井水的顶点ID | Vx的[I])。我该怎么做?

And this is where I am stuck, as "source(*pathIterator, dgraph)" and "target(*pathIterator, dgraph) " Get addresses, but I need the vertice indexes to access xNode[i], i is the NodeID (or well the vertice ID | Vx[i]). How can I do that?

编辑:我试图做的:

I tried to do:

for(PathType::reverse_iterator pathIterator = path.rbegin(); pathIterator != path.rend(); ++pathIterator) { for(int i = 0; i < MAX_NODES; ++i) { if(source(*pathIterator, dgraph) == *((Vertex*)Vx[i])) { cout << " " << i << " " << endl; break; } } }

不过这只是崩溃。

but this just crashes..

推荐答案

随着的typedef 期从这个问题,你可以使用 GET(升压::的vertex_index,DGraph组件,v)获得诉的索引。您也可以使用缓存属性映射:

With the typedefs from that question, you can use get(boost::vertex_index, dgraph, v) to get the index of v. You can also cache the property map using:

IndexMap vi = get(boost::vertex_index, dgraph);

然后用 GET(VI,V)来获得指数v 。

更多推荐

的boost :: Dijkstra算法最短路径,如何让顶点从路径迭代指数?

本文发布于:2023-11-30 15:56:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650596.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   最短   顶点   算法   指数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!