Comparator not sorting right
<p>So, I'm trying to implement a genetic algorithm for a project and for some reason after running for several generations it shows just one array over and over again. After commenting out the sorting function it stopped doing that. Thus I figured that something is wrong with my sorting function:</p>

<pre><code>private double[][] sortPopulation(final double[][] popArr) {
    Arrays.sort(popArr, new Comparator&lt;double[]&gt;() {
        @Override
        public int compare(double[] o1, double[] o2) {
            return Double.compare(o1[popArr[0].length - 1], o2[popArr[0].length - 1]);
        }
    });
    return popArr;
}
</code></pre>

<p>The function gets a two dimensional array which is my population running from <code>[0-99][0-32]</code> The last value in the second dimension represents the value given by a fitness function which is the value I want to sort the population by.</p>

<p>What I get in the first generation is:</p>

<pre><code>1. [22 20 1 8 29 32 16 7 14 12 30 28 15 6 23 25 2 31 18 11 3 27 24 9 19 5 26 0 4 10 17 13 21]    Fitness value: 324.7188322103662
2. [24 27 25 12 30 15 18 20 28 23 10 0 29 26 13 17 6 9 22 4 1 7 8 5 21 32 16 31 14 2 3 19 11]    Fitness value: 337.496502384419
3. [11 17 29 26 28 30 9 10 32 15 21 27 7 4 12 8 13 20 5 3 14 2 31 0 24 19 16 22 1 25 23 18 6]    Fitness value: 340.2679234841635
4. [14 26 15 1 21 8 23 27 18 32 4 12 16 7 13 3 31 20 22 24 5 30 29 28 0 25 11 9 19 10 6 2 17]    Fitness value: 355.58802355081076
</code></pre>

<p>And the second:</p>

<pre><code>1. [22 20 1 8 29 32 16 7 14 12 30 28 15 6 23 25 2 31 18 11 3 27 24 9 19 5 26 0 4 10 17 13 21]    Fitness value: 320.9572496353372
2. [22 20 1 8 29 32 16 7 14 12 30 28 15 6 23 25 2 31 18 11 3 27 24 9 19 5 26 0 4 10 17 13 21]    Fitness value: 320.9572496353372
3. [11 17 29 26 28 30 9 10 32 15 21 27 7 4 12 8 13 20 5 3 14 2 31 0 24 19 16 22 1 25 23 18 6]    Fitness value: 354.2361876347537
4. [11 17 29 26 28 30 9 10 32 15 21 27 7 4 12 8 13 20 5 3 14 2 31 0 24 19 16 22 1 25 23 18 6]    Fitness value: 354.2361876347537
</code></pre>

<p>And the third:</p>

<pre><code>1. [24 27 25 12 30 15 18 20 28 23 10 0 29 26 13 17 6 9 22 4 1 7 8 5 21 32 16 31 14 2 3 19 11]    Fitness value: 337.496502384419
2. [24 27 25 12 30 15 18 20 28 23 10 0 29 26 13 17 6 9 22 4 1 7 8 5 21 32 16 31 14 2 3 19 11]    Fitness value: 337.496502384419
3. [24 27 25 12 30 15 18 20 28 23 10 0 29 26 13 17 6 9 22 4 1 7 8 5 21 32 16 31 14 2 3 19 11]    Fitness value: 337.496502384419
4. [24 27 25 12 30 15 18 20 28 23 10 0 29 26 13 17 6 9 22 4 1 7 8 5 21 32 16 31 14 2 3 19 11]    Fitness value: 337.496502384419
5. [15 16 18 14 12 25 6 26 27 9 21 28 7 17 23 32 19 31 2 4 3 24 11 22 0 5 30 29 20 10 13 8 1]    Fitness value: 340.49473823049664
6. [15 16 18 14 12 25 6 26 27 9 21 28 7 17 23 32 19 31 2 4 3 24 11 22 0 5 30 29 20 10 13 8 1]    Fitness value: 340.49473823049664
7. [15 16 18 14 12 25 6 26 27 9 21 28 7 17 23 32 19 31 2 4 3 24 11 22 0 5 30 29 20 10 13 8 1]    Fitness value: 340.49473823049664
8. [15 16 18 14 12 25 6 26 27 9 21 28 7 17 23 32 19 31 2 4 3 24 11 22 0 5 30 29 20 10 13 8 1]    Fitness value: 340.49473823049664
</code></pre>

<p>You get the picture I think. Anyone can help me with that?</p>