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, 322 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..b20ffa01 --- /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,101 @@ | |||
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 | |||
12 | def void init (EObject root, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
13 | val otherContents = root.eAllContents.toList(); | ||
14 | otherContents.add(root); | ||
15 | init(otherContents, metrics, name, referenceTypes); | ||
16 | } | ||
17 | |||
18 | /** | ||
19 | * init the graph with all nodes and reference types in the meta model | ||
20 | * @param objects: objects in the instance model (exclude root) | ||
21 | * @param metrics: metrics to be evaluated | ||
22 | * @param name: name of the instance model | ||
23 | * @param ReferenceTypes: reference types defined in the meta model | ||
24 | */ | ||
25 | def void init(List<EObject> objects, List<Metric> metrics, String name, List<String> referenceTypes){ | ||
26 | objects.forEach[it| | ||
27 | statistic.addNode(it); | ||
28 | ] | ||
29 | |||
30 | referenceTypes.forEach[it| | ||
31 | statistic.addType(it); | ||
32 | ]; | ||
33 | |||
34 | objects.forEach[source| | ||
35 | source.eClass.EAllReferences.forEach[r| | ||
36 | //add the type first (if it is not added already) | ||
37 | //many references | ||
38 | if(r.isMany){ | ||
39 | source.getNeighbours(r).forEach[target| | ||
40 | addEdge(source, target, r); | ||
41 | ] | ||
42 | }else{ | ||
43 | //single references | ||
44 | val target = source.eGet(r) as EObject; | ||
45 | addEdge(source, target, r); | ||
46 | } | ||
47 | ] | ||
48 | ] | ||
49 | |||
50 | this.metrics = metrics; | ||
51 | this.name = name; | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * Set basic information for the output | ||
56 | */ | ||
57 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
58 | val metaInfo = new ArrayList<String>(); | ||
59 | metaInfo.add(META_MODEL_HEADER); | ||
60 | metaInfo.add(this.metaModel); | ||
61 | |||
62 | val edgeInfo = new ArrayList<String>(); | ||
63 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
64 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
65 | |||
66 | val nodeInfo = new ArrayList<String>(); | ||
67 | nodeInfo.add(NUM_NODE_HEADER); | ||
68 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
69 | |||
70 | output.add(metaInfo); | ||
71 | output.add(edgeInfo); | ||
72 | output.add(nodeInfo); | ||
73 | } | ||
74 | |||
75 | def EList<EObject> getNeighbours(EObject o, EReference r){ | ||
76 | return (o.eGet(r, true) as EList<EObject>); | ||
77 | } | ||
78 | |||
79 | def addEdge(EObject source, EObject target, EReference r){ | ||
80 | if(target !== null && r !== null){ | ||
81 | statistic.addEdge(source, target, r.name); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | override GraphStatistic getStatistic(){ | ||
86 | return this.statistic; | ||
87 | } | ||
88 | |||
89 | override String getName(){ | ||
90 | return this.name; | ||
91 | } | ||
92 | |||
93 | def void setMetaModel(String model){ | ||
94 | this.metaModel = model; | ||
95 | } | ||
96 | |||
97 | def String getMetaModel(){ | ||
98 | return this.metaModel; | ||
99 | } | ||
100 | |||
101 | } \ 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..6d65367f --- /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,41 @@ | |||
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 | |||
7 | abstract class Graph { | ||
8 | |||
9 | protected static val String META_MODEL_HEADER = "Meta Mode" | ||
10 | protected static val String NUM_NODE_HEADER = "Number Of Nodes"; | ||
11 | protected static val String NUM_EDGE_TYPE_HEADER = "Number of Edge types"; | ||
12 | protected static val String STATE_ID_HEADER = "State Id"; | ||
13 | |||
14 | protected val statistic = new GraphStatistic(); | ||
15 | protected var List<Metric> metrics; | ||
16 | protected var String name = ""; | ||
17 | protected var String metaModel = ""; | ||
18 | |||
19 | /** | ||
20 | * evaluate all metrics for this model | ||
21 | * return the result as a two dimentional list | ||
22 | */ | ||
23 | def ArrayList<ArrayList<String>> evaluateAllMetrics(){ | ||
24 | val result = new ArrayList<ArrayList<String>>(); | ||
25 | setBasicInformation(result); | ||
26 | |||
27 | for(metric : this.metrics){ | ||
28 | val datas = metric.evaluate(this.statistic); | ||
29 | for(row : datas){ | ||
30 | result.add(new ArrayList<String>(row)); | ||
31 | } | ||
32 | } | ||
33 | return result; | ||
34 | } | ||
35 | |||
36 | def void setBasicInformation(ArrayList<ArrayList<String>> result); | ||
37 | |||
38 | def GraphStatistic getStatistic(); | ||
39 | |||
40 | def String getName(); | ||
41 | } \ 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..074a75da --- /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,73 @@ | |||
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.viatrasolver.partialinterpretationlanguage.partialinterpretation.BinaryElementRelationLink | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
6 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.impl.BooleanElementImpl | ||
7 | import java.util.ArrayList | ||
8 | import java.util.List | ||
9 | |||
10 | class PartialInterpretationGraph extends Graph{ | ||
11 | var lastStateId=""; | ||
12 | |||
13 | new(PartialInterpretation partial, List<Metric> metrics, String name){ | ||
14 | partial.problem.relations.forEach[ | ||
15 | this.statistic.addType(it.name); | ||
16 | ] | ||
17 | // add all elements | ||
18 | val elements = getElements(partial); | ||
19 | for(element : elements){ | ||
20 | statistic.addNode(element) | ||
21 | } | ||
22 | |||
23 | for(relationInterpretation : partial.partialrelationinterpretation) { | ||
24 | val type = relationInterpretation.interpretationOf.name | ||
25 | |||
26 | for(edge : relationInterpretation.relationlinks.filter(BinaryElementRelationLink)){ | ||
27 | statistic.addEdge(edge.param1, edge.param2, type); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | this.name = name; | ||
32 | this.metrics = metrics; | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Set basic information for the output | ||
37 | */ | ||
38 | override setBasicInformation(ArrayList<ArrayList<String>> output){ | ||
39 | val metaInfo = new ArrayList<String>(); | ||
40 | metaInfo.add(META_MODEL_HEADER); | ||
41 | metaInfo.add(this.metaModel); | ||
42 | |||
43 | val edgeInfo = new ArrayList<String>(); | ||
44 | edgeInfo.add(NUM_EDGE_TYPE_HEADER); | ||
45 | edgeInfo.add(this.statistic.allTypes.size()+""); | ||
46 | |||
47 | val nodeInfo = new ArrayList<String>(); | ||
48 | nodeInfo.add(NUM_NODE_HEADER); | ||
49 | nodeInfo.add(this.statistic.allNodes.size()+""); | ||
50 | |||
51 | val stateInfo = new ArrayList<String>(); | ||
52 | stateInfo.add(STATE_ID_HEADER); | ||
53 | stateInfo.add(this.name); | ||
54 | |||
55 | output.add(metaInfo); | ||
56 | output.add(edgeInfo); | ||
57 | output.add(nodeInfo); | ||
58 | output.add(stateInfo); | ||
59 | } | ||
60 | |||
61 | private def getElements(PartialInterpretation partial){ | ||
62 | return partial.newElements.filter[!(it instanceof BooleanElementImpl)] + partial.problem.elements; | ||
63 | } | ||
64 | |||
65 | override getStatistic() { | ||
66 | throw new UnsupportedOperationException("TODO: auto-generated method stub") | ||
67 | } | ||
68 | |||
69 | override getName() { | ||
70 | return name; | ||
71 | } | ||
72 | |||
73 | } \ No newline at end of file | ||