所以我试图通过长和纬来计算我拥有的每条路线的距离。我将它添加到 arrayList,然后移动到下一条路线。它似乎正在计算前 3 个的路线,但它似乎只是继续添加第 3 个元素。
谁能看到我做错了什么?这是一个相当大的功能
ArrayList<Integer> xCoords = new ArrayList<Integer>();
ArrayList<Integer> yCoords = new ArrayList<Integer>();
int fitness2 = 0;
for (List<Integer> eachChromeNew : populationShuffle){
for (int n =0; n < eachChromeNew.size();n++){
xCoords.add(geoPoints.get(n).getLongitudeE6());
yCoords.add(geoPoints.get(n).getLatitudeE6());
}
for (int c = 0; c < xCoords.size();c++){
if(c != xCoords.size()-1)
{
int x1 = xCoords.get(c);
int y1 = xCoords.get(c + 1);
int x2 = yCoords.get(c);
int y2 = yCoords.get(c + 1);
fitness2 += Math.sqrt((Math.pow(x2 - x1,2) + Math.pow(y2 - y1, 2)));
}
fitnessArrayTest.add(fitness2);
}
System.out.println("Fitness Test is: = " +fitness2);
}
这是输出
10-08 21:43:10.715: I/System.out(26785): Fitness Test is: = 669448211
10-08 21:43:10.715: I/System.out(26785): Fitness Test is: = 2092025460
10-08 21:43:10.720: I/System.out(26785): Fitness Test is: = 2147483647
10-08 21:43:10.720: I/System.out(26785): Fitness Test is: = 2147483647
10-08 21:43:10.720: I/System.out(26785): Fitness Test is: = 2147483647
10-08 21:43:10.720: I/System.out(26785): Fitness Test is: = 2147483647
编辑
因此,在将其更改为建议的两倍后,它似乎略有工作,但在几次之后似乎稳步增加。这就是我的意思:
1
0-08 21:56:07.275: I/System.out(28729): Fitness Test is: = 6.694724656380861E8
10-08 21:56:07.275: I/System.out(28729): Fitness Test is: = 2.0921019557100217E9
10-08 21:56:07.275: I/System.out(28729): Fitness Test is: = 4.267888470215804E9
10-08 21:56:07.275: I/System.out(28729): Fitness Test is: = 7.196832009155435E9
10-08 21:56:07.280: I/System.out(28729): Fitness Test is: = 1.0878932572528923E10
10-08 21:56:07.280: I/System.out(28729): Fitness Test is: = 1.5314190160336267E10
10-08 21:56:07.280: I/System.out(28729): Fitness Test is: = 2.050260477257744E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 2.644417640925244E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 3.313890507036129E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 4.0586790755903984E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 4.878783346588052E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 5.774203320029091E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 6.744938995913514E10
10-08 21:56:07.285: I/System.out(28729): Fitness Test is: = 7.790990374241312E10
10-08 21:56:07.290: I/System.out(28729): Fitness Test is: = 8.912357455012492E10
出现在数字末尾的这些 E8、E9 和 E10 是什么?
编辑
在马丁建议将其除以 1000000 之后,我得到了更好的答案范围,但是我知道遇到了另一个问题,希望是最后一个问题。这是健身每次都会增加,我期待的是随机顺序。这是新的输出
10-08 22:18:49.990: I/System.out(2576): Fitness Test is: = 669.4690141960474
10-08 22:18:49.995: I/System.out(2576): Fitness Test is: = 2092.0939129186613
10-08 22:18:49.995: I/System.out(2576): Fitness Test is: = 4267.874696167842
10-08 22:18:49.995: I/System.out(2576): Fitness Test is: = 7196.8113639435915
10-08 22:18:49.995: I/System.out(2576): Fitness Test is: = 10878.903916245905
10-08 22:18:50.000: I/System.out(2576): Fitness Test is: = 15314.152353074784
10-08 22:18:50.005: I/System.out(2576): Fitness Test is: = 20502.556674430216
10-08 22:18:50.005: I/System.out(2576): Fitness Test is: = 26444.116880312213
10-08 22:18:50.005: I/System.out(2576): Fitness Test is: = 33138.83297072078
10-08 22:18:50.005: I/System.out(2576): Fitness Test is: = 40586.70494565593
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 48787.73280511766
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 57741.916549105954
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 67449.25617762083
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 77909.75169066226
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 89123.40308823026
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 101090.21037032483
10-08 22:18:50.010: I/System.out(2576): Fitness Test is: = 113810.17353694596
10-08 22:18:50.015: I/System.out(2576): Fitness Test is: = 127283.29258809367
10-08 22:18:50.015: I/System.out(2576): Fitness Test is: = 141509.56752376774
现在有人能看出什么不对吗?