diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt index af2f1fb..816f9c2 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/ext/OpenGotha.kt @@ -6,7 +6,6 @@ import java.time.LocalDate import org.jeudego.pairgoth.model.* import org.jeudego.pairgoth.opengotha.TournamentType import org.jeudego.pairgoth.opengotha.ObjectFactory -import org.jeudego.pairgoth.store.Store import org.jeudego.pairgoth.store.nextGameId import org.jeudego.pairgoth.store.nextPlayerId import org.jeudego.pairgoth.store.nextTournamentId @@ -93,7 +92,7 @@ object OpenGotha { ), secondary = SecondaryCritParams( barThresholdActive = pairParams.paiSeBarThresholdActive.toBoolean(), - rankThreshold = Pairable.parseRank(pairParams.paiSeRankThreshold), + rankSecThreshold = Pairable.parseRank(pairParams.paiSeRankThreshold), nbWinsThresholdActive = pairParams.paiSeNbWinsThresholdActive.toBoolean(), defSecCrit = pairParams.paiSeDefSecCrit.toDouble() ), @@ -333,7 +332,7 @@ object OpenGotha { } - + 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 c1104d8..399c21a 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 @@ -6,7 +6,6 @@ import org.jeudego.pairgoth.model.MainCritParams.SeedMethod.SPLIT_AND_SLIP 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 @@ -69,7 +68,7 @@ data class MainCritParams( // secondary criterium parameters data class SecondaryCritParams( val barThresholdActive: Boolean = true, // Do not apply secondary criteria for players above bar - val rankThreshold: Int = 0, // Do not apply secondary criteria above 1D rank + val rankSecThreshold: Int = 0, // Do not apply secondary criteria above 1D rank val nbWinsThresholdActive: Boolean = true, // Do not apply secondary criteria when nbWins >= nbRounds / 2 val defSecCrit: Double = MainCritParams.MAX_CATEGORIES_WEIGHT, // Should be MA_MAX_MINIMIZE_SCORE_DIFFERENCE for MM, MA_MAX_AVOID_MIXING_CATEGORIES for others ) { @@ -158,7 +157,7 @@ class Swiss( ), secondary = SecondaryCritParams( barThresholdActive = true, - rankThreshold = -30, + rankSecThreshold = -30, nbWinsThresholdActive = true, defSecCrit = MainCritParams.MAX_CATEGORIES_WEIGHT ), @@ -269,14 +268,14 @@ fun MainCritParams.toJson() = Json.Object( fun SecondaryCritParams.Companion.fromJson(json: Json.Object, localDefault: SecondaryCritParams? = null) = SecondaryCritParams( barThresholdActive = json.getBoolean("barThreshold") ?: localDefault?.barThresholdActive ?: default.barThresholdActive, - rankThreshold = json.getInt("rankThreshold") ?: localDefault?.rankThreshold ?: default.rankThreshold, + rankSecThreshold = json.getInt("rankThreshold") ?: localDefault?.rankSecThreshold ?: default.rankSecThreshold, nbWinsThresholdActive = json.getBoolean("winsThreshold") ?: localDefault?.nbWinsThresholdActive ?: default.nbWinsThresholdActive, defSecCrit = json.getDouble("secWeight") ?: localDefault?.defSecCrit ?: default.defSecCrit ) fun SecondaryCritParams.toJson() = Json.Object( "barThreshold" to barThresholdActive, - "rankThreshold" to rankThreshold, + "rankThreshold" to rankSecThreshold, "winsThreshold" to nbWinsThresholdActive, "secWeight" to defSecCrit ) 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 f8b3e46..adcdc0d 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 @@ -429,13 +429,6 @@ sealed class BaseSolver( return score } - open fun SecondaryCritParams.notNeeded(p1: Pairable, p2: Pairable) { - // secCase = 0 : No player is above thresholds - // secCase = 1 : One player is above thresholds - // secCase = 2 : Both players are above thresholds - // TODO understand where it is used - } - fun GeographicalParams.apply(p1: Pairable, p2: Pairable): Double { val placementScoreRange = groupsCount 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 dca12a1..bf50bae 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 @@ -35,26 +35,22 @@ class MacMahonSolver(round: Int, override fun SecondaryCritParams.apply(p1: Pairable, p2: Pairable): Double { - // Do we apply Secondary Criteria - // secCase = 0 : No player is above thresholds -> apply secondary criteria - // secCase = 1 : At least one player is above thresholds -> do not apply + // Do we apply Secondary Criteria. + // No player is above thresholds -> apply secondary criteria + // At least one player is above thresholds -> do not apply - var score = 0.0 - var secCase = 0 + val nbw2Threshold = + if (nbWinsThresholdActive) totalRounds + else 2 * totalRounds - val nbw2Threshold: Int - if (nbWinsThresholdActive) nbw2Threshold = totalRounds - else nbw2Threshold = 2 * totalRounds + val skipSecondary = + (2 * p1.nbW >= nbw2Threshold) || + (2 * p2.nbW >= nbw2Threshold) || + (p1.rank + p1.nbW >= mmBar) || + (p2.rank + p2.nbW >= mmBar) - if( (2*p1.nbW >= nbw2Threshold) || - (2*p2.nbW >= nbw2Threshold) || - (p1.rank+p1.nbW >= mmBar) || - (p2.rank+p2.nbW >= mmBar) ) secCase = 1 - - - if (secCase == 0) score = pairing.geo.apply(p1, p2) - - return score + return if (skipSecondary) 0.0 + else pairing.geo.apply(p1, p2) } override fun HandicapParams.pseudoRank(pairable: Pairable): Int {