Correct pairingSort function
This commit is contained in:
@@ -79,7 +79,7 @@ sealed class Solver(
|
|||||||
val criterionP = p.eval(criterion)
|
val criterionP = p.eval(criterion)
|
||||||
val criterionQ = q.eval(criterion)
|
val criterionQ = q.eval(criterion)
|
||||||
if (criterionP != criterionQ) {
|
if (criterionP != criterionQ) {
|
||||||
return (criterionP * 100 - criterionQ * 100).toInt()
|
return (criterionQ * 100 - criterionP * 100).toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
@@ -89,7 +89,7 @@ sealed class Solver(
|
|||||||
val criterionP = p.eval(criterion)
|
val criterionP = p.eval(criterion)
|
||||||
val criterionQ = q.eval(criterion)
|
val criterionQ = q.eval(criterion)
|
||||||
if (criterionP != criterionQ) {
|
if (criterionP != criterionQ) {
|
||||||
return (criterionP * 100 - criterionQ * 100).toInt()
|
return (criterionQ * 1e6 - criterionP * 1e6).toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p.rating == q.rating) {
|
if (p.rating == q.rating) {
|
||||||
@@ -174,14 +174,11 @@ sealed class Solver(
|
|||||||
val matching = KolmogorovWeightedPerfectMatching(graph, ObjectiveSense.MAXIMIZE)
|
val matching = KolmogorovWeightedPerfectMatching(graph, ObjectiveSense.MAXIMIZE)
|
||||||
val solution = matching.matching
|
val solution = matching.matching
|
||||||
|
|
||||||
fun gamesSort(p1:Pairable, p2:Pairable) = 0.5*(p1.place + p2.place)
|
val sorted = solution.map{
|
||||||
|
|
||||||
var sorted = solution.map{
|
|
||||||
listOf(graph.getEdgeSource(it), graph.getEdgeTarget(it))
|
listOf(graph.getEdgeSource(it), graph.getEdgeTarget(it))
|
||||||
}.sortedBy { gamesSort(it[0],it[1])}
|
}.sortedWith(compareBy({ 0.5*(it[0].place + it[1].place) }, { min(it[0].place, it[1].place) }))
|
||||||
|
|
||||||
|
val result = sorted.flatMap { games(white = it[0], black = it[1]) }
|
||||||
var result = sorted.flatMap { games(white = it[0], black = it[1]) }
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@@ -237,11 +237,12 @@ class BasicTests: TestBase() {
|
|||||||
costs.add(parts[1].toDouble())
|
costs.add(parts[1].toDouble())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tmp_pair = if (name1 > name2) Pair(name1,name2) else Pair(name2,name1)
|
||||||
// Add to map
|
// Add to map
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
map1[Pair(name1, name2)] = costs
|
map1[tmp_pair] = costs
|
||||||
} else {
|
} else {
|
||||||
map2[Pair(name1, name2)] = costs
|
map2[tmp_pair] = costs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
count += 1
|
count += 1
|
||||||
@@ -253,9 +254,10 @@ class BasicTests: TestBase() {
|
|||||||
// Check if key exists in both
|
// Check if key exists in both
|
||||||
if (map2.containsKey(key)) {
|
if (map2.containsKey(key)) {
|
||||||
// Compare values
|
// Compare values
|
||||||
|
//logger.info("Comparing $key")
|
||||||
if (value != map2[key] && diff_found==false) {
|
if (value != map2[key] && diff_found==false) {
|
||||||
// Key exists but values differ - print key
|
// Key exists but values differ - print key
|
||||||
logger.info("Difference found at $key")
|
logger.info("Difference found at $key : $value")
|
||||||
logger.info("baseDuplicateGameCost = "+value!![0].toString()+" "+map2[key]!![0].toString())
|
logger.info("baseDuplicateGameCost = "+value!![0].toString()+" "+map2[key]!![0].toString())
|
||||||
logger.info("baseRandomCost = "+value!![1].toString()+" "+map2[key]!![1].toString())
|
logger.info("baseRandomCost = "+value!![1].toString()+" "+map2[key]!![1].toString())
|
||||||
logger.info("baseBWBalanceCost = "+value!![2].toString()+" "+map2[key]!![2].toString())
|
logger.info("baseBWBalanceCost = "+value!![2].toString()+" "+map2[key]!![2].toString())
|
||||||
@@ -318,7 +320,7 @@ class BasicTests: TestBase() {
|
|||||||
val players_np = TestAPI.get("/api/tour/$id_np/part").asArray()
|
val players_np = TestAPI.get("/api/tour/$id_np/part").asArray()
|
||||||
logger.info(players_np.toString().slice(0..50) + "...")
|
logger.info(players_np.toString().slice(0..50) + "...")
|
||||||
var games_np = TestAPI.post("/api/tour/$id_np/pair/1", Json.Array("all")).asArray()
|
var games_np = TestAPI.post("/api/tour/$id_np/pair/1", Json.Array("all")).asArray()
|
||||||
// logger.info("games for round 1: {}", games_np.toString())
|
logger.info("games for round 1: {}", games_np.toString())
|
||||||
|
|
||||||
// logger.info("Compare weights with itself")
|
// logger.info("Compare weights with itself")
|
||||||
assertTrue(compare_weights("weights.txt", "weights.txt"), "Weights not equal to itselft")
|
assertTrue(compare_weights("weights.txt", "weights.txt"), "Weights not equal to itselft")
|
||||||
|
Reference in New Issue
Block a user