Fix MMS computation for current round and while pairing
This commit is contained in:
@@ -7,6 +7,7 @@ import org.jeudego.pairgoth.model.PairingType.*
|
|||||||
import org.jeudego.pairgoth.pairing.solver.MacMahonSolver
|
import org.jeudego.pairgoth.pairing.solver.MacMahonSolver
|
||||||
import org.jeudego.pairgoth.pairing.solver.SwissSolver
|
import org.jeudego.pairgoth.pairing.solver.SwissSolver
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
// base pairing parameters
|
// base pairing parameters
|
||||||
data class BaseCritParams(
|
data class BaseCritParams(
|
||||||
@@ -135,8 +136,7 @@ sealed class Pairing(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun Tournament<*>.historyBefore(round: Int) =
|
internal fun Tournament<*>.historyBefore(round: Int) =
|
||||||
if (lastRound() == 1) emptyList()
|
(1 until min(round, lastRound() + 1)).map { games(it).values.toList() }
|
||||||
else (1 until round).map { games(it).values.toList() }
|
|
||||||
|
|
||||||
/*private fun Tournament<*>.historyBefore(round: Int) : List<List<Game>> {
|
/*private fun Tournament<*>.historyBefore(round: Int) : List<List<Game>> {
|
||||||
println("Welcome to tournament.historyBefore !")
|
println("Welcome to tournament.historyBefore !")
|
||||||
|
@@ -72,7 +72,7 @@ sealed class Tournament <P: Pairable>(
|
|||||||
fun games(round: Int) = games.getOrNull(round - 1) ?:
|
fun games(round: Int) = games.getOrNull(round - 1) ?:
|
||||||
if (round > games.size + 1) throw Error("invalid round")
|
if (round > games.size + 1) throw Error("invalid round")
|
||||||
else mutableMapOf<ID, Game>().also { games.add(it) }
|
else mutableMapOf<ID, Game>().also { games.add(it) }
|
||||||
fun lastRound() = games.size
|
fun lastRound() = max(1, games.size)
|
||||||
|
|
||||||
fun recomputeHdAndDUDD(round: Int, gameID: ID) {
|
fun recomputeHdAndDUDD(round: Int, gameID: ID) {
|
||||||
// Instantiate solver with game history
|
// Instantiate solver with game history
|
||||||
|
@@ -91,8 +91,8 @@ abstract class BasePairingHelper(
|
|||||||
val Pairable.sosos: Double get() = historyHelper.sosos[id] ?: 0.0
|
val Pairable.sosos: Double get() = historyHelper.sosos[id] ?: 0.0
|
||||||
val Pairable.sodos: Double get() = historyHelper.sodos[id] ?: 0.0
|
val Pairable.sodos: Double get() = historyHelper.sodos[id] ?: 0.0
|
||||||
val Pairable.cums: Double get() = historyHelper.cumScore[id] ?: 0.0
|
val Pairable.cums: Double get() = historyHelper.cumScore[id] ?: 0.0
|
||||||
fun Pairable.missedRounds(upToRound: Int): Int = (1..upToRound).map { round ->
|
fun Pairable.missedRounds(upToRound: Int, pairing: Set<ID>): Int = (1..upToRound).map { round ->
|
||||||
if (historyHelper.playersPerRound.getOrNull(round - 1)?.contains(id) == true) 0 else 1
|
if (historyHelper.playersPerRound.getOrNull(round - 1)?.contains(id) == true || pairing.contains(id)) 0 else 1
|
||||||
}.sum()
|
}.sum()
|
||||||
fun Pairable.eval(criterion: Criterion) = evalCriterion(this, criterion)
|
fun Pairable.eval(criterion: Criterion) = evalCriterion(this, criterion)
|
||||||
open fun evalCriterion(pairable: Pairable, criterion: Criterion) = when (criterion) {
|
open fun evalCriterion(pairable: Pairable, criterion: Criterion) = when (criterion) {
|
||||||
|
@@ -16,11 +16,12 @@ class MacMahonSolver(round: Int,
|
|||||||
|
|
||||||
override val scores: Map<ID, Double> by lazy {
|
override val scores: Map<ID, Double> by lazy {
|
||||||
require (mmBar > mmFloor) { "MMFloor is higher than MMBar" }
|
require (mmBar > mmFloor) { "MMFloor is higher than MMBar" }
|
||||||
|
val pairing = pairables.map { it.id }.toSet()
|
||||||
pairablesMap.mapValues {
|
pairablesMap.mapValues {
|
||||||
it.value.let { pairable ->
|
it.value.let { pairable ->
|
||||||
pairable.mmBase +
|
pairable.mmBase +
|
||||||
pairable.nbW + // TODO take tournament parameter into account
|
pairable.nbW + // TODO take tournament parameter into account
|
||||||
pairable.missedRounds(round) * pairingParams.main.mmsValueAbsent
|
pairable.missedRounds(round, pairing) * pairingParams.main.mmsValueAbsent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user