-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdinput.py
130 lines (91 loc) · 2.76 KB
/
oldinput.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import numpy as np
import os
import workfunction
def getT(e):
return e[1]
def getScore(e):
return e[1]
def score(indexes_of_books, books):
result = 0
for i in indexes_of_books:
result += books[i]
return result
bo = []
def readInput(path_data):
with open(path_data) as f:
lines = f.readlines()
n_books, n_libraries, n_days = np.asarray(lines[0].split()).astype(int)
scores_of_books = np.asarray(lines[1].split(), int)
st = [(i,s) for i,s in enumerate(scores_of_books)]
ss = sorted(st,key=getScore,reverse=True)
bo = [i[0] for i in ss]
s = [i[1] for i in ss]
main_dict = {idx: val for idx, val in enumerate(scores_of_books)}
line_index = 2
libraries = {}
for lib_index in range(int(n_libraries)):
bs = np.asarray(lines[line_index + 1].split(), int)
bs = sorted(bs, key=lambda x: bo.index(x))
libraries[lib_index] = [np.asarray(lines[line_index].split(), int),
bs ,
score(np.asarray(lines[line_index + 1].split(), int), scores_of_books)]
line_index += 2
return (n_books,n_libraries,n_days),libraries,s
p,d,s = readInput(os.path.join("datasets", "a_example.txt"))
days = p[2]
count = 1
z = []
ls = []
f = ''
liblines=[]
booklines=[]
for day in range(days):
scores = []
dzs = []
if len(ls) == len(d):
break
for lib_i,lib in d.iteritems():
if lib_i in ls:
continue
Tj = lib[0][1]
Mj = lib[0][2]
score,dZ = workfunction.maxScore(s,lib[1],z,days,day,Tj,Mj)
scores.append((lib_i,score,dZ))
dzs.append(dZ)
scores= sorted(scores,key=getScore,reverse=True)
libsubm = '{} {}\n'.format(scores[0][0],len(dZ))
booksubm = ''
for b in dZ:
booksubm+=str(b)+' '
booksubm+='\n'
liblines.append(libsubm)
booklines.append(booksubm)
ls.append(scores[0][0])
z += scores[0][2]
f+='{}\n'.format(len(ls))
for i,v in enumerate(liblines):
f+=liblines[i]
f+=booklines[i]
print f
outfile = 'out_a.txt'
with open(outfile,'w+') as file:
file.write(f)
# Ts = []
# worklist = []
# for i,v in d.iteritems():
# Ts.append((i,v[0][1]))
# Ts = sorted(Ts,key=getT)
# outfile_b = 'b_out.txt'
# with open(outfile_b,'w+') as f:
# header = '{}'.format(len(Ts))
# print header
# f.write(header+'\n')
# for i,v in enumerate(Ts):
# libsubm = ''
# booksubm = ''
# libsubm = '{} {}'.format(v[0],np.min([days-count,len(d[v[0]][1])]))
# for b in d[v[0]][1][:days-count]:
# booksubm += str(b) + ' '
# count+=1
# f.write(libsubm+'\n')
# f.write(booksubm+'\n')