Add argument totalRounds, needed to compute secondary weights

This commit is contained in:
Quentin Rendu
2024-05-23 15:28:45 +02:00
committed by Claude Brisson
parent 793180a116
commit 0bb62b6a3f
6 changed files with 23 additions and 17 deletions

View File

@@ -172,7 +172,7 @@ class Swiss(
): Pairing(SWISS, pairingParams, placementParams) {
companion object {}
override fun pair(tournament: Tournament<*>, round: Int, pairables: List<Pairable>): List<Game> {
return SwissSolver(round, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round)).pair()
return SwissSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round)).pair()
}
}
@@ -201,7 +201,7 @@ class MacMahon(
): Pairing(MAC_MAHON, pairingParams, placementParams) {
companion object {}
override fun pair(tournament: Tournament<*>, round: Int, pairables: List<Pairable>): List<Game> {
return MacMahonSolver(round, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar).pair()
return MacMahonSolver(round, tournament.rounds, tournament.historyBefore(round), pairables, pairingParams, placementParams, tournament.usedTables(round), mmFloor, mmBar).pair()
}
}

View File

@@ -79,9 +79,9 @@ sealed class Tournament <P: Pairable>(
// TODO cleaner solver instantiation
val history = historyBefore(round)
val solver = if (pairing is Swiss) {
SwissSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round))
SwissSolver(round, rounds, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round))
} else if (pairing is MacMahon) {
MacMahonSolver(round, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round), pairing.mmFloor, pairing.mmBar)
MacMahonSolver(round, rounds, history, pairables.values.toList(), pairing.pairingParams, pairing.placementParams, usedTables(round), pairing.mmFloor, pairing.mmBar)
} else throw Exception("Invalid tournament type")
// Recomputes DUDD and hd

View File

@@ -5,6 +5,7 @@ import java.util.*
abstract class BasePairingHelper(
val round: Int,
val totalRounds: Int,
history: List<List<Game>>, // History of all games played for each round
var pairables: List<Pairable>, // All pairables for this round, it may include the bye player
val pairing: PairingParams,

View File

@@ -18,12 +18,13 @@ import kotlin.math.*
sealed class BaseSolver(
round: Int,
totalRounds: Int,
history: List<List<Game>>, // History of all games played for each round
pairables: List<Pairable>, // All pairables for this round, it may include the bye player
pairing: PairingParams,
placement: PlacementParams,
val usedTables: BitSet
) : BasePairingHelper(round, history, pairables, pairing, placement) {
) : BasePairingHelper(round, totalRounds, history, pairables, pairing, placement) {
companion object {
val rand = Random(/* seed from properties - TODO */)
@@ -192,6 +193,7 @@ sealed class BaseSolver(
val hd1 = pairing.handicap.handicap(white = p1, black = p2)
val hd2 = pairing.handicap.handicap(white = p2, black = p1)
val potentialHd: Int = max(hd1, hd2)
val score = if (potentialHd == 0) {
val wb1: Int = p1.colorBalance
val wb2: Int = p2.colorBalance
@@ -416,11 +418,11 @@ sealed class BaseSolver(
var secCase = 0
val nbw2Threshold: Int
if (nbWinsThresholdActive) nbw2Threshold = round
else nbw2Threshold = 2 * round
if (nbWinsThresholdActive) nbw2Threshold = totalRounds
else nbw2Threshold = 2 * totalRounds
if( (2*p1.main >= nbw2Threshold) ||
(2*p2.main >= nbw2Threshold) ) secCase = 1
if( (2*p1.nbW >= nbw2Threshold) ||
(2*p2.nbW >= nbw2Threshold) ) secCase = 1
if (secCase == 0) score = pairing.geo.apply(p1, p2)

View File

@@ -7,13 +7,14 @@ import kotlin.math.min
import kotlin.math.roundToInt
class MacMahonSolver(round: Int,
totalRounds: Int,
history: List<List<Game>>,
pairables: List<Pairable>,
pairingParams: PairingParams,
placementParams: PlacementParams,
usedTables: BitSet,
private val mmFloor: Int, private val mmBar: Int) :
BaseSolver(round, history, pairables, pairingParams, placementParams, usedTables) {
BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) {
override val scores: Map<ID, Pair<Double, Double>> by lazy {
require (mmBar > mmFloor) { "MMFloor is higher than MMBar" }
@@ -42,13 +43,14 @@ class MacMahonSolver(round: Int,
var secCase = 0
val nbw2Threshold: Int
if (nbWinsThresholdActive) nbw2Threshold = round
else nbw2Threshold = 2 * round
if (nbWinsThresholdActive) nbw2Threshold = totalRounds
else nbw2Threshold = 2 * totalRounds
if( (2*p1.nbW >= nbw2Threshold) ||
(2*p2.nbW >= nbw2Threshold) ||
(p1.rank+p1.nbW >= mmBar) ||
(p2.rank+p2.nbW >= mmBar) ) secCase = 1
if( (2*p1.main >= nbw2Threshold) ||
(2*p2.main >= nbw2Threshold) ||
(p1.main >= mmBar) ||
(p2.main >= mmBar) ) secCase = 1
if (secCase == 0) score = pairing.geo.apply(p1, p2)

View File

@@ -4,13 +4,14 @@ import org.jeudego.pairgoth.model.*
import java.util.*
class SwissSolver(round: Int,
totalRounds: Int,
history: List<List<Game>>,
pairables: List<Pairable>,
pairingParams: PairingParams,
placementParams: PlacementParams,
usedTables: BitSet
):
BaseSolver(round, history, pairables, pairingParams, placementParams, usedTables) {
BaseSolver(round, totalRounds, history, pairables, pairingParams, placementParams, usedTables) {
// In a Swiss tournament the main criterion is the number of wins and already computed