这是我的代码:
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
从moveStatsList
获取m1
和m2
的属性,该属性在比较期间不会更改。
getOccurrencesRate
m1.after - m1.before = 0使m1
和m2
等于,但我会用两个权重数组加权m1
和m2
。
我看到了"Comparison method violates its general contract!"问题,但问题是每次运行程序时错误都不会进行比较。这似乎是不确定的。
也许从double
转换为int
?