- 积分
- 133
- 注册时间
- 2006-1-10
- 仿真币
-
- 最后登录
- 1970-1-1
|
悬赏10仿真币未解决
- HeldKarp1[pts_List]:=Module[{n=Length[pts],nearestTwo,averageDist},
- (* 寻找最近的两个邻近点 *)
- nearestTwo[n_]:=Nearest[pts,pts[[n]],3,DistanceFunction->EuclideanDistance];
- (* 计算最近的两个邻近点距离之和的平均数 *)
- averageDist[n_] :=With[{triples=nearestTwo[n]},0.5 (EuclideanDistance[triples[[1]],triples[[2]]]+EuclideanDistance[triples[[1]],triples[[3]]])];
- (* 计算累计值作为下界 *)
- Total@Table[averageDist[i], {i,1,n}]];
- SeedRandom[1234];pts=RandomReal[1,{100,2}];
- HeldKarp1[pts]//AbsoluteTiming
复制代码
HeldKarp1 模块的作用为计算任意邻近两点的平均距离,在此处为一个估算值。
改进模块的计算效率,计算时间最短为佳。 |
|