diff --git a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index 733e3ea61396eba34febc92d96b5a868dd84cb7f..f463ce4521a8849bde9c968c6e4339fe790f8b20 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -71,6 +71,9 @@ class BenchmarkExecutorImpl( } result = (false !in experimentResults) + // differentiate metric here on first/second ele pairs, also wenn demand so und wenn capacity dann mit (resource,load) + // so könnten wir die Methoden in Results so lassen und müssten keine Dopplung einbauen + // wird alles sehr undurchsichtig damit wenn man die vertauscht, evtl mit metric zu den Results klarer machen this.results.setResult(Pair(load, resource), result) } diff --git a/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index 8664ea03460832bb966e878eb96a0678b969020f..7ab1619931c81e3f98e10af8fa3764c3451bfe88 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -120,21 +120,7 @@ class TheodoliteExecutor( //execute benchmarks for each load for the demand metric, or for each resource amount for capacity metric try { - if (config.metric == "demand") { - //demand metric - for (load in config.loads) { - if (executor.run.get()) { - config.searchStrategy.findSuitableResource(load, config.resources) - } - } - } else { - //capacity metric - for (resource in config.resources) { - if (executor.run.get()) { - config.searchStrategy.findSuitableLoad(resource, config.loads) - } - } - } + config.searchStrategy.findSuitableCapacity(config.loads, config.resources, config.metric) } finally { ioHandler.writeToJSONFile( diff --git a/theodolite/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt b/theodolite/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt index 6849d74fd5caf09077922fdefca7cabda87128a0..f4ff6c5ddfaaa98dc11b8c1d8c449927ecefe9a3 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt @@ -12,8 +12,8 @@ class LowerBoundRestriction(results: Results) : RestrictionStrategy(results) { override fun apply(load: Int, resources: List<Int>): List<Int> { val maxLoad: Int? = this.results.getMaxBenchmarkedLoad(load) - var lowerBound: Int? = this.results.getMinRequiredInstances(maxLoad) - if (lowerBound == null) { + var lowerBound: Int = this.results.getMinRequiredInstances(maxLoad) + if (lowerBound == Int.MIN_VALUE || lowerBound == Int.MAX_VALUE) { lowerBound = resources[0] } return resources.filter { x -> x >= lowerBound } diff --git a/theodolite/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt b/theodolite/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt index 963da39e9dc30955a6300f240b9d293ebe1ee15c..b402b917f41863f9d749d50a5a14d2244ce8d1be 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt @@ -14,7 +14,7 @@ abstract class RestrictionStrategy(val results: Results) { /** * Apply the restriction of the given resource list for the given load based on the results object. * - * @param load LoadDimension for which a subset of resources are required. + * @param load LoadDimension for which a subset of resources is required. * @param resources List of Resource s to be restricted. * @return Returns a list containing only elements that have not been filtered out by the * restriction (possibly empty). diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt index c4497934b91ce958b497e8749b78b5ce6f9f0620..a02505844f2d28f7266513ef333daac8c56fb1a2 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -20,8 +20,6 @@ class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm return null } - // Stops after having the first load which is not possible anymore with the current resource, maybe some later load still possible tho - // kinda like GuessSearchStrat case -> differentiate or is it fine like that? override fun findSuitableLoad(resource: Int, loads: List<Int>): Int? { var maxSuitableLoad: Int? = null for (load in loads) { diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionSearch.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionSearch.kt index 0367686c23a7cdadd8cf091bcd4126d92c508ddb..10cc4a7a2a11c135101249ef88d197e7e08bd437 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionSearch.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/RestrictionSearch.kt @@ -26,9 +26,10 @@ class RestrictionSearch( return this.searchStrategy.findSuitableResource(load, restrictedResources) } - //TODO: not sure if it makes sense but actually doing the same as for finding suitable resource with the restrictions override fun findSuitableLoad(resource: Int, loads: List<Int>): Int? { - //erste Zeile komisch, wird auch bei resource so gemacht aber warum? das ist doch ne liste warum also toList? - TODO("Not yet implemented") + var restrictedLoads = loads + for (strategy in this.restrictionStrategies) { + restrictedLoads = restrictedLoads.intersect(strategy.apply(resource, loads).toSet()).toList() + } } } \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt index 31f9deed59283698085cc31090029c7f3730492e..ff8827ce603ca299aee6ad6297d79be355777c7f 100644 --- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -14,6 +14,27 @@ import theodolite.util.Results @RegisterForReflection abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val guessStrategy: GuessStrategy? = null, val results: Results? = null) { + + + fun findSuitableCapacity(loads: List<Int>, resources: List<Int>, metric: String) { + + if (metric == "demand") { + //demand metric + for (load in loads) { + if (benchmarkExecutor.run.get()) { + this.findSuitableResource(load, resources) + } + } + } else { + //capacity metric + for (resource in resources) { + if (benchmarkExecutor.run.get()) { + this.findSuitableLoad(resource, loads) + } + } + } + } + /** * Find smallest suitable resource from the specified resource list for the given load. *