From a4c55c82e2c6c0b62f0c56042c188cd14f458a79 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Fri, 26 Jan 2024 08:13:15 +0100 Subject: [PATCH] Fix MMS computation for current round and while pairing --- .../src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt | 4 ++-- .../src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt | 2 +- .../kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt | 4 ++-- .../org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt index 909a4ed..786f960 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairing.kt @@ -7,6 +7,7 @@ import org.jeudego.pairgoth.model.PairingType.* import org.jeudego.pairgoth.pairing.solver.MacMahonSolver import org.jeudego.pairgoth.pairing.solver.SwissSolver import java.util.* +import kotlin.math.min // base pairing parameters data class BaseCritParams( @@ -135,8 +136,7 @@ sealed class Pairing( } internal fun Tournament<*>.historyBefore(round: Int) = - if (lastRound() == 1) emptyList() - else (1 until round).map { games(it).values.toList() } + (1 until min(round, lastRound() + 1)).map { games(it).values.toList() } /*private fun Tournament<*>.historyBefore(round: Int) : List> { println("Welcome to tournament.historyBefore !") diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt index 4afe9a2..2bf1693 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Tournament.kt @@ -72,7 +72,7 @@ sealed class Tournament ( fun games(round: Int) = games.getOrNull(round - 1) ?: if (round > games.size + 1) throw Error("invalid round") else mutableMapOf().also { games.add(it) } - fun lastRound() = games.size + fun lastRound() = max(1, games.size) fun recomputeHdAndDUDD(round: Int, gameID: ID) { // Instantiate solver with game history diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt index dde45a3..87bc582 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/BasePairingHelper.kt @@ -91,8 +91,8 @@ abstract class BasePairingHelper( val Pairable.sosos: Double get() = historyHelper.sosos[id] ?: 0.0 val Pairable.sodos: Double get() = historyHelper.sodos[id] ?: 0.0 val Pairable.cums: Double get() = historyHelper.cumScore[id] ?: 0.0 - fun Pairable.missedRounds(upToRound: Int): Int = (1..upToRound).map { round -> - if (historyHelper.playersPerRound.getOrNull(round - 1)?.contains(id) == true) 0 else 1 + fun Pairable.missedRounds(upToRound: Int, pairing: Set): Int = (1..upToRound).map { round -> + if (historyHelper.playersPerRound.getOrNull(round - 1)?.contains(id) == true || pairing.contains(id)) 0 else 1 }.sum() fun Pairable.eval(criterion: Criterion) = evalCriterion(this, criterion) open fun evalCriterion(pairable: Pairable, criterion: Criterion) = when (criterion) { diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt index f58fbd5..f0e97be 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/MacMahonSolver.kt @@ -16,11 +16,12 @@ class MacMahonSolver(round: Int, override val scores: Map by lazy { require (mmBar > mmFloor) { "MMFloor is higher than MMBar" } + val pairing = pairables.map { it.id }.toSet() pairablesMap.mapValues { it.value.let { pairable -> pairable.mmBase + pairable.nbW + // TODO take tournament parameter into account - pairable.missedRounds(round) * pairingParams.main.mmsValueAbsent + pairable.missedRounds(round, pairing) * pairingParams.main.mmsValueAbsent } } }