简体   繁体   English

使用 networkx 解决修改后的旅行商问题(TSP)

[英]Solving a modified Travelling Salesman Problem(TSP) using networkx

I am trying to solve a modified version of the TSP.我正在尝试解决 TSP 的修改版本。 In my version, multiple visits to a city are allowed, as long as the path is the shortest, and also, only subset of the cities are compulsory to visit, as in, you can go through other cities to visit all the subset cities if path is shorter, but if not, the other cities can be ignored.在我的版本中,允许多次访问一个城市,只要路径最短,而且,只有城市的子集是必须访问的,例如,如果您可以通过其他城市访问所有子集城市路径较短,但如果不是,其他城市可以忽略。 NetworkX has approx. NetworkX 有大约。 solution for the traditional TSP using the dwave_networkx.algorithms.tsp.traveling_salesperson , but I have trouble solving this one.使用dwave_networkx.algorithms.tsp.traveling_salesperson的传统 TSP 解决方案,但我无法解决这个问题。 A naive approach can be to find all possible combinations of the subset cities and check which has the shortest total path length, but that solution will have an^2 complexity for trying each combination, plus the complexity for finding shortest path for each two cities.一种天真的方法是找到子集城市的所有可能组合并检查哪个具有最短的总路径长度,但该解决方案将具有 ^2 尝试每个组合的复杂性,加上为每两个城市寻找最短路径的复杂性。 So, what should I use to solve this problem using NetworkX.那么,我应该使用 NetworkX 来解决这个问题。

You can select a path randomly and optimize the way on it.您可以随机选择一条路径并优化其路径。 Basically, randomly assign a way between two nodes.基本上,在两个节点之间随机分配一条路。 Than on nodes, try to find optimal way for n+2 nodes.比在节点上,尝试为 n+2 个节点找到最佳方式。 A --> B --> C if there is a path between shortest then try A--> D --> C---E if there is path between D and E shortest than D --> K --> E then again iterate A--> D --> F --> E simply that sound to me a good idea. A --> B --> C 如果最短路径之间有路径则尝试 A--> D --> C---E 如果 D 和 E 之间的路径最短于 D --> K --> E然后再次迭代 A--> D --> F --> E 对我来说这听起来是个好主意。 I don't have proof now but it can give you the possible shortest path.我现在没有证据,但它可以为您提供可能的最短路径。 I hope that will be helpful.我希望这会有所帮助。 Good luck.祝你好运。

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

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