Correct pairingSort function

This commit is contained in:
Quentin Rendu
2023-10-16 18:46:07 +02:00
parent 50ff3fa0fc
commit 931e3266ff
2 changed files with 11 additions and 12 deletions

View File

@@ -79,7 +79,7 @@ sealed class Solver(
val criterionP = p.eval(criterion)
val criterionQ = q.eval(criterion)
if (criterionP != criterionQ) {
return (criterionP * 100 - criterionQ * 100).toInt()
return (criterionQ * 100 - criterionP * 100).toInt()
}
}
return 0
@@ -89,7 +89,7 @@ sealed class Solver(
val criterionP = p.eval(criterion)
val criterionQ = q.eval(criterion)
if (criterionP != criterionQ) {
return (criterionP * 100 - criterionQ * 100).toInt()
return (criterionQ * 1e6 - criterionP * 1e6).toInt()
}
}
if (p.rating == q.rating) {
@@ -174,14 +174,11 @@ sealed class Solver(
val matching = KolmogorovWeightedPerfectMatching(graph, ObjectiveSense.MAXIMIZE)
val solution = matching.matching
fun gamesSort(p1:Pairable, p2:Pairable) = 0.5*(p1.place + p2.place)
var sorted = solution.map{
val sorted = solution.map{
listOf(graph.getEdgeSource(it), graph.getEdgeTarget(it))
}.sortedBy { gamesSort(it[0],it[1])}
}.sortedWith(compareBy({ 0.5*(it[0].place + it[1].place) }, { min(it[0].place, it[1].place) }))
var result = sorted.flatMap { games(white = it[0], black = it[1]) }
val result = sorted.flatMap { games(white = it[0], black = it[1]) }
return result