java.lang.IllegalArgumentException: Comparison method violates its general contract
DKorosec opened this issue · 1 comments
DKorosec commented
Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeHi(Unknown Source)
at java.util.TimSort.mergeAt(Unknown Source)
at java.util.TimSort.mergeForceCollapse(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.ArrayList.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at org.um.feri.ears.benchmark.RatingBenchmark.setWinLoseFromResultList(RatingBenchmark.java:161)
at org.um.feri.ears.benchmark.RatingBenchmark.run(RatingBenchmark.java:219)
at MainBenchMarkTest.TEST_ALGO(MainBenchMarkTest.java:53)
at MainBenchMarkTest.main(MainBenchMarkTest.java:88)
When running the following configuration I get this exception printed above. (It takes some time, but it will be 100% reproducible)
TEST_ALGO(5, 10, 70, 75, 1508185232848L, 2);
public static void TEST_ALGO(int from_f, int to_f, int from_c, int to_c, long seed, int repeat)
{
System.out.println("seed: "+seed);
Util.rnd.setSeed(seed);
ArrayList<Algorithm> players = new ArrayList<Algorithm>();
players.add(new DEE007(10,0.7,0.89,"CrepA"));
players.add(new DEE007(10,0.71,0.79,"CrepB"));
if(true)
{
for(int pop = 10; pop <= 100; pop += 10)
{
for(int c = from_c; c <= to_c; c+=1)
{
for(int f = from_f; f <= to_f; f+=1)
{
double cParam = c/100.0d;
double fParam = f/100.0d;
if(cParam > 1)
cParam = 1;
if(fParam > 1)
fParam = 1;
String aname = "{{"+Integer.toString(pop)+","+Double.toString(cParam)+","+Double.toString(fParam)+"}}";
Algorithm algorithm = new DEE007(pop, cParam, fParam, "new_Dominik"+aname);
players.add(algorithm);
}
}
}
}
ResultArena ra = new ResultArena(100);
RatingRPUOed2 suopm = new RatingRPUOed2(); //Create banchmark
suopm.setDisplayRatingIntervalChart(false);
for (Algorithm al:players) {
ra.addPlayer(al.getID(), 1500, 350, 0.06,0,0,0); //init rating 1500
suopm.registerAlgorithm(al);
}
BankOfResults ba = new BankOfResults();
suopm.run(ra, ba, repeat);
ArrayList<Player> list = ra.recalcRatings();
//for(int i=0;i < 10 && i < list.size();i++) {
System.out.println(list.get(0)); //print rangs
//}
}
import java.util.ArrayList;
import org.um.feri.ears.algorithms.Algorithm;
import org.um.feri.ears.algorithms.AlgorithmInfo;
import org.um.feri.ears.algorithms.Author;
import org.um.feri.ears.problems.DoubleSolution;
import org.um.feri.ears.problems.StopCriteriaException;
import org.um.feri.ears.problems.Task;
import org.um.feri.ears.util.Util;
public class DEE007 extends Algorithm {
int pop_size;
double CR, F;
ArrayList<DoubleSolution> pop;
DoubleSolution best;
//Initialize all agents {\displaystyle \mathbf {x} } \mathbf {x} with random positions in the search-space.
public DEE007(int ps, double CR, double F, String s) {
pop_size = ps;
this.CR = CR;
this.F = F;
ai = new AlgorithmInfo("","",s,s); //EARS add algorithm name
au = new Author("E007", "N/A"); //EARS author info
}
public void init(Task taskProblem) throws StopCriteriaException {
pop = new ArrayList<>();
DoubleSolution tmp;
for (int i=0; i<pop_size;i++) {
if (taskProblem.isStopCriteria()) break;
tmp = taskProblem.getRandomSolution();
if (i==0) best = tmp;
else if (taskProblem.isFirstBetter(tmp, best)) best = tmp;
pop.add(tmp);
}
}
@Override
public DoubleSolution execute(Task taskProblem) throws StopCriteriaException {
init(taskProblem);
int a, b, c, R;
DoubleSolution yEval;
while (!taskProblem.isStopCriteria()) {
for (int i=0; i<pop_size;i++) {
if (taskProblem.isStopCriteria()) break;
do
a = Util.rnd.nextInt(pop_size);
while (a==i);
do
b = Util.rnd.nextInt(pop_size);
while ((b==i)||(b==a));
do
c = Util.rnd.nextInt(pop_size);
while ((c==i)||(c==a)||(c==b));
R = Util.rnd.nextInt(taskProblem.getNumberOfDimensions());
double y[] = new double[taskProblem.getNumberOfDimensions()];
for (int j=0; j<taskProblem.getNumberOfDimensions(); j++) {
if ((Util.nextDouble()<CR) || (j==R)) {
y[j] = taskProblem.setFeasible(pop.get(a).getDoubleVariables()[j]+F*(pop.get(b).getDoubleVariables()[j]-pop.get(c).getDoubleVariables()[j]),j);
} else y[j] = pop.get(i).getDoubleVariables()[j];
}
yEval = taskProblem.eval(y);
if (taskProblem.isFirstBetter(yEval, pop.get(i))){
pop.set(i, yEval);
if (taskProblem.isFirstBetter(yEval, best)) best = yEval;
}
}
}
return best;
}
@Override
public void resetDefaultsBeforNewRun() {
// TODO Auto-generated method stub
}
}