最小路径 - 所有边至少一次

发布于 2024-08-23 13:44:22 字数 195 浏览 7 评论 0 原文

我有很多循环的有向图,可能是强连接的,我需要从中得到一个最小的循环。我的意思是我需要得到周期,这是图中最短的周期,并且每条边至少被覆盖一次。

我一直在寻找一些算法或一些理论背景,但我唯一找到的是中国邮递员算法。但这个解决方案不适用于有向图。

有人可以帮助我吗?谢谢

编辑>>该图的所有边都具有相同的成本 - 例如 1

I have directed graph with lot of cycles, probably strongly connected, and I need to get a minimal cycle from it. I mean I need to get cycle, which is the shortest cycle in graph, and every edge is covered at least once.

I have been searching for some algorithm or some theoretical background, but only thing I have found is Chinese postman algorithm. But this solution is not for directed graph.

Can anybody help me? Thanks

Edit>> All edges of that graph have the same cost - for instance 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

情释 2024-08-30 13:44:22

看看这篇论文 - 定向中国邮递员问题。但这是正确的问题分类(假设没有更多限制)。

如果您只是阅读理论,请仔细阅读 此页面,来自算法设计手册。

关键引述(指导版本的后半部分):

可以通过向图G添加适当的边以使其成为欧拉图来构造最优邮差旅行。具体来说,我们找到 G 中每对奇数度顶点之间的最短路径。在 G 中的两个奇数度顶点之间添加一条路径会将它们都变成偶数度,从而使我们更接近欧拉图。找到添加到 G 的最佳最短路径集可以简化为在奇数度顶点上识别图中的最小权重完美匹配,其中边 (i,j) 的权重是从 i 到 G 的最短路径的长度j。对于有向图,可以使用二分匹配来解决这个问题,其中根据顶点是否具有更多的传入或传出边来进行分区。一旦图形是欧拉图,就可以使用上述过程在线性时间内提取实际循环。

Take a look at this paper - Directed Chinese Postman Problem. That is the correct problem classification though (assuming there are no more restrictions).

If you're just reading into theory, take a good read at this page, which is from the Algorithms Design Manual.

Key quote (the second half for the directed version):

The optimal postman tour can be constructed by adding the appropriate edges to the graph G so as to make it Eulerian. Specifically, we find the shortest path between each pair of odd-degree vertices in G. Adding a path between two odd-degree vertices in G turns both of them to even-degree, thus moving us closer to an Eulerian graph. Finding the best set of shortest paths to add to G reduces to identifying a minimum-weight perfect matching in a graph on the odd-degree vertices, where the weight of edge (i,j) is the length of the shortest path from i to j. For directed graphs, this can be solved using bipartite matching, where the vertices are partitioned depending on whether they have more ingoing or outgoing edges. Once the graph is Eulerian, the actual cycle can be extracted in linear time using the procedure described above.

最后的乘客 2024-08-30 13:44:22

我怀疑它是否是最佳的,但是假设图形保证有一个循环,您可以进行基于队列的搜索。每个队列条目将包含代表路径的节点列表。当您从队列中取出一个元素时,将所有可能的后续步骤添加到队列中,确保您不会重新访问节点。如果最后一个节点与第一个节点相同,则您已找到最小循环。

I doubt that it's optimal, but you could do a queue based search assuming the graph is guaranteed to have a cycle. Each queue entry would contain a list of nodes representing paths. When you take an element off the queue, add all possible next steps to the queue, ensuring you are not re-visiting nodes. If the last node is the same as the first node, you've found the minimum cycle.

无尽的现实 2024-08-30 13:44:22

您正在寻找的称为“欧拉路径”。您可以通过 Google 搜索找到足够的信息,基本信息位于此处
关于算法,有一种算法叫做Fleury算法,google一下或者看看这里

what you are looking for is called "Eulerian path". You can google it to find enough info, basics are here
And about algorithm, there is an algorithm called Fleury's algorithm, google for it or take a look here

ゃ人海孤独症 2024-08-30 13:44:22

我认为可能值得简单地写出哪些顶点是奇数,然后找到它们的哪个组合将导致最少的额外时间(如果权重是时间或距离),那么总长度将是每个边权重加上额外的。例如,如果奇数阶顶点是 A、B、C、D,请尝试 AB 和 CD,然后是 AC 和 BD,依此类推。 (我不确定这是否是一个专门命名的方法,它对我有用)。
编辑:刚刚意识到这主要只适用于无向图。

I think it might be worth while just simply writing which vertices are odd and then find which combo of them will lead to the least amount of extra time (if the weights are for times or distances) then the total length will be every edge weight plus the extra. For example, if the odd order vertices are A,B,C,D try AB&CD then AC&BD and so on. (I'm not sure if this is a specifically named method, it just worked for me).
edit: just realised this mostly only works for undirected graphs.

淤浪 2024-08-30 13:44:22

网络完全由有向边组成的特殊情况可以在多项式时间内解决。我认为原始论文是 Matching, Euler Tours and the Chinese postman (1973) - a有向图问题算法的清晰描述从第 115 页开始(pdf 第 28 页):

当连通图的所有边都是有向且该图
是对称的,有一个特别简单且有吸引力的算法
指定欧拉游览...

在有向、对称、连通图 G 中查找欧拉游览的算法是首先找到 G 的跨越树状图。然后,在
任何节点 n,除了树状结构的根 r 之外,指定任意顺序
只要树状结构的边缘指向远离 n 的边缘
是排序中的最后一个。对于根 r,指定任意顺序
远离 r 的边。

van Aardenne-Ehrenfest 和 de Bruin 使用该算法
枚举某个有向图中的所有欧拉游览[1]。

The special case in which the network consists entirely of directed edges can be solved in polynomial time. I think the original paper is Matching, Euler tours and the Chinese postman (1973) - a clear description of the algorithm for the directed graph problem begins on page 115 (page 28 of the pdf):

When all of the edges of a connected graph are directed and the graph
is symmetric, there is a particularly simple and attractive algorithm for
specifying an Euler tour...

The algorithm to find an Euler tour in a directed, symmetric, connected graph G is to first find a spanning arborescence of G. Then, at
any node n, except the root r of the arborescence, specify any order for
the edges directed away from n so long as the edge of the arborescence
is last in the ordering. For the root r, specify any order at all for the
edges directed away from r.

This algorithm was used by van Aardenne-Ehrenfest and de Bruin to
enumerate all Euler tours in a certain directed graph [ 1 ].

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