-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.py
More file actions
56 lines (50 loc) · 1.62 KB
/
loader.py
File metadata and controls
56 lines (50 loc) · 1.62 KB
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
import re
import numpy as np
# The format of these data files is:
# number of problems
# for each problem in turn:
# number of jobs (n)
# for each job i (i=1,...,n) in turn:
# p(i), a(i), b(i)
def load_data(path):
results = []
with open(path) as file:
problems = int(file.readline())
for problem in range(problems):
n = int(file.readline())
p_list = []
a_list = []
b_list = []
for j in range(n):
line = file.readline()
line = re.sub(' +', ' ', line).lstrip()
p, a, b = line.split(' ')
p_list.append(int(p))
a_list.append(int(a))
b_list.append(int(b))
result = {
"problems": problems,
"n": n,
"p": p_list,
"a": a_list,
"b": b_list
}
results.append(result)
return results
def convert_to_numpy_array(data):
arrays = []
for datum in data:
values = []
for i in range(len(datum['p'])):
values.append([[datum['p'][i]], [datum['a'][i]], [datum['b'][i]]])
array = np.array(values, dtype=int)
arrays.append(array)
return np.asarray(arrays)
def save_data(path, result, scheduled_task):
len = result['n']
with open(path, 'w') as file:
file.write(result["sum_f"])
file.write(str(len))
for i in range(len):
t_id = scheduled_task[i]["id"]
file.write(result['p'][t_id] + "\t" + result['a'][t_id] + "\t" + result['b'][t_id])