From 7340f2de57ae1f775116bd583c160a0cdd3a929f Mon Sep 17 00:00:00 2001 From: Theo Barollet Date: Fri, 29 Dec 2023 16:13:15 +0100 Subject: [PATCH] fixed mmsolver instantiation in dudd computation --- .../kotlin/org/jeudego/pairgoth/model/Tournament.kt | 4 ++-- .../jeudego/pairgoth/pairing/solver/BaseSolver.kt | 13 ++++++------- .../pairgoth/pairing/solver/MacMahonSolver.kt | 10 ++++++---- 3 files changed, 14 insertions(+), 13 deletions(-) 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 2b80e20..d4e5810 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 @@ -74,11 +74,11 @@ sealed class Tournament ( fun recomputeDUDD(round: Int, gameID: ID) { // Instantiate solver with game history // TODO cleaner solver instantiation - val history = games.map { games -> games.values.toList() } + val history = historyBefore(round) val solver = if (pairing is Swiss) { SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams) } else if (pairing is MacMahon) { - MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, pairing.mmBar, pairing.mmFloor) + MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, pairing.mmFloor, pairing.mmBar) } else throw Exception("Invalid tournament type") // Recomputes DUDD 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 1fb6812..797298c 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 @@ -194,8 +194,9 @@ sealed class BaseSolver( else if (wb1 == 0 && abs(wb2) >= 2 || wb2 == 0 && abs(wb1) >= 2) colorBalanceWeight / 2 else 0.0 } else { // apply a *big* score to let the stronger player have white - if (hd2 == 0) colorBalanceWeight * 10 - else 0.0 + //if (hd2 == 0) colorBalanceWeight * 10 + //else 0.0 + 0.0 } return score } @@ -304,8 +305,6 @@ sealed class BaseSolver( val lSPgroupSize = lowerSP.placeInGroup.second - - if (pairing.main.drawUpDownUpperMode === MainCritParams.DrawUpDown.TOP) { score += duddWeight / 2 * (uSPgroupSize - 1 - upperSP.placeInGroup.first) / uSPgroupSize } else if (pairing.main.drawUpDownUpperMode === MainCritParams.DrawUpDown.MIDDLE) { @@ -332,7 +331,7 @@ sealed class BaseSolver( score += 4 * duddWeight } - /*if(debug){ + /*if(true) { println("Names DU DD "+p1.nameSeed()+" "+p1_DU+" "+p1_DD+" "+p2.nameSeed()+" "+p2_DU+" "+p2_DD) println("Names "+upperSP.nameSeed()+" "+upperSP.group+" "+lowerSP.nameSeed()+" "+lowerSP.group) println("DUDD scenario, GroupDiff = "+scenario.toString()+" "+(upperSP.group-lowerSP.group).toString()) @@ -421,8 +420,8 @@ sealed class BaseSolver( fun GeographicalParams.apply(p1: Pairable, p2: Pairable): Double { val placementScoreRange = groupsCount - val geoMaxCost = pairing.geo.avoidSameGeo - //val geoMaxCost = 100000000000.0 + //val geoMaxCost = pairing.geo.avoidSameGeo + val geoMaxCost = 100000000000.0 val countryFactor = preferMMSDiffRatherThanSameCountry val clubFactor: Int = preferMMSDiffRatherThanSameClub 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 2c35af3..01cc555 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 @@ -12,12 +12,14 @@ class MacMahonSolver(round: Int, private val mmFloor: Int, private val mmBar: Int): BaseSolver(round, history, pairables, pairingParams, placementParams) { + override val scores: Map by lazy { + require (mmBar > mmFloor) { "MMFloor is higher than MMBar" } pairablesMap.mapValues { - it.value.let { - pairable -> pairable.mmBase + - pairable.nbW + // TODO take tournament parameter into account - pairable.missedRounds(round) * pairingParams.main.mmsValueAbsent + it.value.let { pairable -> + pairable.mmBase + + pairable.nbW + // TODO take tournament parameter into account + pairable.missedRounds(round) * pairingParams.main.mmsValueAbsent } } }