Commit 7d21b778 authored by Alexander Diewald's avatar Alexander Diewald

DSE-TCgen: Move the metrics calculation code

Issue-Ref: 4008
Issue-Url: https://af3-developer.fortiss.org/issues/4008Signed-off-by: Alexander Diewald's avatarAlexander Diewald <diewald@fortiss.org>
parent f8e44a4b
ArchitectureGraph.java 4f1539b6997b7a71d744ef750aa2f102097f211d YELLOW
ExplorationTestCaseGenerator.java 750ca96bf8e481c7d9a2303f8da609ffb914f6f2 RED
ExplorationTestCaseGenerator.java 583c4679996e0c8c277c23da4f5285dea849b650 RED
......@@ -19,7 +19,7 @@ import static org.fortiss.af3.exploration.testgenerator.util.AnnotationGeneratio
import static org.fortiss.af3.exploration.testgenerator.util.CompArchGeneratonUtil.generateLogicalArchitectures;
import static org.fortiss.af3.exploration.testgenerator.util.DseUtils.expandByDseProblems;
import static org.fortiss.af3.exploration.testgenerator.util.FileWriterUtil.write;
import static org.fortiss.af3.exploration.testgenerator.util.GraphUtil.getGraphMetrics;
import static org.fortiss.af3.exploration.testgenerator.util.GraphMetricUtils.getGraphMetrics;
import static org.fortiss.af3.exploration.testgenerator.util.ProjectUtils.createAF3Projects;
import static org.fortiss.af3.exploration.testgenerator.util.ProjectUtils.saveFileProjects;
import static org.fortiss.af3.exploration.util.ExplorationUtils.isDumpTestgenGraphmetricsEnabled;
......
AnnotationGenerationUtils.java 7fdab0a64ce72636bc59262b889b62eed54980ee YELLOW
CompArchGeneratonUtil.java 8d02b63410de3c790672c49699559245a8a306ef RED
CompArchGeneratonUtil.java d8c6db8002cc003f3681d6afd5fff3742c5fa437 RED
DseUtils.java d81af0b7f649d2453aada362fc50572fce31ebc8 YELLOW
FileWriterUtil.java 4a95559f571d41fa44e6236fc055ab5baac7c384 YELLOW
GraphGenerationUtilities.java 3be2143bf23befd2c9103c621ce31accf65b7cc6 YELLOW
GraphMetricUtils.java ce15ba42b7bd36ad2ae46ebd084911e69c815a5f YELLOW
GraphUtil.java afaec2934ff3038bdcf9d10f7b75c71f0dd2e036 YELLOW
GraphMetricUtils.java 99a398d4ff9b15b3eeb35748e32aa34a9b197f07 YELLOW
GraphUtils.java d11a2a067b343a2639f495c3417328f268f57127 YELLOW
ProjectUtils.java fe0009a32f6aaa58fb3330e2b9e383e217afc0dd YELLOW
......@@ -22,7 +22,7 @@ import static java.lang.Math.max;
import static java.lang.Math.pow;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createComponent;
import static org.fortiss.af3.exploration.testgenerator.util.GraphGenerationUtilities.generateRandomGraph;
import static org.fortiss.af3.exploration.testgenerator.util.GraphUtil.getComponentArchitecture;
import static org.fortiss.af3.exploration.testgenerator.util.GraphUtils.getComponentArchitecture;
import static org.fortiss.tooling.base.utils.AnnotationUtils.instantiateAnnotationsRecursive;
import java.io.IOException;
......
......@@ -2,17 +2,24 @@ package org.fortiss.af3.exploration.testgenerator.util;
import static java.util.stream.Collectors.toList;
import static org.conqat.lib.commons.math.MathUtils.max;
import static org.fortiss.af3.exploration.testgenerator.util.GraphUtils.getGraph;
import static org.jgrapht.Graphs.neighborListOf;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.OptionalInt;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.exploration.testgenerator.ArchitectureGraph;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.jgrapht.alg.cycle.DirectedSimpleCycles;
import org.jgrapht.alg.cycle.SzwarcfiterLauerSimpleCycles;
import org.jgrapht.alg.scoring.BetweennessCentrality;
import org.jgrapht.alg.scoring.ClusteringCoefficient;
import org.jgrapht.alg.shortestpath.GraphMeasurer;
import org.jgrapht.graph.DefaultWeightedEdge;
/**
......@@ -22,10 +29,37 @@ import org.jgrapht.graph.DefaultWeightedEdge;
*/
public class GraphMetricUtils {
/**
* Calculates a variety of graph metrics for a given logical architecture.
*
* @param componentArchitecture
* Logical architecture to calculates metrics of
* @return A map containing the values of each graph metric
*/
public static Map<String, Double> getGraphMetrics(ComponentArchitecture componentArchitecture) {
Map<String, Double> graphMetrics = new HashMap<String, Double>();
ArchitectureGraph<Component> graph = getGraph(componentArchitecture);
GraphMeasurer<Component, DefaultWeightedEdge> measurer = new GraphMeasurer<>(graph);
ClusteringCoefficient<Component, DefaultWeightedEdge> clusterCoeff =
new ClusteringCoefficient<>(graph);
graphMetrics.put("average_degree", getAverageDegree(graph));
graphMetrics.put("clustering_coefficient", clusterCoeff.getAverageClusteringCoefficient());
graphMetrics.put("central_point_dominance", getCentralPointDominance(graph));
graphMetrics.put("diameter", measurer.getDiameter());
graphMetrics.put("radius", measurer.getRadius());
graphMetrics.put("nr_edges", (double)graph.edgeSet().size());
graphMetrics.put("nr_vertices", (double)graph.vertexSet().size());
graphMetrics.put("cyclic_coefficient", getCyclicCoefficient(graph));
return graphMetrics;
}
/**
* Returns the dominance factor of the central point(s) of the given {@link ArchitectureGraph}.
*/
public static double getCentralPointDominance(ArchitectureGraph<?> graph) {
private static double getCentralPointDominance(ArchitectureGraph<?> graph) {
Collection<Double> betweeness =
(new BetweennessCentrality<>(graph, true)).getScores().values();
Double maxBetweeness = max(betweeness);
......@@ -36,7 +70,7 @@ public class GraphMetricUtils {
* Returns the average degree of the given {@link ArchitectureGraph}, i.e. the averaged value of
* the degrees of all of its vertices.
*/
public static double getAverageDegree(ArchitectureGraph<?> graph) {
private static double getAverageDegree(ArchitectureGraph<?> graph) {
return ((double)graph.edgeSet().size()) / ((double)graph.vertexSet().size());
}
......
......@@ -3,13 +3,8 @@ package org.fortiss.af3.exploration.testgenerator.util;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createChannelAndAttach;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createInputPort;
import static org.fortiss.af3.component.utils.ComponentModelElementFactory.createOutputPort;
import static org.fortiss.af3.exploration.testgenerator.util.GraphMetricUtils.getAverageDegree;
import static org.fortiss.af3.exploration.testgenerator.util.GraphMetricUtils.getCentralPointDominance;
import static org.fortiss.af3.exploration.testgenerator.util.GraphMetricUtils.getCyclicCoefficient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
......@@ -18,8 +13,6 @@ import org.fortiss.af3.component.model.InputPort;
import org.fortiss.af3.component.model.OutputPort;
import org.fortiss.af3.component.utils.ComponentModelElementFactory;
import org.fortiss.af3.exploration.testgenerator.ArchitectureGraph;
import org.jgrapht.alg.scoring.ClusteringCoefficient;
import org.jgrapht.alg.shortestpath.GraphMeasurer;
import org.jgrapht.graph.DefaultWeightedEdge;
import com.google.common.collect.HashBasedTable;
......@@ -33,10 +26,10 @@ import com.google.common.collect.Table;
*
* @author munaro
*/
public class GraphUtil {
public class GraphUtils {
/** Hiding constructor. */
private GraphUtil() {
private GraphUtils() {
// Prevent instantiation.
}
......@@ -121,33 +114,6 @@ public class GraphUtil {
return architecture;
}
/**
* Calculates a variety of graph metrics for a given logical architecture.
*
* @param componentArchitecture
* Logical architecture to calculates metrics of
* @return A map containing the values of each graph metric
*/
public static Map<String, Double> getGraphMetrics(ComponentArchitecture componentArchitecture) {
Map<String, Double> graphMetrics = new HashMap<String, Double>();
ArchitectureGraph<Component> graph = getGraph(componentArchitecture);
GraphMeasurer<Component, DefaultWeightedEdge> measurer = new GraphMeasurer<>(graph);
ClusteringCoefficient<Component, DefaultWeightedEdge> clusterCoeff =
new ClusteringCoefficient<>(graph);
graphMetrics.put("average_degree", getAverageDegree(graph));
graphMetrics.put("clustering_coefficient", clusterCoeff.getAverageClusteringCoefficient());
graphMetrics.put("central_point_dominance", getCentralPointDominance(graph));
graphMetrics.put("diameter", measurer.getDiameter());
graphMetrics.put("radius", measurer.getRadius());
graphMetrics.put("nr_edges", (double)graph.edgeSet().size());
graphMetrics.put("nr_vertices", (double)graph.vertexSet().size());
graphMetrics.put("cyclic_coefficient", getCyclicCoefficient(graph));
return graphMetrics;
}
/**
* Checks whether a logical component is connected to another one.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment