Skip to content
Snippets Groups Projects
Commit eb0387c7 authored by Marcel Samir Becker's avatar Marcel Samir Becker
Browse files

Search metric differentiation outsourced to SearchStrategy

parent d798ba38
Branches
Tags
1 merge request!215Redesign Strategy, Load, and Resources data types
...@@ -71,6 +71,9 @@ class BenchmarkExecutorImpl( ...@@ -71,6 +71,9 @@ class BenchmarkExecutorImpl(
} }
result = (false !in experimentResults) 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) this.results.setResult(Pair(load, resource), result)
} }
......
...@@ -120,21 +120,7 @@ class TheodoliteExecutor( ...@@ -120,21 +120,7 @@ class TheodoliteExecutor(
//execute benchmarks for each load for the demand metric, or for each resource amount for capacity metric //execute benchmarks for each load for the demand metric, or for each resource amount for capacity metric
try { try {
if (config.metric == "demand") { config.searchStrategy.findSuitableCapacity(config.loads, config.resources, config.metric)
//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)
}
}
}
} finally { } finally {
ioHandler.writeToJSONFile( ioHandler.writeToJSONFile(
......
...@@ -12,8 +12,8 @@ class LowerBoundRestriction(results: Results) : RestrictionStrategy(results) { ...@@ -12,8 +12,8 @@ class LowerBoundRestriction(results: Results) : RestrictionStrategy(results) {
override fun apply(load: Int, resources: List<Int>): List<Int> { override fun apply(load: Int, resources: List<Int>): List<Int> {
val maxLoad: Int? = this.results.getMaxBenchmarkedLoad(load) val maxLoad: Int? = this.results.getMaxBenchmarkedLoad(load)
var lowerBound: Int? = this.results.getMinRequiredInstances(maxLoad) var lowerBound: Int = this.results.getMinRequiredInstances(maxLoad)
if (lowerBound == null) { if (lowerBound == Int.MIN_VALUE || lowerBound == Int.MAX_VALUE) {
lowerBound = resources[0] lowerBound = resources[0]
} }
return resources.filter { x -> x >= lowerBound } return resources.filter { x -> x >= lowerBound }
......
...@@ -14,7 +14,7 @@ abstract class RestrictionStrategy(val results: Results) { ...@@ -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. * 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. * @param resources List of Resource s to be restricted.
* @return Returns a list containing only elements that have not been filtered out by the * @return Returns a list containing only elements that have not been filtered out by the
* restriction (possibly empty). * restriction (possibly empty).
......
...@@ -20,8 +20,6 @@ class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm ...@@ -20,8 +20,6 @@ class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm
return null 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? { override fun findSuitableLoad(resource: Int, loads: List<Int>): Int? {
var maxSuitableLoad: Int? = null var maxSuitableLoad: Int? = null
for (load in loads) { for (load in loads) {
......
...@@ -26,9 +26,10 @@ class RestrictionSearch( ...@@ -26,9 +26,10 @@ class RestrictionSearch(
return this.searchStrategy.findSuitableResource(load, restrictedResources) 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? { 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? var restrictedLoads = loads
TODO("Not yet implemented") for (strategy in this.restrictionStrategies) {
restrictedLoads = restrictedLoads.intersect(strategy.apply(resource, loads).toSet()).toList()
}
} }
} }
\ No newline at end of file
...@@ -14,6 +14,27 @@ import theodolite.util.Results ...@@ -14,6 +14,27 @@ import theodolite.util.Results
@RegisterForReflection @RegisterForReflection
abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val guessStrategy: GuessStrategy? = null, abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val guessStrategy: GuessStrategy? = null,
val results: Results? = 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. * Find smallest suitable resource from the specified resource list for the given load.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment