From 9ff354873d6bb3c9a9505d996aaac4867cdc26b7 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Thu, 15 Feb 2024 13:47:38 +0100 Subject: [PATCH] Handle additionnal seeding criterium --- .../org/jeudego/pairgoth/model/Pairable.kt | 4 ++-- .../pairgoth/pairing/BasePairingHelper.kt | 18 +++++++++++++----- .../org/jeudego/pairgoth/pairing/Random.kt | 4 ++-- .../pairgoth/pairing/solver/BaseSolver.kt | 12 ++++++------ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt index a182996..3d5952e 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/model/Pairable.kt @@ -16,7 +16,7 @@ sealed class Pairable(val id: ID, val name: String, open val rating: Int, open v abstract fun toMutableJson(): Json.MutableObject abstract val club: String? abstract val country: String? - open fun nameSeed(separator: String =" "): String { + open fun fullName(separator: String = " "): String { return name } val skip = mutableSetOf() // skipped rounds @@ -95,7 +95,7 @@ class Player( } override fun toJson(): Json.Object = toMutableJson() - override fun nameSeed(separator: String): String { + override fun fullName(separator: String): String { return name + separator + firstname } } 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 f30ec92..c4d968d 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 @@ -4,6 +4,7 @@ import org.jeudego.pairgoth.model.* import java.util.* abstract class BasePairingHelper( + val round: 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 pairing: PairingParams, @@ -125,15 +126,22 @@ abstract class BasePairingHelper( val criterionP = p.eval(criterion) val criterionQ = q.eval(criterion) if (criterionP != criterionQ) { - return (criterionQ * 1e6 - criterionP * 1e6).toInt() + return -criterionP.compareTo(criterionQ) } } - if (p.rating == q.rating) { - return if (p.name > q.name) 1 else -1 + val additionalCriterion = + if (round <= pairing.main.lastRoundForSeedSystem1) pairing.main.additionalPlacementCritSystem1 + else pairing.main.additionalPlacementCritSystem2 + if (additionalCriterion != Criterion.NONE) { + val criterionP = p.eval(additionalCriterion) + val criterionQ = q.eval(additionalCriterion) + if (criterionP != criterionQ) { + return -criterionP.compareTo(criterionQ) + } } - return q.rating - p.rating + return p.fullName().compareTo(q.fullName()) } open fun nameSort(p: Pairable, q: Pairable): Int { - return if (p.name > q.name) 1 else -1 + return p.fullName().compareTo(q.fullName()) } } \ No newline at end of file diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt index 91a2d32..8cb7910 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Random.kt @@ -4,8 +4,8 @@ import org.jeudego.pairgoth.model.Pairable fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double { var inverse = false - var name1 = p1.nameSeed("") - var name2 = p2.nameSeed("") + var name1 = p1.fullName("") + var name2 = p2.fullName("") if (name1 > name2) { name1 = name2.also { name2 = name1 } inverse = true 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 b005731..0823694 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 @@ -22,13 +22,13 @@ import kotlin.math.min import kotlin.math.roundToInt sealed class BaseSolver( - val round: Int, // Round number + round: Int, history: List>, // History of all games played for each round pairables: List, // All pairables for this round, it may include the bye player pairing: PairingParams, placement: PlacementParams, val usedTables: BitSet - ) : BasePairingHelper(history, pairables, pairing, placement) { + ) : BasePairingHelper(round, history, pairables, pairing, placement) { companion object { val rand = Random(/* seed from properties - TODO */) @@ -77,7 +77,7 @@ sealed class BaseSolver( } // println("choose Bye: " + p.nameSeed() + " mms2 " +2*p.main+" "+ weightForBye) } - println("Bye player : " + chosenByePlayer.nameSeed()) + println("Bye player : " + chosenByePlayer.fullName()) byePlayers.add(chosenByePlayer) nameSortedPairables.remove(chosenByePlayer) // Keep chosenByePlayer in pairingSortedPairables to be identical to opengotha @@ -91,8 +91,8 @@ sealed class BaseSolver( weight(p, q).let { if (it != Double.NaN) builder.addEdge(p, q, it/1e6) } weight(q, p).let { if (it != Double.NaN) builder.addEdge(q, p, it/1e6) } weightsLogger?.apply { - this.println("Player1Name=${p.nameSeed()}") - this.println("Player2Name=${q.nameSeed()}") + this.println("Player1Name=${p.fullName()}") + this.println("Player2Name=${q.fullName()}") this.println("baseDuplicateGameCost=${dec.format(pairing.base.avoidDuplicatingGames(p, q))}") this.println("baseRandomCost=${dec.format(pairing.base.applyRandom(p, q))}") this.println("baseBWBalanceCost=${dec.format(pairing.base.applyColorBalance(p, q))}") @@ -384,7 +384,7 @@ sealed class BaseSolver( if ((2 * cla1 < groupSize && 2 * cla2 >= groupSize) || (2 * cla1 >= groupSize && 2 * cla2 < groupSize)) { val randRange = maxSeedingWeight * 0.2 val rand: Double - if (p1.nameSeed() > p2.nameSeed()) {rand = detRandom(randRange, p2, p1)} + if (p1.fullName() > p2.fullName()) {rand = detRandom(randRange, p2, p1)} else {rand = detRandom(randRange, p1, p2)} maxSeedingWeight - rand } else {