Add argument totalRounds, needed to compute secondary weights
This commit is contained in:

committed by
Claude Brisson

parent
793180a116
commit
0bb62b6a3f
@@ -172,7 +172,7 @@ class Swiss(
|
|||||||
): Pairing(SWISS, pairingParams, placementParams) {
|
): Pairing(SWISS, pairingParams, placementParams) {
|
||||||
companion object {}
|
companion object {}
|
||||||
override fun pair(tournament: Tournament<*>, round: Int, pairables: List<Pairable>): List<Game> {
|
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) {
|
): Pairing(MAC_MAHON, pairingParams, placementParams) {
|
||||||
companion object {}
|
companion object {}
|
||||||
override fun pair(tournament: Tournament<*>, round: Int, pairables: List<Pairable>): List<Game> {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -79,9 +79,9 @@ sealed class Tournament <P: Pairable>(
|
|||||||
// TODO cleaner solver instantiation
|
// TODO cleaner solver instantiation
|
||||||
val history = historyBefore(round)
|
val history = historyBefore(round)
|
||||||
val solver = if (pairing is Swiss) {
|
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) {
|
} 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")
|
} else throw Exception("Invalid tournament type")
|
||||||
|
|
||||||
// Recomputes DUDD and hd
|
// Recomputes DUDD and hd
|
||||||
|
@@ -5,6 +5,7 @@ import java.util.*
|
|||||||
|
|
||||||
abstract class BasePairingHelper(
|
abstract class BasePairingHelper(
|
||||||
val round: Int,
|
val round: Int,
|
||||||
|
val totalRounds: Int,
|
||||||
history: List<List<Game>>, // History of all games played for each round
|
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
|
var pairables: List<Pairable>, // All pairables for this round, it may include the bye player
|
||||||
val pairing: PairingParams,
|
val pairing: PairingParams,
|
||||||
|
@@ -18,12 +18,13 @@ import kotlin.math.*
|
|||||||
|
|
||||||
sealed class BaseSolver(
|
sealed class BaseSolver(
|
||||||
round: Int,
|
round: Int,
|
||||||
|
totalRounds: Int,
|
||||||
history: List<List<Game>>, // History of all games played for each round
|
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
|
pairables: List<Pairable>, // All pairables for this round, it may include the bye player
|
||||||
pairing: PairingParams,
|
pairing: PairingParams,
|
||||||
placement: PlacementParams,
|
placement: PlacementParams,
|
||||||
val usedTables: BitSet
|
val usedTables: BitSet
|
||||||
) : BasePairingHelper(round, history, pairables, pairing, placement) {
|
) : BasePairingHelper(round, totalRounds, history, pairables, pairing, placement) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val rand = Random(/* seed from properties - TODO */)
|
val rand = Random(/* seed from properties - TODO */)
|
||||||
@@ -192,6 +193,7 @@ sealed class BaseSolver(
|
|||||||
val hd1 = pairing.handicap.handicap(white = p1, black = p2)
|
val hd1 = pairing.handicap.handicap(white = p1, black = p2)
|
||||||
val hd2 = pairing.handicap.handicap(white = p2, black = p1)
|
val hd2 = pairing.handicap.handicap(white = p2, black = p1)
|
||||||
val potentialHd: Int = max(hd1, hd2)
|
val potentialHd: Int = max(hd1, hd2)
|
||||||
|
|
||||||
val score = if (potentialHd == 0) {
|
val score = if (potentialHd == 0) {
|
||||||
val wb1: Int = p1.colorBalance
|
val wb1: Int = p1.colorBalance
|
||||||
val wb2: Int = p2.colorBalance
|
val wb2: Int = p2.colorBalance
|
||||||
@@ -416,11 +418,11 @@ sealed class BaseSolver(
|
|||||||
var secCase = 0
|
var secCase = 0
|
||||||
|
|
||||||
val nbw2Threshold: Int
|
val nbw2Threshold: Int
|
||||||
if (nbWinsThresholdActive) nbw2Threshold = round
|
if (nbWinsThresholdActive) nbw2Threshold = totalRounds
|
||||||
else nbw2Threshold = 2 * round
|
else nbw2Threshold = 2 * totalRounds
|
||||||
|
|
||||||
if( (2*p1.main >= nbw2Threshold) ||
|
if( (2*p1.nbW >= nbw2Threshold) ||
|
||||||
(2*p2.main >= nbw2Threshold) ) secCase = 1
|
(2*p2.nbW >= nbw2Threshold) ) secCase = 1
|
||||||
|
|
||||||
if (secCase == 0) score = pairing.geo.apply(p1, p2)
|
if (secCase == 0) score = pairing.geo.apply(p1, p2)
|
||||||
|
|
||||||
|
@@ -7,13 +7,14 @@ import kotlin.math.min
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class MacMahonSolver(round: Int,
|
class MacMahonSolver(round: Int,
|
||||||
|
totalRounds: Int,
|
||||||
history: List<List<Game>>,
|
history: List<List<Game>>,
|
||||||
pairables: List<Pairable>,
|
pairables: List<Pairable>,
|
||||||
pairingParams: PairingParams,
|
pairingParams: PairingParams,
|
||||||
placementParams: PlacementParams,
|
placementParams: PlacementParams,
|
||||||
usedTables: BitSet,
|
usedTables: BitSet,
|
||||||
private val mmFloor: Int, private val mmBar: Int) :
|
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 {
|
override val scores: Map<ID, Pair<Double, Double>> by lazy {
|
||||||
require (mmBar > mmFloor) { "MMFloor is higher than MMBar" }
|
require (mmBar > mmFloor) { "MMFloor is higher than MMBar" }
|
||||||
@@ -42,13 +43,14 @@ class MacMahonSolver(round: Int,
|
|||||||
var secCase = 0
|
var secCase = 0
|
||||||
|
|
||||||
val nbw2Threshold: Int
|
val nbw2Threshold: Int
|
||||||
if (nbWinsThresholdActive) nbw2Threshold = round
|
if (nbWinsThresholdActive) nbw2Threshold = totalRounds
|
||||||
else nbw2Threshold = 2 * round
|
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)
|
if (secCase == 0) score = pairing.geo.apply(p1, p2)
|
||||||
|
|
||||||
|
@@ -4,13 +4,14 @@ import org.jeudego.pairgoth.model.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SwissSolver(round: Int,
|
class SwissSolver(round: Int,
|
||||||
|
totalRounds: Int,
|
||||||
history: List<List<Game>>,
|
history: List<List<Game>>,
|
||||||
pairables: List<Pairable>,
|
pairables: List<Pairable>,
|
||||||
pairingParams: PairingParams,
|
pairingParams: PairingParams,
|
||||||
placementParams: PlacementParams,
|
placementParams: PlacementParams,
|
||||||
usedTables: BitSet
|
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
|
// In a Swiss tournament the main criterion is the number of wins and already computed
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user