-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.py
61 lines (56 loc) · 1.81 KB
/
utils.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
58
59
60
61
def read_param(filepath,dest,n_lines=48):
file=open(filepath,"r")
lines=file.readlines()
for i in range(n_lines):
line=list(map(float,list(lines[i].strip().split())))
dest.append(line[1:])
file.close()
def add_lists(l1,l2):
return [sum(x) for x in zip(l1, l2)]
def sub_lists(l1,l2):
return [a - b for a, b in zip(l1, l2)]
def less_than(l1,l2):
for i in range(len(l1)):
if(l1[i]>l2[i]):
return False
return True
def min_finish_time(ref_time,finish_times):
mft=10**8+10
for i in range(len(finish_times)):
if(finish_times[i]>ref_time):
mft=min(mft,finish_times[i])
if(mft==10**8+10):
mft=ref_time
return mft
def find_index(index_list,value_list,stat='min'):
#Function to find the index from index list whose value in value list is minimum or maximum
if(stat=='min'):
pos=0
minv=value_list[index_list[0]]
for i in range(len(index_list)):
if(value_list[index_list[i]]<minv or (value_list[index_list[i]]==minv and index_list[i]<index_list[pos])):
minv=value_list[index_list[i]]
pos=i
else: # stat='max'
pos=0
maxv=value_list[index_list[0]]
for i in range(len(index_list)):
if(value_list[index_list[i]]>maxv or (value_list[index_list[i]]==maxv and index_list[i]<index_list[pos])):
maxv=value_list[index_list[i]]
pos=i
return pos
def normalised(arr,norm=0):
if(norm==0):
newarr=[i/max(arr) for i in arr]
else:
newarr=[i/norm for i in arr]
return newarr
def latex(*argv):
args=[]
for arg in argv:
args.append(arg)
for arg in args:
print(arg,end='')
if(arg!=args[-1]):
print(" & ",end='')
print("\\\\")