diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt index 18c54dc..b99f9c1 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/HistoryHelper.kt @@ -2,7 +2,7 @@ package org.jeudego.pairgoth.pairing import org.jeudego.pairgoth.model.* -open class HistoryHelper(protected val history: List, score: Map) { +open class HistoryHelper(protected val history: List, computeScore: () -> Map) { fun getCriterionValue(p: Pairable, crit: PlacementCriterion): Int { // Returns generic criterion @@ -26,7 +26,7 @@ open class HistoryHelper(protected val history: List, score: Map> by lazy { + protected val paired: Set> by lazy { (history.map { game -> Pair(game.black, game.white) } + history.map { game -> @@ -36,7 +36,7 @@ open class HistoryHelper(protected val history: List, score: Map by lazy { + private val colorBalance: Map by lazy { history.flatMap { game -> if (game.handicap == 0) { listOf(Pair(game.white, +1), Pair(game.black, -1)) } else { @@ -47,8 +47,8 @@ open class HistoryHelper(protected val history: List, score: Map by lazy { - mutableMapOf().apply { + val numberWins: Map by lazy { + mutableMapOf().apply { history.forEach { game -> when (game.result) { Game.Result.BLACK -> put(game.black, getOrDefault(game.black, 0.0) + 1.0) @@ -63,6 +63,11 @@ open class HistoryHelper(protected val history: List, score: Map @@ -114,8 +119,8 @@ open class HistoryHelper(protected val history: List, score: Map, score: Map): - HistoryHelper(history, score) { +class TeamOfIndividualsHistoryHelper(history: List, computeScore: () -> Map): + HistoryHelper(history, computeScore) { private fun Pairable.asTeam() = this as TeamTournament.Team diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt index 5d0010d..d35fe3b 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt @@ -12,6 +12,7 @@ import kotlin.math.abs import kotlin.math.max import kotlin.math.min +val DEBUG_EXPORT_WEIGHT = true private fun detRandom(max: Long, p1: Pairable, p2: Pairable): Long { var nR: Long = 0 @@ -353,10 +354,10 @@ sealed class Solver( } // Generic parameters calculation - private val standingScore = computeStandingScore() - val historyHelper = - if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper(history, standingScore) - else HistoryHelper(history, standingScore) + //private val standingScore by lazy { computeStandingScore() } + + val historyHelper = if (pairables.first().let { it is TeamTournament.Team && it.teamOfIndividuals }) TeamOfIndividualsHistoryHelper(history, ::computeStandingScore) + else HistoryHelper(history, ::computeStandingScore) @@ -404,7 +405,6 @@ sealed class Solver( val Pairable.nbW: Double get() = historyHelper.nbW(this) ?: 0.0 val Pairable.sos: Double get() = historyHelper.sos[id]!! - val Pairable.sosm1: Double get() = historyHelper.sosm1[id]!! val Pairable.sosm2: Double get() = historyHelper.sosm2[id]!! val Pairable.sosos: Double get() = historyHelper.sosos[id]!!