diff options
Diffstat (limited to 'Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQRMAX.xtend_')
-rw-r--r-- | Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQRMAX.xtend_ | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQRMAX.xtend_ b/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQRMAX.xtend_ new file mode 100644 index 00000000..071abe38 --- /dev/null +++ b/Metrics/ca.mcgill.ecse.dslreasoner.realistic.metrics/bin/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculations/CalcSQRMAX.xtend_ | |||
@@ -0,0 +1,87 @@ | |||
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 CalcSQRMAX extends CalcMetric{ | ||
14 | |||
15 | // /////////////////// | ||
16 | // SQRMAX(v) = # squares containing v / (# neighbours of v * max # of neeighbours of any neighbour of v) | ||
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 totalC = 0.0 | ||
32 | var max2ndNeighbours = 0.0 | ||
33 | var num1stNeighbours = 0.0 | ||
34 | for (node : nodes) { | ||
35 | val neighbours = node.lookup(node2Neighbours) | ||
36 | num1stNeighbours = neighbours.size | ||
37 | max2ndNeighbours = 0 | ||
38 | var numSquares = 0.0 | ||
39 | for (neighbour1 : neighbours) { | ||
40 | for (neighbour2 : neighbours) { | ||
41 | if (neighbour1 != neighbour2) { | ||
42 | val neighsOfNeigh = neighbour1.lookup(node2Neighbours) | ||
43 | if (max2ndNeighbours < neighsOfNeigh.size) { | ||
44 | max2ndNeighbours = neighsOfNeigh.size | ||
45 | } | ||
46 | for (neighOfNeigh1 : neighsOfNeigh) { | ||
47 | if (neighOfNeigh1 != node && neighOfNeigh1.lookup(node2Neighbours).contains(neighbour2)) { | ||
48 | // print(neighbour1) | ||
49 | // print(" ") | ||
50 | // print(neighbour2) | ||
51 | // print(" ") | ||
52 | // print(neighOfNeigh1) | ||
53 | // println() | ||
54 | numSquares++ | ||
55 | } | ||
56 | } | ||
57 | |||
58 | } | ||
59 | } | ||
60 | } | ||
61 | // println(node) | ||
62 | val num2ndNeighbours = num1stNeighbours * max2ndNeighbours | ||
63 | |||
64 | // print("(" + numSquares + "x" + num2ndNeighbours) | ||
65 | var sqr = 0.0 | ||
66 | if (num2ndNeighbours != 0) { | ||
67 | sqr = numSquares / num2ndNeighbours | ||
68 | } | ||
69 | |||
70 | // println("=" + sqr + ")") | ||
71 | totalC += sqr | ||
72 | } | ||
73 | val numNodes = nodes.length | ||
74 | val avgC = totalC / numNodes | ||
75 | |||
76 | return avgC | ||
77 | } | ||
78 | |||
79 | override calcFromNHLattice(PartialInterpretation pm) { | ||
80 | return 0.0 | ||
81 | // return getCfromNHLattice(pm, 2, v) | ||
82 | } | ||
83 | |||
84 | override calcFromNHLattice(PartialInterpretation pm, Integer depth) { | ||
85 | return 0.0 | ||
86 | } | ||
87 | } \ No newline at end of file | ||