的boost :: Dijkstra算法最短路径,如何让顶点从路径迭代指数? [英] Boost:: Dijkstra Shortest Path, how to get vertice index from path iterator?

查看:216
本文介绍了的boost :: Dijkstra算法最短路径,如何让顶点从路径迭代指数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您开始阅读之前,帮助你理解我的问题,我告诉我从这个链接复制code:<一href=\"http://stackoverflow.com/questions/7156880/dijkstra-shortest-path-with-vertexlist-lists-in-boost-graph\">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算法最短路径,如何让顶点从路径迭代指数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆