This is my code:
Collections.sort(ordered_neighborhood, (m1, m2) -> {
double improvM1 = 0, improvM2 = 0, occurrM1 = 0, occurrM2 = 0;
improvM1 = getImprovementsRate(moveStatsList, m1);
improvM2 = getImprovementsRate(moveStatsList, m2);
occurrM1 = getOccurrencesRate(moveStatsList, m1);
occurrM2 = getOccurrencesRate(moveStatsList, m2);
int costM1 = (int) (((m1.after - m1.before) - improvM1 + occurrM1) * 1000);
int costM2 = (int) (((m2.after - m2.before) - improvM2 + occurrM2) * 1000);
int r = (costM1 - costM2);
return r;
});
getImprovementsRate
get an attribute from moveStatsList
for m1
and m2
that doesn't change during comparison.
The same for getOccurrencesRate
m1.after - m1.before = 0 makes m1
and m2
equals, but I would to weight m1
and m2
with two weights arrays.
I seen "Comparison method violates its general contract!" question but: the problem is that the error doesn't compare every time I run my programs. It seems to be non deterministic.
Maybe casting from double
to int
?