aboutsummaryrefslogtreecommitdiffstats
path: root/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend
diff options
context:
space:
mode:
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend')
-rw-r--r--Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/src/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.xtend107
1 files changed, 107 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/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 @@
1package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph
2
3import com.google.common.collect.ArrayListMultimap
4import com.google.common.collect.Multimap
5import java.util.HashMap
6import java.util.HashSet
7import java.util.List
8import org.eclipse.emf.ecore.EObject
9
10class 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