- 积分
- 15
- UID
- 2138
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
发表于 2004-8-24 00:00:00
|
显示全部楼层
Tsp 问题是需要回到原点的,看这段代码好像没有回到出发点。
以下是引用youngfan在2004-7-5 15:06:54的发言:
修改后距离程序如下,总长为4万公里左右。昨天晚上做到3点,头有点晕了,大家重新计算,原来积分保留(我的回0)。
public int getdistance()
{ double s=0.0;
double co=0.0;
double d=0.0;
double p1x,p1y,p2x,p2y;
double w1,w2,dj;
for (int i=0;i<44;i++)
{p1x=citypos[ind*2];
p1y=citypos[ind*2+1];
p2x=citypos[ind[i+1]*2];
p2y=citypos[ind[i+1]*2+1];
w1=Math.PI*p1y/180.0;
w2=Math.PI*p2y/180.0;
dj=Math.abs(p1x-p2x)*Math.PI/180.0;
co=Math.sin(w1)*Math.sin(w2)+Math.cos(w1)*Math.cos(w2)*Math.cos(dj);
d=Math.acos(co)*6371.0;
s+=d;
}
return (int)s;
}//end getdistance
[此贴子已经被作者于2004-7-5 15:17:11编辑过] |
|