diff options
Diffstat (limited to 'Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQROSZ2.xtend_')
-rw-r--r-- | Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQROSZ2.xtend_ | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQROSZ2.xtend_ b/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQROSZ2.xtend_ new file mode 100644 index 00000000..e999d62f --- /dev/null +++ b/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQROSZ2.xtend_ | |||
@@ -0,0 +1,69 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculations | ||
2 | |||
3 | import ca.mcgill.ecse.dslreasoner.realistic.metrics.examples.Util | ||
4 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.neighbourhood.PartialInterpretation2ImmutableTypeLattice | ||
5 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
6 | import java.util.HashMap | ||
7 | import java.util.Map | ||
8 | import java.util.Set | ||
9 | import org.eclipse.emf.ecore.EObject | ||
10 | |||
11 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
12 | |||
13 | class CalcSQROSZ2 extends CalcMetric { | ||
14 | |||
15 | // /////////////////// | ||
16 | // SQROSZ2(v) = # depth-4 paths that lead to v / total # depth-4 paths | ||
17 | // /////////////////// | ||
18 | static val neighbourhoodComputer = new PartialInterpretation2ImmutableTypeLattice | ||
19 | |||
20 | override calcFromModel(EObject model) { | ||
21 | val nodes = model.eResource.allContents.toList | ||
22 | |||
23 | // fill HashSet | ||
24 | var Map<EObject, Set<EObject>> node2Neighbours = new HashMap | ||
25 | Util.fillWithNodes(nodes, node2Neighbours) | ||
26 | |||
27 | // iterate over nodes and add connected nodes | ||
28 | Util.getNeighboursList(nodes, node2Neighbours) | ||
29 | |||
30 | // Measurements | ||
31 | var totalSQR = 0.0 | ||
32 | var totalDenom = 0.0 | ||
33 | var num4thNeighbours = 0.0 | ||
34 | for (node : nodes) { | ||
35 | val neighbours = node.lookup(node2Neighbours) | ||
36 | |||
37 | for (neighbour1 : neighbours) { | ||
38 | val neighbours1 = neighbour1.lookup(node2Neighbours) | ||
39 | |||
40 | for (neighbour2 : neighbours1) { | ||
41 | val neighbours2 = neighbour2.lookup(node2Neighbours) | ||
42 | |||
43 | for (neighbour3 : neighbours2) { | ||
44 | val neighbours3 = neighbour3.lookup(node2Neighbours) | ||
45 | num4thNeighbours = neighbours3.size | ||
46 | |||
47 | if (neighbours3.contains(node)) { | ||
48 | totalSQR += 1 | ||
49 | } | ||
50 | totalDenom += num4thNeighbours | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | |||
55 | } | ||
56 | val avgSQR = totalSQR / totalDenom | ||
57 | |||
58 | return avgSQR | ||
59 | } | ||
60 | |||
61 | override calcFromNHLattice(PartialInterpretation pm) { | ||
62 | return 0.0 | ||
63 | // return getCfromNHLattice(pm, 2, v) | ||
64 | } | ||
65 | |||
66 | override calcFromNHLattice(PartialInterpretation pm, Integer depth) { | ||
67 | return 0.0 | ||
68 | } | ||
69 | } \ No newline at end of file | ||