diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index 389c3b9167eab7c0d56c18af113f1edcefecac8f..b98f8c438e9c46aeec4ed699b25cb989533b8334 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -48,7 +48,7 @@ class TheodoliteExecutor() { // execute benchmarks for each load for(load in config.loads) { - config.compositeStrategy.findSuitableResources(load, config.resources) + config.compositeStrategy.findSuitableResource(load, config.resources) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt index 1aaab229cc30ee3fe7972b71088a933af109c6e0..49cec7416ac9d366dbf35ec225b49d17d54b1043 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt @@ -7,7 +7,7 @@ import theodolite.util.Results import java.lang.IllegalArgumentException class BinarySearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : SearchStrategy(benchmarkExecutor, results) { - override fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource? { + override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { val result = search(load, resources, 0, resources.size - 1) if( result == -1 ) { return null; @@ -19,6 +19,7 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : Sea if (lower > upper) { throw IllegalArgumentException() } + // special case: length == 1 or 2 if (lower == upper ) { if (this.benchmarkExecutor.runExperiment(load, resources[lower])) return lower else { @@ -26,6 +27,7 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : Sea return lower + 1 } } else { + // 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) / 2 if (this.benchmarkExecutor.runExperiment(load, resources[mid])) { if (mid == lower) { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt index ed8750083881f72a091c0acd923ef7c46ff79db7..20033a1d5084921f7d033dd3f5cb7cca6409c90c 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt @@ -8,11 +8,11 @@ import theodolite.util.Results class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, val searchStrategy: SearchStrategy, val restrictionStrategies: Set<RestrictionStrategy>, results: Results) : SearchStrategy(benchmarkExecutor, results) { - override fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource? { + override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { var restrictedResources = resources.toList() for (strategy in this.restrictionStrategies) { restrictedResources = restrictedResources.intersect(strategy.next(load, resources)).toList() } - return this.searchStrategy.findSuitableResources(load, restrictedResources) + return this.searchStrategy.findSuitableResource(load, restrictedResources) } } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt index 37fa4ca41678c285bb4fb6a86633dedecb78ba03..abbedf3c0acc1e1de4afc59b7a9c526a05928783 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -7,7 +7,7 @@ import theodolite.util.Results class LinearSearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : SearchStrategy(benchmarkExecutor, results) { - override fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource? { + override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { for (res in resources) { if (this.benchmarkExecutor.runExperiment(load, res)) return res } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt index 7e151ef6f3cfaf16a48c43f7369bbfc8041e9295..2b0143c52ecbfc6fc140841d3e0166b13a87a44d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -6,5 +6,5 @@ import theodolite.util.Resource import theodolite.util.Results abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val results: Results) { - abstract fun findSuitableResources(load: LoadDimension, resources: List<Resource>): Resource?; + abstract fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource?; } \ No newline at end of file diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt index 0f9b1b850b9963aa9e9851f963e4f02abcf09924..a9961d69bc22b8321577f1c7bb9bc37965f67360 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt @@ -40,7 +40,7 @@ class CompositeStrategyTest { expected.add(null) for(load in mockLoads) { - actual.add(strategy.findSuitableResources(load, mockResources)) + actual.add(strategy.findSuitableResource(load, mockResources)) } assertEquals(actual, expected) @@ -71,7 +71,7 @@ class CompositeStrategyTest { expected.add(null) for(load in mockLoads) { - actual.add(strategy.findSuitableResources(load, mockResources)) + actual.add(strategy.findSuitableResource(load, mockResources)) } assertEquals(actual, expected) @@ -101,7 +101,7 @@ class CompositeStrategyTest { val expected: ArrayList<Resource?> = ArrayList(listOf(0,2,2,3,4,6,7).map{ x -> Resource(x)}) for(load in mockLoads) { - actual.add(strategy.findSuitableResources(load, mockResources)) + actual.add(strategy.findSuitableResource(load, mockResources)) } assertEquals(actual, expected)