[JAVA] 最小生成树解决TSP

Neptune.WQ Neptune.WQ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题背景:
TSP Problem:

Input: a weighted complete undirected graph G with vertex set
G.V={ v_0,v_(1,)…,v_(n-1)}. The weight of the edge from v_i and v_j is denoted as G.w(i,j). It is assumed that the weights of the edges are non-negative. In other words, the weights satisfy the following constraints:

{ (G.w(i,j)=G.w(j,i); G.w(i,j)>0 if i≠ j; G.w(j,i)=0 if i=j) }

Output: a TSP tour on G which is a Hamiltonian cycle that cycle that starts from v_0, visit each node in G only once and return back to starting vertex〖 v〗_0.

Objective: Minimize the total weight of the edges in the TSP tour.

Heuristics

Minimum Spanning Tree (MST) Based Heuristic

Construct a MST, T, for the vertices in G from starting point v_0;

Traverse around T to get the initial TSP tour for G;

Exploit the triangular inequality and remove unnecessary visits in the TSP tour.

Compute the length of the tour.

Nearest Neighbour (NN) Heuristic

current vertex ← v0;

Loop for n-1 steps

At each step, choose to visit next the vertex that is closest to the current vertex;

Update the current vertex;

Including the closing edge (back to v0) in the tour;

Compute the length of the tour.

求以上两种算法的JAVA代码思路
补充: 1. 自动生成一个随机的N顶点图片的代码已经附上, 问题是如何实现以上两种算法呢. 拜托
...全文
评论 4
收藏 已收藏
分享
返回顶部
Neptune.WQ
Java 51,407 成员 86,130 内容