diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiTools.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiTools.kt index 6928eed..ecbc176 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiTools.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/api/ApiTools.kt @@ -40,7 +40,7 @@ fun Tournament<*>.getSortedPairables(round: Int): List { it.value.let { pairable -> val mmBase = pairable.mmBase() val score = roundScore(mmBase + - (nbW(pairable) ?: 0.0) + // TODO take tournament parameter into account + (nbW(pairable) ?: 0.0) + (1..round).map { round -> if (playersPerRound.getOrNull(round - 1)?.contains(pairable.id) == true) 0 else 1 }.sum() * pairing.pairingParams.main.mmsValueAbsent) 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 01cb937..d7010e2 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 @@ -174,7 +174,7 @@ class Swiss( ): Pairing(SWISS, pairingParams, placementParams) { companion object {} override fun solver(tournament: Tournament<*>, round: Int, pairables: List) = - SwissSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round)) + SwissSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, tournament.pairables, pairingParams, placementParams, tournament.usedTables(round)) } class MacMahon( @@ -202,7 +202,7 @@ class MacMahon( ): Pairing(MAC_MAHON, pairingParams, placementParams) { companion object {} override fun solver(tournament: Tournament<*>, round: Int, pairables: List) = - MacMahonSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar) + MacMahonSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, tournament.pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar) } class RoundRobin( 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 ec61529..1ec18a0 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 @@ -1,13 +1,13 @@ package org.jeudego.pairgoth.pairing import org.jeudego.pairgoth.model.* -import java.util.* abstract class BasePairingHelper( val round: Int, val totalRounds: Int, history: List>, // History of all games played for each round var pairables: List, // All pairables for this round, it may include the bye player + val pairablesMap: Map, // Map of all known pairables for this tournament val pairing: PairingParams, val placement: PlacementParams, ) { @@ -41,10 +41,6 @@ abstract class BasePairingHelper( pairables.sortedWith(::nameSort).toMutableList() } - protected val pairablesMap by lazy { - pairables.associateBy { it.id } - } - // Generic parameters calculation //private val standingScore by lazy { computeStandingScore() } diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt index ae10a91..fe021a0 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/BaseSolver.kt @@ -11,20 +11,24 @@ import org.jgrapht.alg.matching.blossom.v5.ObjectiveSense import org.jgrapht.graph.DefaultWeightedEdge import org.jgrapht.graph.SimpleDirectedWeightedGraph import org.jgrapht.graph.builder.GraphBuilder +import org.slf4j.LoggerFactory import java.io.PrintWriter import java.text.DecimalFormat import java.util.* import kotlin.math.* +val logger = LoggerFactory.getLogger("debug") + sealed class BaseSolver( round: Int, totalRounds: Int, history: List>, // History of all games played for each round pairables: List, // All pairables for this round, it may include the bye player + pairablesMap: Map, // Map of all known pairables in this tournament pairing: PairingParams, placement: PlacementParams, val usedTables: BitSet - ) : BasePairingHelper(round, totalRounds, history, pairables, pairing, placement) { + ) : BasePairingHelper(round, totalRounds, history, pairables, pairablesMap, pairing, placement) { companion object { val rand = Random(/* seed from properties - TODO */) @@ -85,6 +89,13 @@ sealed class BaseSolver( pairingSortedPairables.remove(ByePlayer) } + if (round == 4) { + logger.info("@@@@@ Round 4 @@@@@") + for (p in sortedPairables) { + logger.info("#${p.id} ${p.name} ${scores[p.id]?.first} ${scores[p.id]?.second} ${p.sos}") + } + } + for (i in nameSortedPairables.indices) { for (j in i + 1 until nameSortedPairables.size) { val p = nameSortedPairables[i] 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 a529477..d360712 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 @@ -10,11 +10,12 @@ class MacMahonSolver(round: Int, totalRounds: Int, history: List>, pairables: List, + pairablesMap: Map, pairingParams: PairingParams, placementParams: PlacementParams, usedTables: BitSet, private val mmFloor: Int, private val mmBar: Int) : - BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) { + BaseSolver(round, totalRounds, history, pairables, pairablesMap, pairingParams, placementParams, usedTables) { override val scores: Map> by lazy { require (mmBar > mmFloor) { "MMFloor is higher than MMBar" } @@ -22,7 +23,7 @@ class MacMahonSolver(round: Int, pairablesMap.mapValues { it.value.let { pairable -> val score = roundScore(pairable.mmBase + - pairable.nbW + // TODO take tournament parameter into account + pairable.nbW + pairable.missedRounds(round, pairing) * pairingParams.main.mmsValueAbsent) Pair( if (pairingParams.main.sosValueAbsentUseBase) pairable.mmBase diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt index 3a8ef58..3497947 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/solver/SwissSolver.kt @@ -7,11 +7,12 @@ class SwissSolver(round: Int, totalRounds: Int, history: List>, pairables: List, + pairablesMap: Map, pairingParams: PairingParams, placementParams: PlacementParams, usedTables: BitSet ): - BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) { + BaseSolver(round, totalRounds, history, pairables, pairablesMap, pairingParams, placementParams, usedTables) { // In a Swiss tournament the main criterion is the number of wins and already computed