gpt4 book ai didi

algorithm - 来自多个集合的最短路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:08:58 25 4
gpt4 key购买 nike

我必须找到各种集合中节点之间的最短路径,我只能在每个集合中使用一次节点。每个节点都通过距离连接到每个其他节点。集合中的节点之间没有连接的情况除外。该路径必须包含每个集合中的一个节点。

例如。

    Set A - [a1, a2, a3]
Set B - [b1, b2]
Set C - [c1]
Set D - [d1, d2, d3]
Set Z - [z1, z2, z3]

节点是a1,a2,a3,b1,b2...

例如。节点a1

有联系

b1,b2,c1,d1,d2,d3,z1,z2,z3

或节点c1

有联系

a1,a2,a3,b1,b2,d1,d2,d3,z1,z2,z3

可能的路径是:

a1 -> b1 -> c1 -> d1 -> z1, or c1 -> z2 -> a3 -> b1 -> d2

每个节点之间的距离(集合中的节点除外,没有连接)可以是从0到1。

最佳答案

这被称为广义旅行商问题。

来自 C. Noon & J.Bean, An Efficient Transformation of the Generalized Traveling Salesman Problem :

The Generalized Traveling Salesman Problem (GTSP) is a useful model for problems involving decisions of selection and sequence. The asymmetric version of the problem is defined on a directed graph with nodes N, connecting arcs A and a vector of corresponding arc costs c. The nodes are pregrouped into m mutually exclusive and exhaustive nodesets. Connecting arcs are defined only between nodes belonging to different sets, that is, there are no intraset arcs. Each defined arc has a corresponding non-negative cost. The GTSP can be stated as the problem of finding a minimum cost m-arc cycle which includes exactly one node from each nodeset.

本文解释了如何将您的问题转化为标准旅行商问题的案例。

关于algorithm - 来自多个集合的最短路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16150424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com