Refactor code to create weights/names map
This commit is contained in:

committed by
Claude Brisson

parent
4d311afb2c
commit
bea4c8db19
@@ -26,14 +26,8 @@ class PairingTests: TestBase() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun compare_weights(file1: File, file2: File, skipSeeding: Boolean = false):Boolean {
|
||||
BaseSolver.weightsLogger!!.flush()
|
||||
// Maps to store name pairs and costs
|
||||
val map1 = HashMap<Pair<String, String>, List<Double>>()
|
||||
val map2 = HashMap<Pair<String, String>, List<Double>>()
|
||||
var count: Int = 1
|
||||
|
||||
for (file in listOf(file1, file2)) {
|
||||
fun create_weights_map(file: File): HashMap<Pair<String, String>, List<Double>> {
|
||||
val map = HashMap<Pair<String, String>, List<Double>>()
|
||||
|
||||
// Read lines
|
||||
val lines = file.readLines()
|
||||
@@ -59,15 +53,16 @@ class PairingTests: TestBase() {
|
||||
|
||||
val tmp_pair = if (name1 > name2) Pair(name1,name2) else Pair(name2,name1)
|
||||
// Add to map
|
||||
if (count == 1) {
|
||||
map1[tmp_pair] = costs
|
||||
} else {
|
||||
map2[tmp_pair] = costs
|
||||
map[tmp_pair] = costs
|
||||
}
|
||||
return map
|
||||
}
|
||||
count += 1
|
||||
|
||||
}
|
||||
fun compare_weights(file1: File, file2: File, skipSeeding: Boolean = false):Boolean {
|
||||
BaseSolver.weightsLogger!!.flush()
|
||||
// Maps to store name pairs and costs
|
||||
val map1 = create_weights_map(file1)
|
||||
val map2 = create_weights_map(file2)
|
||||
|
||||
var identical = true
|
||||
for ((key, value) in map1) {
|
||||
@@ -141,34 +136,7 @@ class PairingTests: TestBase() {
|
||||
|
||||
fun compute_sumOfWeight_OG(file: File, opengotha: Json.Array, players: Json.Array): Double{
|
||||
// Map to store name pairs and costs
|
||||
val map = HashMap<Pair<String, String>, List<Double>>()
|
||||
|
||||
// Read lines
|
||||
val lines = file.readLines()
|
||||
|
||||
// Store headers
|
||||
val header1 = lines[0]
|
||||
val header2 = lines[1]
|
||||
|
||||
logger.info("Reading weights file "+file)
|
||||
|
||||
// Loop through sections
|
||||
for (i in 2..lines.size-1 step 12) {
|
||||
// Get name pair
|
||||
val name1 = lines[i].split("=")[1]
|
||||
val name2 = lines[i+1].split("=")[1]
|
||||
|
||||
// Nested loop over costs
|
||||
val costs = mutableListOf<Double>()
|
||||
for (j in i + 2..i + 11) {
|
||||
val parts = lines[j].split("=")
|
||||
costs.add(parts[1].toDouble())
|
||||
}
|
||||
|
||||
val tmp_pair = if (name1 > name2) Pair(name1,name2) else Pair(name2,name1)
|
||||
// Add to map
|
||||
map[tmp_pair] = costs
|
||||
}
|
||||
val map = create_weights_map(file)
|
||||
|
||||
val mapNamesID = HashMap<Int?, String>()
|
||||
for (i in 0 until players.size) {
|
||||
|
Reference in New Issue
Block a user