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 c95489f..efb9983 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 @@ -33,7 +33,7 @@ sealed class BaseSolver( val rand = Random(/* seed from properties - TODO */) // Used in tests var weightsLogger: PrintWriter? = null - var asymmetricDetRandom = false + var legacy_mode = false } open fun openGothaWeight(p1: Pairable, p2: Pairable) = @@ -389,7 +389,7 @@ sealed class BaseSolver( val randRange = maxSeedingWeight * 0.2 // for old tests to pass val rand = - if (asymmetricDetRandom && p1.fullName() > p2.fullName()) { + if (legacy_mode && p1.fullName() > p2.fullName()) { // for old tests to pass detRandom(randRange, p2, p1, false) } else { @@ -426,13 +426,12 @@ sealed class BaseSolver( val placementScoreRange = groupsCount val geoMaxCost = pairing.geo.avoidSameGeo - //val geoMaxCost = 100000000000.0 - val countryFactor: Int = if (biggestCountrySize.toDouble() / pairables.size <= proportionMainClubThreshold) + val countryFactor: Int = if (legacy_mode || biggestCountrySize.toDouble() / pairables.size <= proportionMainClubThreshold) preferMMSDiffRatherThanSameCountry else 0 - val clubFactor: Int = if (biggestClubSize.toDouble() / pairables.size <= proportionMainClubThreshold) + val clubFactor: Int = if (legacy_mode || biggestClubSize.toDouble() / pairables.size <= proportionMainClubThreshold) preferMMSDiffRatherThanSameClub else 0 diff --git a/api-webapp/src/test/kotlin/BOSP2024Test.kt b/api-webapp/src/test/kotlin/BOSP2024Test.kt index e46ad75..a2adf96 100644 --- a/api-webapp/src/test/kotlin/BOSP2024Test.kt +++ b/api-webapp/src/test/kotlin/BOSP2024Test.kt @@ -2,6 +2,7 @@ package org.jeudego.pairgoth.test import com.republicate.kson.Json import org.jeudego.pairgoth.pairing.solver.BaseSolver +import org.jeudego.pairgoth.model.Game import org.jeudego.pairgoth.test.PairingTests.Companion.compare_weights import org.junit.jupiter.api.Test import java.io.FileWriter @@ -22,24 +23,31 @@ class BOSP2024Test: TestBase() { val resp = TestAPI.post("/api/tour", tournament).asObject() val tourId = resp.getInt("id") BaseSolver.weightsLogger = PrintWriter(FileWriter(getOutputFile("bosp2024-weights.txt"))) + + BaseSolver.legacy_mode = true + TestAPI.post("/api/tour/$tourId/pair/3", Json.Array("all")).asArray() + + // compare weights + assertTrue(compare_weights(getOutputFile("bosp2024-weights.txt"), getTestFile("opengotha/bosp2024/bosp2024_weights_R3.txt")), "Not matching opengotha weights for BOSP test") + TestAPI.delete("/api/tour/$tourId/pair/3", Json.Array("all")) + + BaseSolver.legacy_mode = false val games = TestAPI.post("/api/tour/$tourId/pair/3", Json.Array("all")).asArray() // Aksut Husrev is ID 18 - val buggy = games.map { it as Json.Object }.filter { game -> + val solved = games.map { it as Json.Object }.filter { game -> // build the two-elements set of players ids val players = game.entries.filter { (k, v) -> k == "b" || k == "w" }.map { (k, v) -> (v as Number).toInt() }.toSet() // keep game with Aksut Husrev players.contains(18) }.firstOrNull() - assertNotNull(buggy) + assertNotNull(solved) // if the bug is still here, the opponent is Suleymanoglu Serap, id 24 - val black = buggy!!.getInt("b")!! - val white = buggy!!.getInt("w")!! + val black = solved.getInt("b")!! + val white = solved.getInt("w")!! val opponent = if (black == 18) white else black assertNotEquals(24, opponent) - // compare weights - //assertTrue(compare_weights(getOutputFile("bosp2024-weights.txt"), getTestFile("opengotha/bosp2024/bosp2024_weights_R3.txt")), "Not matching opengotha weights for BOSP test") } } diff --git a/api-webapp/src/test/kotlin/PairingTests.kt b/api-webapp/src/test/kotlin/PairingTests.kt index f0482f7..e2e2da9 100644 --- a/api-webapp/src/test/kotlin/PairingTests.kt +++ b/api-webapp/src/test/kotlin/PairingTests.kt @@ -164,9 +164,14 @@ class PairingTests: TestBase() { return sumOfWeights } - fun test_from_XML(name:String, forcePairing:List){ + fun test_from_XML(name: String, forcePairing:List) { + test_from_XML_internal(name, true) + test_from_XML_internal(name, false) + } + + fun test_from_XML_internal(name: String, legacy: Boolean){ // Let pairgoth use the legacy asymmetric detRandom() - BaseSolver.asymmetricDetRandom = true + BaseSolver.legacy_mode = legacy // read tournament with pairing val file = getTestFile("opengotha/pairings/$name.xml") logger.info("read from file $file") @@ -203,8 +208,10 @@ class PairingTests: TestBase() { logger.info("sumOfWeightOG = " + dec.format(sumOfWeightsOG)) logger.info("games for round $round: {}", games.toString()) - // Compare weights with OpenGotha - assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/$name/$name"+"_weights_R$round.txt")), "Not matching opengotha weights for round $round") + // Compare weights with OpenGotha if legacy mode + if (legacy) { + assertTrue(compare_weights(getOutputFile("weights.txt"), getTestFile("opengotha/$name/$name"+"_weights_R$round.txt")), "Not matching opengotha weights for round $round") + } if (round in forcePairing) { logger.info("Non unique pairing, forcing Opengotha pairing to Pairgoth") @@ -265,7 +272,7 @@ class PairingTests: TestBase() { @Test fun `SwissTest simpleSwiss`() { - BaseSolver.asymmetricDetRandom = true + BaseSolver.legacy_mode = true // read tournament with pairing var file = getTestFile("opengotha/pairings/simpleswiss.xml") logger.info("read from file $file") @@ -346,7 +353,7 @@ class PairingTests: TestBase() { @Test fun `SwissTest KPMCSplitbug`() { // Let pairgoth use the legacy asymmetric detRandom() - BaseSolver.asymmetricDetRandom = true + BaseSolver.legacy_mode = true // read tournament with pairing val name = "20240921-KPMC-Splitbug" val file = getTestFile("opengotha/pairings/$name.xml")