-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowControl.py
executable file
·53 lines (45 loc) · 1.39 KB
/
FlowControl.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
import sys
def PrintStatus():
global total_energy
global total_time
print("total energy: ",total_energy)
print("total time: ",total_time)
def ClearData(G):
global cycle_count
global cycle_time
global total_energy
global total_time
cycle_time=0
cycle_count=0
total_energy=0
total_time=0
for (node,data) in G.nodes(data=True):
data['output_gid']=None
def NextCycle(G):
global cycle_count
global cycle_time
global total_time
total_time+=cycle_time
cycle_time=0
cycle_count+=1
for (node,data) in G.nodes(data=True):
data['output_gid']=None
def FlowGid(G,gid):
global cycle_time
global total_energy
global total_time
for (node,data) in G.nodes(data=True):
for edge in G.edges(node,data=True):
if(edge[2]['gid']==gid):
if data['output_gid'] != gid and data['output_gid'] != None:
print("Can't flow different gid from same node!")
sys.exit(2)
total_energy+=edge[2]['energy']
cycle_time=max(cycle_time,edge[2]['time'])
data['output_gid']=gid
def GraphCheck(G):
for node in G.nodes:
for edge in G.edges(node,data=True):
if(edge[1]==node):
print("Self cycle!")
sys.exit(2)