Convert pairing criteria to double instead of int
This commit is contained in:
@@ -4,20 +4,20 @@ import org.jeudego.pairgoth.model.*
|
|||||||
|
|
||||||
open class HistoryHelper(protected val history: List<Game>, computeScore: () -> Map<ID, Double>) {
|
open class HistoryHelper(protected val history: List<Game>, computeScore: () -> Map<ID, Double>) {
|
||||||
|
|
||||||
fun getCriterionValue(p: Pairable, crit: PlacementCriterion): Int {
|
fun getCriterionValue(p: Pairable, crit: PlacementCriterion): Double {
|
||||||
// Returns generic criterion
|
// Returns generic criterion
|
||||||
// Specific criterion are computed by solvers directly
|
// Specific criterion are computed by solvers directly
|
||||||
return when (crit) {
|
return when (crit) {
|
||||||
PlacementCriterion.NULL -> 0
|
PlacementCriterion.NULL -> 0.0
|
||||||
PlacementCriterion.CATEGORY -> TODO()
|
PlacementCriterion.CATEGORY -> TODO()
|
||||||
PlacementCriterion.RANK -> p.rank
|
PlacementCriterion.RANK -> p.rank.toDouble()
|
||||||
PlacementCriterion.RATING -> p.rating
|
PlacementCriterion.RATING -> p.rating.toDouble()
|
||||||
|
|
||||||
PlacementCriterion.EXT -> TODO()
|
PlacementCriterion.EXT -> TODO()
|
||||||
PlacementCriterion.EXR -> TODO()
|
PlacementCriterion.EXR -> TODO()
|
||||||
PlacementCriterion.SDC -> TODO()
|
PlacementCriterion.SDC -> TODO()
|
||||||
PlacementCriterion.DC -> TODO()
|
PlacementCriterion.DC -> TODO()
|
||||||
else -> -1
|
else -> -1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Generic helper functions
|
// Generic helper functions
|
||||||
|
@@ -23,17 +23,17 @@ class MacMahonSolver(round: Int, history: List<Game>, pairables: List<Pairable>,
|
|||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Int {
|
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Double {
|
||||||
// TODO solve this double/int conflict
|
// TODO solve this double/int conflict
|
||||||
return when (criterion) {
|
return when (criterion) {
|
||||||
PlacementCriterion.MMS -> TODO()
|
PlacementCriterion.MMS -> TODO()
|
||||||
PlacementCriterion.SOSM -> p.sos.toInt()
|
PlacementCriterion.SOSM -> p.sos
|
||||||
PlacementCriterion.SOSMM1 -> p.sosm1.toInt()
|
PlacementCriterion.SOSMM1 -> p.sosm1
|
||||||
PlacementCriterion.SOSMM2 -> p.sosm2.toInt()
|
PlacementCriterion.SOSMM2 -> p.sosm2
|
||||||
PlacementCriterion.SODOSM -> p.sodos.toInt()
|
PlacementCriterion.SODOSM -> p.sodos
|
||||||
PlacementCriterion.SOSOSM -> p.sosos.toInt()
|
PlacementCriterion.SOSOSM -> p.sosos
|
||||||
PlacementCriterion.CUSSM -> p.cums.toInt()
|
PlacementCriterion.CUSSM -> p.cums
|
||||||
else -> -1
|
else -> -1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,7 +61,7 @@ sealed class Solver(
|
|||||||
val criterionP = getCriterionValue(p, criterion)
|
val criterionP = getCriterionValue(p, criterion)
|
||||||
val criterionQ = getCriterionValue(q, criterion)
|
val criterionQ = getCriterionValue(q, criterion)
|
||||||
if (criterionP != criterionQ) {
|
if (criterionP != criterionQ) {
|
||||||
return criterionP - criterionQ
|
return (criterionP - criterionQ).toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
@@ -83,20 +83,20 @@ sealed class Solver(
|
|||||||
// SOS and variants will be computed based on this score
|
// SOS and variants will be computed based on this score
|
||||||
abstract fun computeStandingScore(): Map<ID, Double>
|
abstract fun computeStandingScore(): Map<ID, Double>
|
||||||
// This function needs to be overridden for criterion specific to the current pairing mode
|
// This function needs to be overridden for criterion specific to the current pairing mode
|
||||||
open fun getSpecificCriterionValue(p1: Pairable, criterion: PlacementCriterion): Int {
|
open fun getSpecificCriterionValue(p1: Pairable, criterion: PlacementCriterion): Double {
|
||||||
return -1
|
return -1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getCriterionValue(p1: Pairable, criterion: PlacementCriterion): Int {
|
private fun getCriterionValue(p1: Pairable, criterion: PlacementCriterion): Double {
|
||||||
val genericCritVal = historyHelper.getCriterionValue(p1, criterion)
|
val genericCritVal = historyHelper.getCriterionValue(p1, criterion)
|
||||||
// If the value from the history helper is > 0 it means that it is a generic criterion
|
// If the value from the history helper is > 0 it means that it is a generic criterion
|
||||||
// Just returns the value
|
// Just returns the value
|
||||||
if (genericCritVal != -1) {
|
if (genericCritVal < 0) {
|
||||||
return genericCritVal
|
return genericCritVal
|
||||||
}
|
}
|
||||||
// Otherwise we have to delegate it to the solver
|
// Otherwise we have to delegate it to the solver
|
||||||
val critVal = getSpecificCriterionValue(p1, criterion)
|
val critVal = getSpecificCriterionValue(p1, criterion)
|
||||||
if (critVal == -1) throw Error("Couldn't compute criterion value")
|
if (critVal < 0) throw Error("Couldn't compute criterion value")
|
||||||
return critVal
|
return critVal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,17 +23,17 @@ class SwissSolver(round: Int,
|
|||||||
return historyHelper.numberWins
|
return historyHelper.numberWins
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Int {
|
override fun getSpecificCriterionValue(p: Pairable, criterion: PlacementCriterion): Double {
|
||||||
// TODO solve this double/int conflict
|
// TODO solve this double/int conflict
|
||||||
return when (criterion) {
|
return when (criterion) {
|
||||||
PlacementCriterion.NBW -> p.nbW.toInt()
|
PlacementCriterion.NBW -> p.nbW
|
||||||
PlacementCriterion.SOSW -> p.sos.toInt()
|
PlacementCriterion.SOSW -> p.sos
|
||||||
PlacementCriterion.SOSWM1 -> p.sosm1.toInt()
|
PlacementCriterion.SOSWM1 -> p.sosm1
|
||||||
PlacementCriterion.SOSWM2 -> p.sosm2.toInt()
|
PlacementCriterion.SOSWM2 -> p.sosm2
|
||||||
PlacementCriterion.SODOSW -> p.sodos.toInt()
|
PlacementCriterion.SODOSW -> p.sodos
|
||||||
PlacementCriterion.SOSOSW -> p.sosos.toInt()
|
PlacementCriterion.SOSOSW -> p.sosos
|
||||||
PlacementCriterion.CUSSW -> p.cums.toInt()
|
PlacementCriterion.CUSSW -> p.cums
|
||||||
else -> -1
|
else -> -1.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user