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
No related branches found
No related tags found
1 merge request!215Redesign Strategy, Load, and Resources data types
This commit is part of merge request !215. Comments created here will be created in the context of that merge request.
......@@ -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)
}
......
......@@ -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(
......
......@@ -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 }
......
......@@ -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).
......
......@@ -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) {
......
......@@ -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
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment