Code cleaning ; rename secParams.rankThreshold to rankSecThreshold

This commit is contained in:
Claude Brisson
2024-05-24 14:03:51 +02:00
parent f4a4921877
commit 2ad683668c
4 changed files with 19 additions and 32 deletions

View File

@@ -6,7 +6,6 @@ import java.time.LocalDate
import org.jeudego.pairgoth.model.* import org.jeudego.pairgoth.model.*
import org.jeudego.pairgoth.opengotha.TournamentType import org.jeudego.pairgoth.opengotha.TournamentType
import org.jeudego.pairgoth.opengotha.ObjectFactory import org.jeudego.pairgoth.opengotha.ObjectFactory
import org.jeudego.pairgoth.store.Store
import org.jeudego.pairgoth.store.nextGameId import org.jeudego.pairgoth.store.nextGameId
import org.jeudego.pairgoth.store.nextPlayerId import org.jeudego.pairgoth.store.nextPlayerId
import org.jeudego.pairgoth.store.nextTournamentId import org.jeudego.pairgoth.store.nextTournamentId
@@ -93,7 +92,7 @@ object OpenGotha {
), ),
secondary = SecondaryCritParams( secondary = SecondaryCritParams(
barThresholdActive = pairParams.paiSeBarThresholdActive.toBoolean(), barThresholdActive = pairParams.paiSeBarThresholdActive.toBoolean(),
rankThreshold = Pairable.parseRank(pairParams.paiSeRankThreshold), rankSecThreshold = Pairable.parseRank(pairParams.paiSeRankThreshold),
nbWinsThresholdActive = pairParams.paiSeNbWinsThresholdActive.toBoolean(), nbWinsThresholdActive = pairParams.paiSeNbWinsThresholdActive.toBoolean(),
defSecCrit = pairParams.paiSeDefSecCrit.toDouble() defSecCrit = pairParams.paiSeDefSecCrit.toDouble()
), ),
@@ -333,7 +332,7 @@ object OpenGotha {
} }
</PlacementCriteria> </PlacementCriteria>
</PlacementParameterSet> </PlacementParameterSet>
<PairingParameterSet paiBaAvoidDuplGame="${tournament.pairing.pairingParams.base.dupWeight.toLong()}" paiBaBalanceWB="${tournament.pairing.pairingParams.base.colorBalanceWeight.toLong()}" paiBaDeterministic="${tournament.pairing.pairingParams.base.deterministic}" paiBaRandom="${tournament.pairing.pairingParams.base.random.toLong()}" paiMaAdditionalPlacementCritSystem1="${tournament.pairing.pairingParams.main.additionalPlacementCritSystem1.toString().titlecase()}" paiMaAdditionalPlacementCritSystem2="${tournament.pairing.pairingParams.main.additionalPlacementCritSystem2.toString().titlecase()}" paiMaAvoidMixingCategories="${tournament.pairing.pairingParams.main.categoriesWeight.toLong()}" paiMaCompensateDUDD="${tournament.pairing.pairingParams.main.compensateDrawUpDown}" paiMaDUDDLowerMode="${tournament.pairing.pairingParams.main.drawUpDownLowerMode.toString().substring(0, 3)}" paiMaDUDDUpperMode="${tournament.pairing.pairingParams.main.drawUpDownUpperMode.toString().substring(0, 3)}" paiMaDUDDWeight="${tournament.pairing.pairingParams.main.drawUpDownWeight.toLong()}" paiMaLastRoundForSeedSystem1="${tournament.pairing.pairingParams.main.lastRoundForSeedSystem1}" paiMaMaximizeSeeding="${tournament.pairing.pairingParams.main.seedingWeight.toLong()}" paiMaMinimizeScoreDifference="${tournament.pairing.pairingParams.main.scoreWeight.toLong()}" paiMaSeedSystem1="${tournament.pairing.pairingParams.main.seedSystem1.format()}" paiMaSeedSystem2="${tournament.pairing.pairingParams.main.seedSystem2.format()}" paiSeAvoidSameGeo="${tournament.pairing.pairingParams.geo.avoidSameGeo.toLong()}" paiSeBarThresholdActive="${tournament.pairing.pairingParams.secondary.barThresholdActive}" paiSeDefSecCrit="${tournament.pairing.pairingParams.secondary.defSecCrit.toLong()}" paiSeMinimizeHandicap="${tournament.pairing.pairingParams.handicap.weight.toLong()}" paiSeNbWinsThresholdActive="${tournament.pairing.pairingParams.secondary.nbWinsThresholdActive}" paiSePreferMMSDiffRatherThanSameClub="${tournament.pairing.pairingParams.geo.preferMMSDiffRatherThanSameClub}" paiSePreferMMSDiffRatherThanSameCountry="${tournament.pairing.pairingParams.geo.preferMMSDiffRatherThanSameCountry}" paiSeRankThreshold="${displayRank(tournament.pairing.pairingParams.secondary.rankThreshold).uppercase()}" paiStandardNX1Factor="${tournament.pairing.pairingParams.base.nx1}"/> <PairingParameterSet paiBaAvoidDuplGame="${tournament.pairing.pairingParams.base.dupWeight.toLong()}" paiBaBalanceWB="${tournament.pairing.pairingParams.base.colorBalanceWeight.toLong()}" paiBaDeterministic="${tournament.pairing.pairingParams.base.deterministic}" paiBaRandom="${tournament.pairing.pairingParams.base.random.toLong()}" paiMaAdditionalPlacementCritSystem1="${tournament.pairing.pairingParams.main.additionalPlacementCritSystem1.toString().titlecase()}" paiMaAdditionalPlacementCritSystem2="${tournament.pairing.pairingParams.main.additionalPlacementCritSystem2.toString().titlecase()}" paiMaAvoidMixingCategories="${tournament.pairing.pairingParams.main.categoriesWeight.toLong()}" paiMaCompensateDUDD="${tournament.pairing.pairingParams.main.compensateDrawUpDown}" paiMaDUDDLowerMode="${tournament.pairing.pairingParams.main.drawUpDownLowerMode.toString().substring(0, 3)}" paiMaDUDDUpperMode="${tournament.pairing.pairingParams.main.drawUpDownUpperMode.toString().substring(0, 3)}" paiMaDUDDWeight="${tournament.pairing.pairingParams.main.drawUpDownWeight.toLong()}" paiMaLastRoundForSeedSystem1="${tournament.pairing.pairingParams.main.lastRoundForSeedSystem1}" paiMaMaximizeSeeding="${tournament.pairing.pairingParams.main.seedingWeight.toLong()}" paiMaMinimizeScoreDifference="${tournament.pairing.pairingParams.main.scoreWeight.toLong()}" paiMaSeedSystem1="${tournament.pairing.pairingParams.main.seedSystem1.format()}" paiMaSeedSystem2="${tournament.pairing.pairingParams.main.seedSystem2.format()}" paiSeAvoidSameGeo="${tournament.pairing.pairingParams.geo.avoidSameGeo.toLong()}" paiSeBarThresholdActive="${tournament.pairing.pairingParams.secondary.barThresholdActive}" paiSeDefSecCrit="${tournament.pairing.pairingParams.secondary.defSecCrit.toLong()}" paiSeMinimizeHandicap="${tournament.pairing.pairingParams.handicap.weight.toLong()}" paiSeNbWinsThresholdActive="${tournament.pairing.pairingParams.secondary.nbWinsThresholdActive}" paiSePreferMMSDiffRatherThanSameClub="${tournament.pairing.pairingParams.geo.preferMMSDiffRatherThanSameClub}" paiSePreferMMSDiffRatherThanSameCountry="${tournament.pairing.pairingParams.geo.preferMMSDiffRatherThanSameCountry}" paiSeRankThreshold="${displayRank(tournament.pairing.pairingParams.secondary.rankSecThreshold).uppercase()}" paiStandardNX1Factor="${tournament.pairing.pairingParams.base.nx1}"/>
<DPParameterSet displayClCol="true" displayCoCol="true" displayIndGamesInMatches="true" displayNPPlayers="false" displayNumCol="true" displayPlCol="true" gameFormat="short" playerSortType="name" showByePlayer="true" showNotFinallyRegisteredPlayers="true" showNotPairedPlayers="true" showNotParticipatingPlayers="false" showPlayerClub="true" showPlayerCountry="false" showPlayerGrade="true"/> <DPParameterSet displayClCol="true" displayCoCol="true" displayIndGamesInMatches="true" displayNPPlayers="false" displayNumCol="true" displayPlCol="true" gameFormat="short" playerSortType="name" showByePlayer="true" showNotFinallyRegisteredPlayers="true" showNotPairedPlayers="true" showNotParticipatingPlayers="false" showPlayerClub="true" showPlayerCountry="false" showPlayerGrade="true"/>
<PublishParameterSet exportToLocalFile="true" htmlAutoScroll="false" print="false"/> <PublishParameterSet exportToLocalFile="true" htmlAutoScroll="false" print="false"/>
</TournamentParameterSet> </TournamentParameterSet>

View File

@@ -6,7 +6,6 @@ import org.jeudego.pairgoth.model.MainCritParams.SeedMethod.SPLIT_AND_SLIP
import org.jeudego.pairgoth.model.PairingType.* 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 kotlin.math.min import kotlin.math.min
// base pairing parameters // base pairing parameters
@@ -69,7 +68,7 @@ data class MainCritParams(
// secondary criterium parameters // secondary criterium parameters
data class SecondaryCritParams( data class SecondaryCritParams(
val barThresholdActive: Boolean = true, // Do not apply secondary criteria for players above bar 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 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 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( secondary = SecondaryCritParams(
barThresholdActive = true, barThresholdActive = true,
rankThreshold = -30, rankSecThreshold = -30,
nbWinsThresholdActive = true, nbWinsThresholdActive = true,
defSecCrit = MainCritParams.MAX_CATEGORIES_WEIGHT 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( fun SecondaryCritParams.Companion.fromJson(json: Json.Object, localDefault: SecondaryCritParams? = null) = SecondaryCritParams(
barThresholdActive = json.getBoolean("barThreshold") ?: localDefault?.barThresholdActive ?: default.barThresholdActive, 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, nbWinsThresholdActive = json.getBoolean("winsThreshold") ?: localDefault?.nbWinsThresholdActive ?: default.nbWinsThresholdActive,
defSecCrit = json.getDouble("secWeight") ?: localDefault?.defSecCrit ?: default.defSecCrit defSecCrit = json.getDouble("secWeight") ?: localDefault?.defSecCrit ?: default.defSecCrit
) )
fun SecondaryCritParams.toJson() = Json.Object( fun SecondaryCritParams.toJson() = Json.Object(
"barThreshold" to barThresholdActive, "barThreshold" to barThresholdActive,
"rankThreshold" to rankThreshold, "rankThreshold" to rankSecThreshold,
"winsThreshold" to nbWinsThresholdActive, "winsThreshold" to nbWinsThresholdActive,
"secWeight" to defSecCrit "secWeight" to defSecCrit
) )

View File

@@ -429,13 +429,6 @@ sealed class BaseSolver(
return score 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 { fun GeographicalParams.apply(p1: Pairable, p2: Pairable): Double {
val placementScoreRange = groupsCount val placementScoreRange = groupsCount

View File

@@ -35,26 +35,22 @@ class MacMahonSolver(round: Int,
override fun SecondaryCritParams.apply(p1: Pairable, p2: Pairable): Double { override fun SecondaryCritParams.apply(p1: Pairable, p2: Pairable): Double {
// Do we apply Secondary Criteria // Do we apply Secondary Criteria.
// secCase = 0 : No player is above thresholds -> apply secondary criteria // No player is above thresholds -> apply secondary criteria
// secCase = 1 : At least one player is above thresholds -> do not apply // At least one player is above thresholds -> do not apply
var score = 0.0 val nbw2Threshold =
var secCase = 0 if (nbWinsThresholdActive) totalRounds
else 2 * totalRounds
val nbw2Threshold: Int val skipSecondary =
if (nbWinsThresholdActive) nbw2Threshold = totalRounds (2 * p1.nbW >= nbw2Threshold) ||
else nbw2Threshold = 2 * totalRounds (2 * p2.nbW >= nbw2Threshold) ||
(p1.rank + p1.nbW >= mmBar) ||
(p2.rank + p2.nbW >= mmBar)
if( (2*p1.nbW >= nbw2Threshold) || return if (skipSecondary) 0.0
(2*p2.nbW >= nbw2Threshold) || else pairing.geo.apply(p1, p2)
(p1.rank+p1.nbW >= mmBar) ||
(p2.rank+p2.nbW >= mmBar) ) secCase = 1
if (secCase == 0) score = pairing.geo.apply(p1, p2)
return score
} }
override fun HandicapParams.pseudoRank(pairable: Pairable): Int { override fun HandicapParams.pseudoRank(pairable: Pairable): Int {