-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.py
57 lines (54 loc) · 1.67 KB
/
Main.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
49
50
51
52
53
54
55
56
57
import sys
import time
import json
import socket
from _thread import *
import threading
from MST import MSTNode, Edge
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: Main <file>", file=sys.stderr)
sys.exit(-1)
print_lock = threading.Lock()
initial_port = 12345
timeout = 0
nodes = set()
edges = []
with open(str(sys.argv[1]), 'r') as file:
for line in file:
edge = line.split()
timeout += 2 * int(edge[3])
edges.append(
Edge(
src_node = int(edge[0]),
src_port = initial_port + int(edge[0]),
dest_node = int(edge[1]),
dest_port = initial_port + int(edge[1]),
weight = int(edge[2]),
delay = int(edge[3]),
)
)
edges.append(
Edge(
src_node = int(edge[1]),
src_port = initial_port + int(edge[1]),
dest_node = int(edge[0]),
dest_port = initial_port + int(edge[0]),
weight = int(edge[2]),
delay = int(edge[3]),
)
)
nodes.add(int(edge[0]))
nodes.add(int(edge[1]))
threads = []
for node in nodes:
threads.append(
MSTNode(
uid = node,
port = initial_port + node,
edges = [edge for edge in edges if edge.src_node==node],
timeout = timeout
)
)
for x in threads:
x.start()