-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalance_checker.py
39 lines (33 loc) · 1.18 KB
/
balance_checker.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
from __future__ import division
import pickle
from network_generator import *
def checkBalance(network,communityFileName):
attrId = communityFileName
attribute = NodeAttribute(attrId)
communityFile = open(communityFileName, 'r')
for line in communityFile:
line.strip()
line = line.split(':')
if len(line)==2:
nodeId = int(line[0].split('x')[1])
community = int(line[1].strip())
if not (type(community)==int):
print("Wrong parse exception")
else:
node = network.getNodeById(nodeId)
node.addAttribute(attribute,community)
balancedEdges = network.checkBalanceByAttribute(attrId)
print "Balanced edges of " + communityFileName + ": " + str(balancedEdges)
print "Proportion: " + str(float(balancedEdges)/float(network.getNumberOfEdges()))
print "--------------------------"
def main():
with open('test.network','rb') as f:
network = pickle.load(f)
network.getNodeWithHighestPositiveDegree()
#checkBalance(network,"testExact.comm")
#checkBalance(network,"testAprox.comm")
checkBalance(network,"pottsPsl.comm")
#checkBalance(network,"pottsPsl.comm")
#checkBalance(network,"testTestPsl.comm")
if __name__ == "__main__":
main()