From 7f4ff7b3092619444dd3fb0ebbf8ad4d4e8ee503 Mon Sep 17 00:00:00 2001
From: Marcel Becker <stu117960@mail.uni-kiel.de>
Date: Tue, 8 Mar 2022 16:24:37 +0100
Subject: [PATCH] Fixed Binary Search Capacity Metric

---
 .../strategies/searchstrategy/BinarySearch.kt | 20 +++++++++----------
 .../InitialGuessSearchStrategy.kt             |  6 +++---
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt
index e2af7b26a..6e56c3b36 100644
--- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt
+++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt
@@ -42,8 +42,8 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm
         // special case:  length == 1, so lower and upper bounds are the same
         if (lower == upper) {
             val res = resources[lower]
-            logger.info { "Running experiment with load '${load}' and resources '$res'" }
-            if (this.benchmarkExecutor.runExperiment(load, resources[lower])) return lower
+            logger.info { "Running experiment with load '$load' and resource '$res'" }
+            if (this.benchmarkExecutor.runExperiment(load, res)) return lower
             else {
                 if (lower + 1 == resources.size) return -1
                 return lower + 1
@@ -53,8 +53,8 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm
             // length >= 2 and adjust upper and lower depending on the result for `resources[mid]`
             val mid = (upper + lower) / 2
             val res = resources[mid]
-            logger.info { "Running experiment with load '${load}' and resources '$res'" }
-            if (this.benchmarkExecutor.runExperiment(load, resources[mid])) {
+            logger.info { "Running experiment with load '$load' and resource '$res'" }
+            if (this.benchmarkExecutor.runExperiment(load, res)) {
                 // case length = 2
                 if (mid == lower) {
                     return lower
@@ -81,9 +81,9 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm
         }
         // length = 1, so lower and upper bounds are the same
         if (lower == upper) {
-            val res = loads[lower]
-            logger.info { "Running experiment with load '$resource' and resources '$res'" }
-            if (this.benchmarkExecutor.runExperiment(resource, loads[lower])) return lower
+            val load = loads[lower]
+            logger.info { "Running experiment with load '$load' and resource '$resource'" }
+            if (this.benchmarkExecutor.runExperiment(load, resource)) return lower
             else {
                 if (lower + 1 == loads.size) return -1
                 return lower - 1
@@ -92,9 +92,9 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm
             // apply binary search for a list with
             // length > 2 and adjust upper and lower depending on the result for `resources[mid]`
             val mid = (upper + lower + 1) / 2 //round to next int
-            val res = loads[mid]
-            logger.info { "Running experiment with load '$resource' and resources '$res'" }
-            if (this.benchmarkExecutor.runExperiment(resource, loads[mid])) {
+            val load = loads[mid]
+            logger.info { "Running experiment with load '$load' and resource '$resource'" }
+            if (this.benchmarkExecutor.runExperiment(load, resource)) {
                 // length = 2, so since we round down mid is equal to lower
                 if (mid == upper) {
                     return upper
diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
index 6b56e22a8..447d81094 100644
--- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
+++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
@@ -93,7 +93,7 @@ class InitialGuessSearchStrategy(
 
             // If the first experiment passes, starting upwards linear search
             // otherwise starting downward linear search
-            if (!this.benchmarkExecutor.runExperiment(resource, lastMaxLoad)) {
+            if (!this.benchmarkExecutor.runExperiment(lastMaxLoad, resource)) {
                 // downward search
 
                 loadsToCheck = loads.subList(0, startIndex).reversed()
@@ -101,7 +101,7 @@ class InitialGuessSearchStrategy(
                     for (load in loadsToCheck) {
 
                         logger.info { "Running experiment with resource '$resource' and load '$load'" }
-                        if (this.benchmarkExecutor.runExperiment(resource, load)) {
+                        if (this.benchmarkExecutor.runExperiment(load, resource)) {
                             return load
                         }
                     }
@@ -117,7 +117,7 @@ class InitialGuessSearchStrategy(
                 var currentMax: Int = lastMaxLoad
                 for (load in loadsToCheck) {
                     logger.info { "Running experiment with resource '$resource' and load '$load'" }
-                    if (this.benchmarkExecutor.runExperiment(resource, load)) {
+                    if (this.benchmarkExecutor.runExperiment(load, resource)) {
                         currentMax = load
                     }
                 }
-- 
GitLab