Symmetric detRandom for pairings, asymmetric for colour

This commit is contained in:
Quentin Rendu
2025-01-14 10:43:50 +01:00
committed by Claude Brisson
parent b66b577077
commit cbdb8b1f52
2 changed files with 7 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ package org.jeudego.pairgoth.pairing
import org.jeudego.pairgoth.model.Pairable
import org.jeudego.pairgoth.pairing.solver.BaseSolver
fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double {
fun detRandom(max: Double, p1: Pairable, p2: Pairable, symmetric: Boolean): Double {
var inverse = false
var name1 = p1.fullName("")
var name2 = p2.fullName("")
@@ -15,7 +15,8 @@ fun detRandom(max: Double, p1: Pairable, p2: Pairable): Double {
c.code.toDouble() * (i + 1)
}.sum() * 1234567 % (max + 1)
// we want the symmetry, except when explicitly asked for a legacy asymmetric detRandom, for tests
if (inverse && BaseSolver.asymmetricDetRandom) {
// if (inverse && BaseSolver.asymmetricDetRandom) {
if (inverse && !symmetric) {
nR = max - nR
}
return nR

View File

@@ -210,7 +210,7 @@ sealed class BaseSolver(
}
open fun BaseCritParams.applyRandom(p1: Pairable, p2: Pairable): Double {
val score = if (deterministic) detRandom(random, p1, p2)
val score = if (deterministic) detRandom(random, p1, p2, true)
else nonDetRandom(random)
return score
}
@@ -404,9 +404,9 @@ sealed class BaseSolver(
val rand =
if (asymmetricDetRandom && p1.fullName() > p2.fullName()) {
// for old tests to pass
detRandom(randRange, p2, p1)
detRandom(randRange, p2, p1, false)
} else {
detRandom(randRange, p1, p2)
detRandom(randRange, p1, p2, true)
}
maxSeedingWeight - rand
} else {
@@ -546,7 +546,7 @@ sealed class BaseSolver(
} else if (p1.colorBalance < p2.colorBalance) {
score = 1.0
} else { // choose color from a det random
if (detRandom(1.0, p1, p2) === 0.0) {
if (detRandom(1.0, p1, p2, false) === 0.0) {
score = 1.0
} else {
score = -1.0