Java implementation of nearest neighbour algorithm for the travelling salesman problem, using dynamic programming [closed]

穿精又带淫゛_ 提交于 2020-08-20 11:10:09

问题


I am trying to use Java to implement the nearest neighbour algorithm for the travelling salesman problem. Before I knew precisely what I was looking for, I asked a similar question here, but received no assistance. I am starting with a matrix table[i][j] == table[j][i] of doubles, representing the distance between each node. I want to use dynamic programming to find the shortest path starting from each node back to itself by travelling to every other node once.

I have done a significant amount of research, but none of the websites for "nearest neighbour algorithm for travelling salesman problem" present a clear Java implementation that is explained to a novice such as myself. I don't just want an implementation; I want to understand the implementation.

I am using this video as a reference for this algorithm. I have watched the video many times, and I understand it. However, all of my attempts at an implementation have been a failure. Since we are iterating over a matrix, it seems to me that we require two for loops, which then implies a worst-case time complexity of O(n^2).

All of my attempts have resembled something like the following:

public int[] test(double[][] table)
{
    for (int i = 0; i < table[0].length; i++) {
        for (int j = 0; j < table[0].length; j++) {
            if () {
                
            }
        }
    }
}

I have been totally unable to make any progress on this. Regardless of how many videos I watch of the algorithm, I am seemingly unable to understand how to implement it.

来源:https://stackoverflow.com/questions/63427956/java-implementation-of-nearest-neighbour-algorithm-for-the-travelling-salesman-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!