Note that there are some explanatory texts on larger screens.

plurals
  1. POJava error: "Comparison method violates its general contract!"
    primarykey
    data
    text
    <p>I have this code:</p> <pre><code>package org.optimization.geneticAlgorithm; import org.optimization.geneticAlgorithm.selection.Pair; public abstract class Chromosome implements Comparable&lt;Chromosome&gt; { public abstract double fitness(); public abstract Pair&lt;Chromosome&gt; crossover(Chromosome parent); public abstract void mutation(); public int compareTo(Chromosome o) { int rv = 0; if (this.fitness() &gt; o.fitness()) { rv = -1; } else if (this.fitness() &lt; o.fitness()) { rv = 1; } return rv; } } </code></pre> <p>And every time I run this code I get this error:</p> <pre><code>Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract! at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:835) at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:453) at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:376) at java.util.ComparableTimSort.sort(ComparableTimSort.java:182) at java.util.ComparableTimSort.sort(ComparableTimSort.java:146) at java.util.Arrays.sort(Arrays.java:472) at java.util.Collections.sort(Collections.java:155) at org.optimization.geneticAlgorithm.GeneticAlgorithm.nextGeneration(GeneticAlgorithm.java:74) at org.optimization.geneticAlgorithm.GeneticAlgorithm.execute(GeneticAlgorithm.java:40) at test.newData.InferenceModel.main(InferenceModel.java:134) </code></pre> <p>I use OpenJDK7u3 and I return 0 when the objects are equal. Can someone explain this error to me?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload