From 64a2146cc9b66d7f86e714d75de29f5a6a423cab Mon Sep 17 00:00:00 2001 From: Nikolaus Huber <nikolaus.huber@uni-wuerzburg.de> Date: Tue, 14 May 2013 11:32:43 +0000 Subject: [PATCH] git-svn-id: https://se1.informatik.uni-wuerzburg.de/usvn/svn/code/code/DMM/trunk@11546 9e42b895-fcda-4063-8a3b-11be15eb1bbd --- .../WeightedSumCalculator.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculator.java diff --git a/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculator.java b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculator.java new file mode 100644 index 00000000..9ce75b18 --- /dev/null +++ b/edu.kit.ipd.descartes.adaptation/src/edu/kit/ipd/descartes/adaptation/evaluation/weightingfunction/WeightedSumCalculator.java @@ -0,0 +1,73 @@ +package edu.kit.ipd.descartes.adaptation.evaluation.weightingfunction; + +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.EList; + +import edu.kit.ipd.descartes.adaptation.model.dmm.util.WeightingFunctionHelper; +import edu.kit.ipd.descartes.mm.adaptation.WeightedTactic; +import edu.kit.ipd.descartes.mm.adaptation.WeightingFunction; +import edu.kit.ipd.descartes.perfdatarepo.Impact; +import edu.kit.ipd.descartes.perfdatarepo.MetricValue; +import edu.kit.ipd.descartes.perfdatarepo.Result; + +public class WeightedSumCalculator implements IWeightingFunctionCalculator { + + private Logger logger = Logger.getLogger(WeightedSumCalculator.class); + private WeightingFunction weightingFunction = null; + + public WeightedSumCalculator(WeightingFunction f) { + setWeightingFunction(f); + } + + public WeightedSumCalculator() { + } + + public WeightingFunction getWeightingFunction() { + return weightingFunction; + } + + public void setWeightingFunction(WeightingFunction weightingFunction) { + this.weightingFunction = weightingFunction; + } + + @Override + public double calculateWeight(WeightedTactic weightedtactic) { + + double newWeight = 0.0; + Impact impact = weightedtactic.getLastImpact(); + Result before = impact.getBefore(); + Result after = impact.getAfter(); + EList<MetricValue> afterMetricValues = after.getMetricValues(); + + for (MetricValue afterMetricValue : afterMetricValues) { + // calculated delta=(after-before) + double afterValue = afterMetricValue.getValue(); + double beforeValue = WeightingFunctionHelper + .getValueForMetricType(afterMetricValue.getMetricType(), before); + double delta = afterValue - beforeValue; + + // get the corresponding weight + double weightOfMetric = WeightingFunctionHelper.getWeightForMetricType(weightingFunction, + afterMetricValue.getMetricType()); + + if (Double.isNaN(weightOfMetric)) + logger.info("No weight found for metric type: " + afterMetricValue.getMetricType().getName() + ", skipping..."); + else { + // add it + newWeight += weightOfMetric * delta; + logger.debug("Delta for metric type " + afterMetricValue.getMetricType().getName() + " was: " + delta + + " and weight is " + weightOfMetric); + } + } + + return newWeight; + } + + @Override + public void updateWeight(WeightedTactic weightedTactic) { + double newWeight = calculateWeight(weightedTactic); + logger.debug("Setting new weight of " + weightedTactic.getName() + " to " + newWeight); + weightedTactic.setCurrentWeight(newWeight); + } + +} -- GitLab