diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph')
4 files changed, 351 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend new file mode 100644 index 00000000..5c161f4b --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/EMFGraph.xtend | |||
@@ -0,0 +1,106 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import java.util.ArrayList | ||
5 | import java.util.List | ||
6 | import org.eclipse.emf.common.util.EList | ||
7 | import org.eclipse.emf.ecore.EObject | ||
8 | import org.eclipse.emf.ecore.EReference | ||
9 | |||
10 | class EMFGraph extends Graph{ | ||
11 | def void init (EObject root, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
12 | val otherContents = root.eAllContents.toList(); | ||
13 | otherContents.add(root); | ||
14 | init(otherContents, metrics, name, referenceTypes); | ||
15 | } | ||
16 | |||
17 | /** | ||
18 | * init the graph with all nodes and reference types in the meta model | ||
19 | * @param objects: objects in the instance model (exclude root) | ||
20 | * @param metrics: metrics to be evaluated | ||
21 | * @param name: name of the instance model | ||
22 | * @param ReferenceTypes: reference types defined in the meta model | ||
23 | */ | ||
24 | def void init(List<EObject> objects, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
25 | objects.forEach[it| | ||
26 | statistic.addNode(it); | ||
27 | ] | ||
28 | |||
29 | referenceTypes.forEach[it| | ||
30 | statistic.addType(it); | ||
31 | ]; | ||
32 | |||
33 | objects.forEach[source| | ||
34 | source.eClass.EAllReferences.forEach[r| | ||
35 | //add the type first (if it is not added already) | ||
36 | //many references | ||
37 | if(r.isMany){ | ||
38 | source.getNeighbours(r).forEach[target| | ||
39 | addEdge(source, target, r); | ||
40 | ] | ||
41 | }else{ | ||
42 | //single references | ||
43 | val target = source.eGet(r) as EObject; | ||
44 | addEdge(source, target, r); | ||
45 | } | ||
46 | ] | ||
47 | ] | ||
48 | |||
49 | this.metrics = metrics; | ||
50 | this.name = name; | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * Set basic information for the output | ||
55 | */ | ||
56 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
57 | val metaInfo = new ArrayList<String>(); | ||
58 | metaInfo.add(META_MODEL_HEADER); | ||
59 | metaInfo.add(this.metaModel); | ||
60 | |||
61 | val edgeInfo = new ArrayList<String>(); | ||
62 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
63 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
64 | |||
65 | val nodeInfo = new ArrayList<String>(); | ||
66 | nodeInfo.add(NUM_NODE_HEADER); | ||
67 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
68 | |||
69 | val stateInfo = new ArrayList<String>(); | ||
70 | stateInfo.add(STATE_ID_HEADER); | ||
71 | stateInfo.add(this.name); | ||
72 | |||
73 | |||
74 | output.add(metaInfo); | ||
75 | output.add(edgeInfo); | ||
76 | output.add(nodeInfo); | ||
77 | output.add(stateInfo); | ||
78 | } | ||
79 | |||
80 | def EList<EObject> getNeighbours(EObject o, EReference r){ | ||
81 | return (o.eGet(r, true) as EList<EObject>); | ||
82 | } | ||
83 | |||
84 | def addEdge(EObject source, EObject target, EReference r){ | ||
85 | if(target !== null && r !== null){ | ||
86 | statistic.addEdge(source, target, r.name); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | override GraphStatistic getStatistic(){ | ||
91 | return this.statistic; | ||
92 | } | ||
93 | |||
94 | override String getName(){ | ||
95 | return this.name; | ||
96 | } | ||
97 | |||
98 | def void setMetaModel(String model){ | ||
99 | this.metaModel = model; | ||
100 | } | ||
101 | |||
102 | def String getMetaModel(){ | ||
103 | return this.metaModel; | ||
104 | } | ||
105 | |||
106 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend new file mode 100644 index 00000000..cf4aedba --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/Graph.xtend | |||
@@ -0,0 +1,61 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MetricSampleGroup | ||
5 | import java.util.ArrayList | ||
6 | import java.util.List | ||
7 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.MultiplexParticipationCoefficientMetric | ||
8 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.NodeActivityMetric | ||
9 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.OutDegreeMetric | ||
10 | |||
11 | abstract class Graph { | ||
12 | |||
13 | protected static val String META_MODEL_HEADER = "Meta Mode" | ||
14 | protected static val String NUM_NODE_HEADER = "Number Of Nodes"; | ||
15 | protected static val String NUM_EDGE_TYPE_HEADER = "Number of Edge types"; | ||
16 | protected static val String STATE_ID_HEADER = "State Id"; | ||
17 | |||
18 | protected val statistic = new GraphStatistic(); | ||
19 | protected var List<Metric> metrics; | ||
20 | protected var String name = ""; | ||
21 | protected var String metaModel = ""; | ||
22 | |||
23 | /** | ||
24 | * evaluate all metrics for this model | ||
25 | * return the result as a two dimentional list | ||
26 | */ | ||
27 | def ArrayList<ArrayList<String>> evaluateAllMetrics(){ | ||
28 | val result = new ArrayList<ArrayList<String>>(); | ||
29 | setBasicInformation(result); | ||
30 | |||
31 | for(metric : this.metrics){ | ||
32 | val datas = metric.evaluate(this.statistic); | ||
33 | for(row : datas){ | ||
34 | result.add(new ArrayList<String>(row)); | ||
35 | } | ||
36 | } | ||
37 | return result; | ||
38 | } | ||
39 | |||
40 | def MetricSampleGroup evaluateAllMetricsToSamples(){ | ||
41 | var sample = new MetricSampleGroup(); | ||
42 | |||
43 | for(metric : this.metrics){ | ||
44 | if(metric instanceof MultiplexParticipationCoefficientMetric){ | ||
45 | sample.mpcSamples = metric.evaluateSamples(this.statistic); | ||
46 | }else if(metric instanceof NodeActivityMetric){ | ||
47 | sample.naSamples = metric.evaluateSamples(this.statistic); | ||
48 | }else if(metric instanceof OutDegreeMetric){ | ||
49 | sample.outDegreeSamples = metric.evaluateSamples(this.statistic); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | return sample; | ||
54 | } | ||
55 | |||
56 | def void setBasicInformation(ArrayList<ArrayList<String>> result); | ||
57 | |||
58 | def GraphStatistic getStatistic(); | ||
59 | |||
60 | def String getName(); | ||
61 | } \ No newline at end of file | ||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend new file mode 100644 index 00000000..7ed58094 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend | |||
@@ -0,0 +1,107 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import com.google.common.collect.ArrayListMultimap | ||
4 | import com.google.common.collect.Multimap | ||
5 | import java.util.HashMap | ||
6 | import java.util.HashSet | ||
7 | import java.util.List | ||
8 | import org.eclipse.emf.ecore.EObject | ||
9 | |||
10 | class GraphStatistic { | ||
11 | val incomingEdges = new HashMap<String, Multimap<EObject, EObject>>; | ||
12 | val outcomingEdges = new HashMap<String, Multimap<EObject, EObject>>; | ||
13 | |||
14 | val edgeTypes = new HashSet<String>(); | ||
15 | val nodes = new HashSet<EObject>(); | ||
16 | |||
17 | /** | ||
18 | * Add an edge type to to the graph | ||
19 | * @param type: type to add | ||
20 | */ | ||
21 | def void addType(String type){ | ||
22 | if(edgeTypes.contains(type)){ | ||
23 | return; | ||
24 | } | ||
25 | edgeTypes.add(type); | ||
26 | incomingEdges.put(type, ArrayListMultimap.create()); | ||
27 | outcomingEdges.put(type, ArrayListMultimap.create()); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Add a node to he graph | ||
32 | * @param node: node to add | ||
33 | */ | ||
34 | def void addNode(EObject n){ | ||
35 | if(nodes.contains(n)){ | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | nodes.add(n); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Add an edge to the graph | ||
44 | * @param source: source node | ||
45 | * @param target: target node | ||
46 | * @param type: type of the reference | ||
47 | */ | ||
48 | def void addEdge(EObject source, EObject target, String type){ | ||
49 | outcomingEdges.get(type).put(source, target); | ||
50 | incomingEdges.get(type).put(target, source); | ||
51 | } | ||
52 | |||
53 | /** | ||
54 | * calculate the out degree for an object | ||
55 | */ | ||
56 | def int outDegree(EObject o){ | ||
57 | var count = 0; | ||
58 | |||
59 | for (String type : edgeTypes){ | ||
60 | count += outcomingEdges.get(type).get(o).size(); | ||
61 | } | ||
62 | return count; | ||
63 | } | ||
64 | |||
65 | /** | ||
66 | * calculate the in degree of an object | ||
67 | */ | ||
68 | def int inDegree(EObject o){ | ||
69 | var count = 0; | ||
70 | |||
71 | for (String type : edgeTypes){ | ||
72 | count += incomingEdges.get(type).get(o).size(); | ||
73 | } | ||
74 | return count; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * calculate the dimentional degree of a node | ||
79 | */ | ||
80 | def int dimentionalDegree(EObject o, String type){ | ||
81 | return incomingEdges.get(type).get(o).size() + outcomingEdges.get(type).get(o).size(); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * calculate the number of edge types for a given degree. | ||
86 | */ | ||
87 | def int numOfEdgeTypes(EObject o){ | ||
88 | var count = 0; | ||
89 | |||
90 | for(String type : edgeTypes){ | ||
91 | if(dimentionalDegree(o, type) > 0){ | ||
92 | count++; | ||
93 | } | ||
94 | } | ||
95 | |||
96 | return count; | ||
97 | } | ||
98 | |||
99 | def List<String> getAllTypes(){ | ||
100 | return edgeTypes.toList(); | ||
101 | } | ||
102 | |||
103 | def List<EObject> getAllNodes(){ | ||
104 | return nodes.toList(); | ||
105 | } | ||
106 | } | ||
107 | |||
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend new file mode 100644 index 00000000..14337ab0 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/PartialInterpretationGraph.xtend | |||
@@ -0,0 +1,77 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.metrics.Metric | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
7 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.BooleanElementImpl | ||
8 | import java.util.ArrayList | ||
9 | import java.util.List | ||
10 | |||
11 | class PartialInterpretationGraph extends Graph{ | ||
12 | |||
13 | /** | ||
14 | * Define a new PartialInterpretationGraph by parse every element from a PartialInterpretation | ||
15 | */ | ||
16 | new(PartialInterpretation partial, List<Metric> metrics, String name){ | ||
17 | //the edge types are defined in terms of RelationDeclaration | ||
18 | partial.problem.relations.filter(RelationDeclaration).forEach[ | ||
19 | this.statistic.addType(it.name); | ||
20 | ] | ||
21 | // add all elements | ||
22 | val elements = getElements(partial); | ||
23 | for(element : elements){ | ||
24 | statistic.addNode(element) | ||
25 | } | ||
26 | |||
27 | for(relationInterpretation : partial.partialrelationinterpretation) { | ||
28 | val type = relationInterpretation.interpretationOf.name | ||
29 | |||
30 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ | ||
31 | statistic.addEdge(edge.param1, edge.param2, type); | ||
32 | } | ||
33 | } | ||
34 | |||
35 | this.name = name; | ||
36 | this.metrics = metrics; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Set basic information for the output | ||
41 | */ | ||
42 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
43 | val metaInfo = new ArrayList<String>(); | ||
44 | metaInfo.add(META_MODEL_HEADER); | ||
45 | metaInfo.add(this.metaModel); | ||
46 | |||
47 | val edgeInfo = new ArrayList<String>(); | ||
48 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
49 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
50 | |||
51 | val nodeInfo = new ArrayList<String>(); | ||
52 | nodeInfo.add(NUM_NODE_HEADER); | ||
53 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
54 | |||
55 | val stateInfo = new ArrayList<String>(); | ||
56 | stateInfo.add(STATE_ID_HEADER); | ||
57 | stateInfo.add(this.name); | ||
58 | |||
59 | output.add(metaInfo); | ||
60 | output.add(edgeInfo); | ||
61 | output.add(nodeInfo); | ||
62 | output.add(stateInfo); | ||
63 | } | ||
64 | |||
65 | private def getElements(PartialInterpretation partial){ | ||
66 | return partial.newElements.filter[!(it instanceof BooleanElementImpl)] + partial.problem.elements; | ||
67 | } | ||
68 | |||
69 | override getStatistic() { | ||
70 | throw new UnsupportedOperationException("TODO: auto-generated method stub") | ||
71 | } | ||
72 | |||
73 | override getName() { | ||
74 | return name; | ||
75 | } | ||
76 | |||
77 | } \ No newline at end of file | ||