-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupEvaluation.py
50 lines (32 loc) · 1.22 KB
/
GroupEvaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
import sys
import matplotlib.pyplot as plt
import numpy as np
def dbKey(obj):
return int(obj["dbi"])
class Evaluation:
topology = None
def __init__(self, t):
self.topology = t
def calculateGroupFitness(self, groups):
self.accumulatedInterferences(groups)
def accumulatedInterferences(self, groups):
""" Accumulate all interferences between nodes inside the group,
and accumulate all interferences between nodes inside the group."""
for group in groups:
internal, external = self.getInternalAndExternalDbi(group)
total = internal + external
if (total != 0):
print(internal / total, len(group.members))
plt.hist(internal/total)
plt.show()
def getInternalAndExternalDbi(self, group):
internal = 0
external = 0
for node in group.members:
for neighbour in node._neighbours:
if group.name == neighbour["obj"].group.name:
internal += 100 - neighbour["dbi"]
else:
external += 100 - neighbour["dbi"]
return internal, external