Permalink
Browse files

[#126] Add custom metrics for DSE

Renamed AbstractMetric --> AbstractMappingMetric to differ from
DSEMetric

Task-Url: http://github.com/roberthilbrich/assist-public/issues/126
  • Loading branch information...
RobertHilbrich committed Jul 12, 2018
1 parent 4e83231 commit 6f50154ed61f7daf373913c5dd813b344f68361f
Showing with 460 additions and 236 deletions.
  1. +7 −7 ch.hilbri.assist.cli/src/ch/hilbri/assist/cli/Runner.java
  2. +3 −3 ch.hilbri.assist.dse/src/ch/hilbri/assist/dse/evaluation/Evaluation.xtend
  3. +2 −2 ch.hilbri.assist.dse/src/ch/hilbri/assist/dse/evaluation/GuiEvaluationJob.xtend
  4. +5 −5 ...ri.assist.dse/src/ch/hilbri/assist/dse/ui/evaluatesettings/EvaluateDesignSpaceSettingsDialog.java
  5. +3 −3 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/analysis/ResultsAnalysis.java
  6. +2 −2 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/analysis/metrics/builtin/MaxFreeCapacity.xtend
  7. +2 −2 ...sist.mapping/src/ch/hilbri/assist/mapping/analysis/metrics/builtin/MinOrganizationsPerBoard.xtend
  8. +2 −2 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/analysis/metrics/builtin/RandomScore.java
  9. +2 −2 ...t.mapping/src/ch/hilbri/assist/mapping/analysis/metrics/builtin/UniformCoreLoadDistribution.xtend
  10. +15 −15 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/ui/multipageeditor/DetailedResults.java
  11. +3 −3 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/ui/multipageeditor/EvaluateJob.java
  12. +4 −4 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/ui/multipageeditor/MetricScoresTuple.java
  13. +2 −2 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/ui/multipageeditor/MetricScoresTupleList.xtend
  14. +3 −3 ...assist.mapping/src/ch/hilbri/assist/mapping/ui/multipageeditor/MetricTableEntryLabelProvider.java
  15. +2 −2 ch.hilbri.assist.mapping/src/ch/hilbri/assist/mapping/ui/wizards/NewMetricWizard.xtend
  16. +5 −0 ch.hilbri.assist.model.edit/plugin.properties
  17. +219 −0 ...lbri.assist.model.edit/src/ch/hilbri/assist/model/provider/AbstractMappingMetricItemProvider.java
  18. +12 −12 ch.hilbri.assist.model.edit/src/ch/hilbri/assist/model/provider/AbstractMetricItemProvider.java
  19. +2 −2 ch.hilbri.assist.model/model/ASSIST-Model.xcore
  20. +16 −16 ...ri.assist.model/src-gen/ch/hilbri/assist/model/{AbstractMetric.java → AbstractMappingMetric.java}
  21. +6 −6 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/MappingResult.java
  22. +46 −46 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/ModelPackage.java
  23. +31 −31 ...el/src-gen/ch/hilbri/assist/model/impl/{AbstractMetricImpl.java → AbstractMappingMetricImpl.java}
  24. +7 −7 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/impl/MappingResultImpl.java
  25. +14 −14 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/impl/MetricScorePairImpl.java
  26. +2 −2 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/impl/ModelFactoryImpl.java
  27. +27 −27 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/impl/ModelPackageImpl.java
  28. +7 −7 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/util/ModelAdapterFactory.java
  29. +9 −9 ch.hilbri.assist.model/src-gen/ch/hilbri/assist/model/util/ModelSwitch.java
@@ -26,7 +26,7 @@
import ch.hilbri.assist.mapping.solver.exceptions.BasicConstraintsException;
import ch.hilbri.assist.mapping.solver.strategies.ValueSelectorTypes;
import ch.hilbri.assist.mapping.solver.strategies.VariableSelectorTypes;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
import ch.hilbri.assist.model.AssistModel;
import ch.hilbri.assist.model.ModelPackage;
import ch.hilbri.assist.model.MappingResult;
@@ -107,24 +107,24 @@ public static void main(String[] args) throws Exception {
System.out.println(results.size() + " solutions found.");
if (cmd.hasOption("u")) {
List<AbstractMetric> list = new ArrayList<AbstractMetric>();
AbstractMetric metric = new UniformCoreLoadDistribution();
List<AbstractMappingMetric> list = new ArrayList<AbstractMappingMetric>();
AbstractMappingMetric metric = new UniformCoreLoadDistribution();
metric.setWeight(1);
list.add(metric);
System.out.println("Evaluating solutions according to uniform core load metric");
ResultsAnalysis.evaluate(results, list);
}
else if (cmd.hasOption("c")) {
List<AbstractMetric> list = new ArrayList<AbstractMetric>();
AbstractMetric metric = new MaxFreeCapacity();
List<AbstractMappingMetric> list = new ArrayList<AbstractMappingMetric>();
AbstractMappingMetric metric = new MaxFreeCapacity();
metric.setWeight(1);
list.add(metric);
System.out.println("Evaluating solutions according to max free capacity metric");
ResultsAnalysis.evaluate(results, list);
}
else if (cmd.hasOption("r")) {
List<AbstractMetric> list = new ArrayList<AbstractMetric>();
AbstractMetric metric = new RandomScore();
List<AbstractMappingMetric> list = new ArrayList<AbstractMappingMetric>();
AbstractMappingMetric metric = new RandomScore();
metric.setWeight(1);
list.add(metric);
System.out.println("Evaluating solutions according to random score metric");
@@ -6,7 +6,6 @@ import ch.hilbri.assist.dse.ui.handlers.EvalDesignSpace.Mode
import ch.hilbri.assist.mapping.analysis.ResultsAnalysis
import ch.hilbri.assist.mapping.solver.AssistMappingSolver
import ch.hilbri.assist.mapping.solver.exceptions.BasicConstraintsException
import ch.hilbri.assist.model.AbstractMetric
import ch.hilbri.assist.model.AssistModel
import ch.qos.logback.classic.Level
import ch.qos.logback.classic.LoggerContext
@@ -15,20 +14,21 @@ import org.eclipse.emf.ecore.util.EcoreUtil
import org.eclipse.xtend.lib.annotations.Accessors
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ch.hilbri.assist.model.AbstractMappingMetric
class Evaluation {
AssistModel assistModel
Logger logger = LoggerFactory.getLogger(this.class)
@Accessors(PUBLIC_GETTER) List<ExplorationResult> explorationResults = newArrayList()
Mode mode
AbstractMetric metric
AbstractMappingMetric metric
new(AssistModel input, Mode mo) {
this(input, mo, null)
}
new(AssistModel input, Mode mo, AbstractMetric me) {
new(AssistModel input, Mode mo, AbstractMappingMetric me) {
logger.info('''************************************************''')
logger.info(''' ASSIST Design Space Exploration''')
@@ -2,21 +2,21 @@ package ch.hilbri.assist.dse.evaluation
import ch.hilbri.assist.dse.ui.handlers.EvalDesignSpace.Mode
import ch.hilbri.assist.dse.ui.multipageeditor.MultiPageEditor
import ch.hilbri.assist.model.AbstractMetric
import ch.hilbri.assist.model.AssistModel
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.Status
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.emf.common.util.URI
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl
import org.eclipse.swt.widgets.Display
import ch.hilbri.assist.model.AbstractMappingMetric
class GuiEvaluationJob extends Job {
MultiPageEditor multiPageEditor
Evaluation evaluation // private Logger logger = LoggerFactory.getLogger(GuiEvaluationJob)
new(String name, URI modelURI, MultiPageEditor editor, Mode mode, AbstractMetric metric) {
new(String name, URI modelURI, MultiPageEditor editor, Mode mode, AbstractMappingMetric metric) {
super(name);
/* Who is asking to get the results back? */
@@ -20,17 +20,17 @@
import ch.hilbri.assist.dse.ui.handlers.EvalDesignSpace.Mode;
import ch.hilbri.assist.mapping.analysis.metrics.builtin.RandomScore;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
public class EvaluateDesignSpaceSettingsDialog extends TitleAreaDialog {
private Label lblSelectMetric;
private Combo cbxSelectMetric;
private Button btnFeasibilityCheckOnly;
private Button btnFeasibilityAndScoring;
private List<AbstractMetric> availableMetrics = new ArrayList<AbstractMetric>();
private List<AbstractMappingMetric> availableMetrics = new ArrayList<AbstractMappingMetric>();
private Mode currentMode = Mode.FEASIBILITY_ONLY;
private AbstractMetric currentMetric;
private AbstractMappingMetric currentMetric;
public EvaluateDesignSpaceSettingsDialog(Shell parentShell) {
@@ -82,7 +82,7 @@ public void widgetSelected(SelectionEvent e) {
currentMode = Mode.FEASIBILITY_AND_SCORING;
lblSelectMetric.setEnabled(true);
cbxSelectMetric.setEnabled(true);
for (AbstractMetric metric : availableMetrics) {
for (AbstractMappingMetric metric : availableMetrics) {
cbxSelectMetric.add(metric.getName());
}
cbxSelectMetric.select(0);
@@ -120,7 +120,7 @@ public Mode getMode() {
return currentMode;
}
public AbstractMetric getScoringMetric() {
public AbstractMappingMetric getScoringMetric() {
return currentMetric;
}
}
@@ -4,12 +4,12 @@
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
import ch.hilbri.assist.model.MappingResult;
public class ResultsAnalysis {
public static void evaluate(List<MappingResult> results, List<AbstractMetric> metrics) {
public static void evaluate(List<MappingResult> results, List<AbstractMappingMetric> metrics) {
// Delete results from previous evaluations
for (MappingResult result : results) {
@@ -18,7 +18,7 @@ public static void evaluate(List<MappingResult> results, List<AbstractMetric> me
}
// Execute each metric for the results and store the results
for (AbstractMetric metric : metrics) {
for (AbstractMappingMetric metric : metrics) {
DescriptiveStatistics statistics = new DescriptiveStatistics();
/* 1) Calculate the absolute score for each result */
@@ -1,9 +1,9 @@
package ch.hilbri.assist.mapping.analysis.metrics.builtin
import ch.hilbri.assist.model.impl.AbstractMetricImpl
import ch.hilbri.assist.model.MappingResult
import ch.hilbri.assist.model.impl.AbstractMappingMetricImpl
class MaxFreeCapacity extends AbstractMetricImpl {
class MaxFreeCapacity extends AbstractMappingMetricImpl {
new() {
setName("Max free Core Capacity")
setBuiltIn(true)
@@ -1,10 +1,10 @@
package ch.hilbri.assist.mapping.analysis.metrics.builtin
import ch.hilbri.assist.model.Application
import ch.hilbri.assist.model.impl.AbstractMetricImpl
import ch.hilbri.assist.model.MappingResult
import ch.hilbri.assist.model.impl.AbstractMappingMetricImpl
class MinOrganizationsPerBoard extends AbstractMetricImpl {
class MinOrganizationsPerBoard extends AbstractMappingMetricImpl {
new() {
setName("MinOrganizationsPerBoard")
setBuiltIn(true)
@@ -2,9 +2,9 @@
import java.util.Random;
import ch.hilbri.assist.model.MappingResult;
import ch.hilbri.assist.model.impl.AbstractMetricImpl;
import ch.hilbri.assist.model.impl.AbstractMappingMetricImpl;
public class RandomScore extends AbstractMetricImpl {
public class RandomScore extends AbstractMappingMetricImpl {
public RandomScore() {
setName("Random Score");
@@ -1,10 +1,10 @@
package ch.hilbri.assist.mapping.analysis.metrics.builtin
import ch.hilbri.assist.model.impl.AbstractMetricImpl
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics
import ch.hilbri.assist.model.MappingResult
import ch.hilbri.assist.model.impl.AbstractMappingMetricImpl
class UniformCoreLoadDistribution extends AbstractMetricImpl {
class UniformCoreLoadDistribution extends AbstractMappingMetricImpl {
new() {
setName("UniformLoadDistribution")
setBuiltIn(true)
@@ -82,18 +82,18 @@
import ch.hilbri.assist.mapping.ui.multipageeditor.actions.GotoSpecificSolution;
import ch.hilbri.assist.mapping.ui.multipageeditor.actions.SortSolutionsByName;
import ch.hilbri.assist.mapping.ui.multipageeditor.actions.SortSolutionsByScore;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
import ch.hilbri.assist.model.MappingResult;
import ch.hilbri.assist.model.SingleMappingElement;
import ch.hilbri.assist.model.impl.AbstractMetricImpl;
import ch.hilbri.assist.model.impl.AbstractMappingMetricImpl;
public class DetailedResults extends Composite {
/* Major data elements */
private int curResultIndex = -1;
private MappingResult curResult = null;
private List<MappingResult> mappingResults;
private List<AbstractMetric> selectedMetricsList = new ArrayList<AbstractMetric>();
private List<AbstractMetric> availableMetricsList = new ArrayList<AbstractMetric>();
private List<AbstractMappingMetric> selectedMetricsList = new ArrayList<AbstractMappingMetric>();
private List<AbstractMappingMetric> availableMetricsList = new ArrayList<AbstractMappingMetric>();
/* Declaring all relevant UI elements */
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
@@ -298,8 +298,8 @@ else if (curResultIndex == mappingResults.size() - 1) {
gotoLastSolutionAction.setEnabled(true);
}
EMap<AbstractMetric, Double> absScores = curResult.getMetricAbsoluteScoresMap();
EMap<AbstractMetric, Double> scaledScores = curResult.getMetricScaledScoresMap();
EMap<AbstractMappingMetric, Double> absScores = curResult.getMetricAbsoluteScoresMap();
EMap<AbstractMappingMetric, Double> scaledScores = curResult.getMetricScaledScoresMap();
tblViewerResultMetrics.setInput(new MetricScoresTupleList(absScores, scaledScores));
}
@@ -721,12 +721,12 @@ public void widgetSelected(SelectionEvent event) {
// Create a new metrics instance
// we need to do this since we do not know the specific
// class of the abstract metric could be custom!
Class<? extends AbstractMetric> metricClass = availableMetricsList.get(selectedMetricIndex).getClass();
Class<? extends AbstractMappingMetric> metricClass = availableMetricsList.get(selectedMetricIndex).getClass();
Constructor<?> metricClassConstructor = metricClass.getConstructors()[0];
try {
// Create a new instance
AbstractMetric newMetricObject = (AbstractMetric) metricClassConstructor.newInstance();
AbstractMappingMetric newMetricObject = (AbstractMappingMetric) metricClassConstructor.newInstance();
newMetricObject.setWeight(selectedWeight);
// Add new entry to data
@@ -793,7 +793,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
public void widgetSelected(SelectionEvent e) {
// This will hold our new metrics
List<AbstractMetric> newCustomMetrics = new ArrayList<AbstractMetric>();
List<AbstractMappingMetric> newCustomMetrics = new ArrayList<AbstractMappingMetric>();
// Determine the location where we have to look for new metrics
MultiPageEditor currentEditor = (MultiPageEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
@@ -822,8 +822,8 @@ public void widgetSelected(SelectionEvent e) {
return;
// Clear old custom metrics in the currentModel
List<AbstractMetric> removalList = new ArrayList<AbstractMetric>();
for (AbstractMetric m : availableMetricsList)
List<AbstractMappingMetric> removalList = new ArrayList<AbstractMappingMetric>();
for (AbstractMappingMetric m : availableMetricsList)
if (!m.isBuiltIn())
removalList.add(m);
availableMetricsList.removeAll(removalList);
@@ -839,13 +839,13 @@ public void widgetSelected(SelectionEvent e) {
String className = (String) obj;
// Get the new class
Class<? extends AbstractMetricImpl> metricClass = Class
Class<? extends AbstractMappingMetricImpl> metricClass = Class
.forName("metrics.mapping." + className, true, classLoader)
.asSubclass(AbstractMetricImpl.class);
.asSubclass(AbstractMappingMetricImpl.class);
classLoader.close();
// Create a new instance of this metric
AbstractMetric metric = metricClass.getDeclaredConstructor().newInstance();
AbstractMappingMetric metric = metricClass.getDeclaredConstructor().newInstance();
// Add the newly created metric to the temporary list of
// found metrics
@@ -1038,7 +1038,7 @@ private void fillAvailableMetricsCbx() {
cbxAvailableMetrics.setItems(newItems);
}
public void removeSelectedMetric(AbstractMetric entry) {
public void removeSelectedMetric(AbstractMappingMetric entry) {
// Remove the entry (and the delete button)
selectedMetricsList.remove(entry);
@@ -7,16 +7,16 @@
import org.eclipse.swt.widgets.Display;
import ch.hilbri.assist.mapping.analysis.ResultsAnalysis;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
import ch.hilbri.assist.model.MappingResult;
public class EvaluateJob implements IRunnableWithProgress {
private List<MappingResult> allResults;
private List<AbstractMetric> selectedMetrics;
private List<AbstractMappingMetric> selectedMetrics;
private DetailedResults resultsView;
public EvaluateJob(DetailedResults v, List<AbstractMetric> metrics) {
public EvaluateJob(DetailedResults v, List<AbstractMappingMetric> metrics) {
this.allResults = v.getMappingResults();
this.selectedMetrics = metrics;
this.resultsView = v;
@@ -1,6 +1,6 @@
package ch.hilbri.assist.mapping.ui.multipageeditor;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
/**
* This class represents a single entry in the list of metrics that
@@ -10,17 +10,17 @@
*
*/
public class MetricScoresTuple {
private AbstractMetric metric;
private AbstractMappingMetric metric;
private Double absoluteScore;
private Double scaledScore;
public MetricScoresTuple(AbstractMetric m, Double a, Double s) {
public MetricScoresTuple(AbstractMappingMetric m, Double a, Double s) {
metric = m;
absoluteScore = a;
scaledScore = s;
}
public AbstractMetric getMetric() {
public AbstractMappingMetric getMetric() {
return metric;
}
@@ -1,12 +1,12 @@
package ch.hilbri.assist.mapping.ui.multipageeditor
import ch.hilbri.assist.model.AbstractMetric
import java.util.ArrayList
import org.eclipse.emf.common.util.EMap
import ch.hilbri.assist.model.AbstractMappingMetric
class MetricScoresTupleList extends ArrayList<MetricScoresTuple> {
new(EMap<AbstractMetric, Double> absoluteScoresMap, EMap<AbstractMetric, Double> scaledScoresMap) {
new(EMap<AbstractMappingMetric, Double> absoluteScoresMap, EMap<AbstractMappingMetric, Double> scaledScoresMap) {
for (m : absoluteScoresMap.keySet)
add(new MetricScoresTuple(m, absoluteScoresMap.get(m), scaledScoresMap.get(m)))
}
@@ -16,7 +16,7 @@
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.wb.swt.ResourceManager;
import ch.hilbri.assist.model.AbstractMetric;
import ch.hilbri.assist.model.AbstractMappingMetric;
public class MetricTableEntryLabelProvider extends CellLabelProvider {
@@ -38,7 +38,7 @@ public MetricTableEntryLabelProvider(Table tblSelectedMetrics, DetailedResults m
@Override
public void update(final ViewerCell cell) {
final AbstractMetric metricTableEntry = (AbstractMetric) cell.getElement();
final AbstractMappingMetric metricTableEntry = (AbstractMappingMetric) cell.getElement();
switch (cell.getColumnIndex()) {
@@ -104,7 +104,7 @@ public void widgetDefaultSelected(SelectionEvent e) {
}
}
public void clearButton(AbstractMetric metric) {
public void clearButton(AbstractMappingMetric metric) {
Button btn = (Button) allRemoveButtons.get(metric);
if (btn != null)
btn.dispose();
Oops, something went wrong.

0 comments on commit 6f50154

Please sign in to comment.