-
Notifications
You must be signed in to change notification settings - Fork 9
/
Get_Data.py
44 lines (36 loc) · 1.48 KB
/
Get_Data.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
import csv
import os
import numpy as np
def getdata(N, M, NS, percentage, LAMBDA):
dir_path = os.path.dirname(os.path.realpath(__file__))
firstData = []
ifile = open(dir_path + '/data/cap41_%d_%d_%d.csv' % (N, M, NS), "r", encoding="ascii")
read = csv.reader(ifile)
for row in read: firstData.append(row)
ifile.close()
Dis = np.array([np.array(x).astype(np.float) for i, x in enumerate(firstData) if i <= N - 1])
B = [list(np.array(x).astype(np.float)) for i, x in enumerate(firstData) if i >= N and i <= NS + N - 1]
pop = list([np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N][0])
Cost = [np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N + 1][0]
cap = [np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N + 2][0]
Cec = [np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N + 3][0]
p = [np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N + 4][0]
budget = [np.array(x).astype(np.float) for i, x in enumerate(firstData) if i == NS + N + 5][0][0]
M = len(cap)
Dis = np.reshape(Dis, (N, M, NS), 'F')
Data = {
'M': M,
'N': N,
'NS': NS,
'budget': budget,
'percentage': percentage,
'pop': pop,
'cap': cap,
'cec': Cec,
'cost': Cost,
'distance': Dis,
'demand': B,
'p': p,
'lambda': LAMBDA,
}
return Data