简体   繁体   English

在两个顶点之间具有平行边的Dijkstra

[英]Dijkstra with parallel edges between two Vertices

I've got a routing problem where I need to retrieve the best n solutions between two points. 我遇到了一个路由问题,需要在两点之间检索最佳的n个解。 I am using Dijkstra for the optimal solution and Yen Top K algorithm on top of that to get the n best solutions. 我正在使用Dijkstra作为最佳解决方案,并在此之上使用Yen Top K算法来获得n个最佳解决方案。

However there is a twist to it, you can have multiple parallel edges between to vertices. 但是,有一个扭曲,顶点之间可以有多个平行边。 Lets imagine a bus network: 让我们想象一下一个总线网络:

Line A: a -> b -> c -> d -> e
Line B: b -> c -> d -> e -> f
Line C: a -> b -> c -> g -> h

When you build your graph, how do you handle these parallel connections? 构建图形时,如何处理这些并行连接? I am thinking of building the graph like: 我正在考虑建立这样的图形:

Line A: a->b,a->c,a->d a->e,b->c,b->d,b->d,b->e,c->d,c->e,d->e
Line B: b->c,b->d,b->e,e->f,c->d,c->e,c->f,d->e,d->f,e->f
Line C: a->b,a->c,a->g,a->h,b->c,b->g,b->h,c->g,c->h,g->h

With that I have direct edges for when I don't have to change bus. 这样,当我不必更换公交车时,我具有直接优势。 For each Vertex I go through I add a connection penalty weight. 对于我经历的每个顶点,我都添加了连接权重。

So if I want to go from a->e I would probably get Line A as using Line C a->b, Line B b->e might be longer because of the connection time even if the time Line C a->b and Line B b->e might be faster than the route on Line A. 因此,如果我想从a-> e出发,则可能会得到使用Line C a-> b的Line A,由于连接时间,即使Line C a-> b的时间,Line B b-> e可能会更长而B b-> e行可能比A行上的路由更快。

However I still need to handle parallel connections. 但是我仍然需要处理并行连接。 So I guess I need to sort the parallel edges by weight. 所以我想我需要按重量对平行边缘进行排序。

Currently this is based on static timing information but at some point it should take actual schedule information into account. 当前,这是基于静态时序信息,但在某些时候它应该考虑实际的调度信息。 And depending on that your weights between two vertices could change. 并且取决于您在两个顶点之间的权重可能会改变。 Eg by the time you would get to point b the fastest connection via Line C wouldn't be the fastest anymore as you would have just missed Line C etc. 例如,当您到达b点时,通过C线的最快连接将不再是最快的,因为您可能会错过C线等。

Are there any resources anywhere that explain how you would handle these more complex situations? 是否有任何资源可以解释您将如何处理这些更复杂的情况?

One approach could be to reduce the problem back to a simple graph (no parallel edges), by "splitting nodes" 一种方法是通过“分割节点”将问题减少到简单图形(无平行边)

That means, if you have a node u , with edges (v,u)_1, (v,u)_2, ..., (v,u)_k , you can split u to: u, u_1, u_2,...,u_k , with edges: (u_1,u), (u_2,u), ..., (u_k,u), (v,u_1), (v,u_2), ...., (v,u_k) , and weights: w(u_i,u) = 0 for all i and w(v,u_i) = w((v,u)_i) for all i 这意味着,如果您有一个节点u ,且其边缘为(v,u)_1, (v,u)_2, ..., (v,u)_k ,则可以将u拆分为: u, u_1, u_2,...,u_k ,其边线为: (u_1,u), (u_2,u), ..., (u_k,u), (v,u_1), (v,u_2), ...., (v,u_k)和权重: w(u_i,u) = 0 for all i w(v,u_i) = w((v,u)_i) for all i

Now you can run any algorithm designed for simple graph with ease, where the number of vertices is increased in a linear factor of the number of parallel edges. 现在,您可以轻松运行为简单图形设计的任何算法,其中,顶点数以平行边数的线性因子增加。

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

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