From 6fb675e75f18e1ec19785209c88fbf54c59d9e37 Mon Sep 17 00:00:00 2001 From: Quentin Rendu Date: Tue, 26 Sep 2023 09:08:38 +0200 Subject: [PATCH] Add conditions to avoid division by 0 in weights --- .../kotlin/org/jeudego/pairgoth/pairing/Solver.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt index bca2ba7..5c191b8 100644 --- a/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt +++ b/api-webapp/src/main/kotlin/org/jeudego/pairgoth/pairing/Solver.kt @@ -227,9 +227,11 @@ sealed class Solver( var score = 0.0 val scoreRange: Int = groupsCount // TODO check category equality if category are used in SwissCat - val x = abs(p1.group - p2.group).toDouble() / scoreRange.toDouble() - val k: Double = pairing.base.nx1 - score = scoreWeight * (1.0 - x) * (1.0 + k * x) + if (scoreRange!=0){ + val x = abs(p1.group - p2.group).toDouble() / scoreRange.toDouble() + val k: Double = pairing.base.nx1 + score = scoreWeight * (1.0 - x) * (1.0 + k * x) + } logWeights("score", p1, p2, score) return score @@ -304,6 +306,7 @@ sealed class Solver( } else { 0.0 } + //println("countryRatio="+countryRatio.toString()) // Same club and club group (TODO club group) var clubRatio = 0.0 @@ -334,13 +337,15 @@ sealed class Solver( val secPart = min(countryRatio, clubRatio) var geoRatio = mainPart + secPart / 2.0 - if (geoRatio > 0.0) { + + if (geoRatio > 0.0 && placementScoreRange != 0) { geoRatio += 0.5 / placementScoreRange.toDouble() } // The concavity function is applied to geoRatio to get geoCost val dbGeoCost: Double = geoMaxCost.toDouble() * (1.0 - geoRatio) * (1.0 + pairing.base.nx1 * geoRatio) var score = pairing.main.scoreWeight - dbGeoCost + score = min(score, geoMaxCost) return score