Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a_matrix = []
- infection = {}
- seeds = []
- def fill_matrix():
- global threshold
- global numNodes
- global firstNode
- fileVectors = open("decisionTestText.txt")
- numNodes = int(fileVectors.readline().strip())
- firstNode = int(fileVectors.readline().strip())
- threshold = float(fileVectors.readline().strip())
- seededNodes = fileVectors.readline().strip()
- lastComma = -1
- while(not seededNodes.find(",", lastComma + 1) == -1):
- seeds.append(int(seededNodes[lastComma+1: seededNodes.index(",", lastComma+1)].strip())-firstNode+1)
- lastComma = seededNodes.index(",", lastComma + 1)
- seeds.append(int(seededNodes[lastComma+1:].strip())-firstNode+1)
- for i in range(numNodes):
- if not i+1 in seeds:
- infection.update({i+1: 0})
- else:
- infection.update({i+1: 1})
- rowArray = []
- for i in range(numNodes):
- rowArray.append(0)
- for j in range(numNodes):
- a_matrix.append(rowArray.copy())
- for line in fileVectors:
- first = int(line[0:line.index(",")].strip())-firstNode+1
- second = int(line[line.index(",")+1:].strip())-firstNode+1
- a_matrix[first-1][second-1] = 1
- a_matrix[second-1][first-1] = 1
- fileVectors.close()
- def check_infection(node):
- infectedCount = 0
- friendCount = 0
- for i in range(len(a_matrix[node-1])):
- if a_matrix[node-1][i] == 1:
- friendCount += 1
- if infection.get(i+1) == 1:
- infectedCount += 1
- if not friendCount == 0 and infectedCount/friendCount > threshold:
- infection[node] = 1
- def main():
- print("\n\n")
- fill_matrix()
- new_infection = {}
- counter = 0
- for i in range(numNodes):
- new_infection.update({i+firstNode-1:0})
- while not new_infection == infection:
- changedArray = []
- print("t" + str(counter) + ":", end = ' ')
- for i in infection:
- if not infection.get(i) == new_infection.get(i):
- changedArray.append(i+firstNode - 1)
- print(changedArray)
- new_infection = infection.copy()
- for i in range(len(a_matrix)):
- check_infection(i+1)
- counter += 1
- print("\n")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement