-
Notifications
You must be signed in to change notification settings - Fork 2
/
CargarModelo.py
121 lines (92 loc) · 2.37 KB
/
CargarModelo.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
from math import ceil
from PSPLIB import import_from_PSPLIB
from print_graph import print_graph
def load_optimum(file, it):
found = False
fobj = open(file)
for idx,line in enumerate(fobj):
strings = line.rstrip().split()
if found == True and len(strings) > 3:
if idx == idxObj:
fobj.close()
return strings[2]
if strings[0] == "Paramter":
idxObj = idx + it + 2 # 2: 0 index and horizontal line
found = True
def load_limit(file, it):
found = False
fobj = open(file)
for idx,line in enumerate(fobj):
strings = line.rstrip().split()
if len(strings) > 0:
if found == True and len(strings) > 3:
if idx == idxObj:
fobj.close()
return strings[3] # LB
if strings[0] == "Par":
idxObj = idx + it + 2 # 2: 0 index and horizontal line
found = True
def load_others():
from CrearModelo1 import create_model
model = create_model()
model["opt"] = []
model["instances"] = []
# model = import_from_PSPLIB("Tests/j30/j301_1.sm")
# model["opt"] = 43
# model["instances"] = 1
# model = import_from_PSPLIB("Tests/j120/j1205_8.sm")
# model["opt"] = 78
# model["instances"] = 8
return model
def load_model(string, it, T):
if not string == "[]":
param = int(ceil(it/10.0))
inst = it%10
if inst == 0:
inst = 10
if string == "j30":
file = "tests/j30/j30" + str(param) \
+ "_" + str(inst) + ".sm"
elif string == "j60":
file = "tests/j60/j60" + str(param) \
+ "_" + str(inst) + ".sm"
elif string == "j90":
file = "tests/j90/j90" + str(param) \
+ "_" + str(inst) + ".sm"
elif string == "j120":
file = "tests/j120/j120" + str(param) \
+ "_" + str(inst) + ".sm"
else:
raise Exception('Error loading model')
model = import_from_PSPLIB(file)
if string == "j30":
file = "dataset/j30opt.sm"
model.update({
"Opt" : load_optimum(file, it),
"instances" : inst
})
elif string == "j60":
file = "dataset/j60lb.sm"
model.update({
"Opt" : load_limit(file, it),
"instances" : inst
})
elif string == "j90":
file = "dataset/j90lb.sm"
model.update({
"Opt" : load_limit(file, it),
"instances" : inst
})
elif string == "j120":
file = "dataset/j120lb.sm"
model.update({
"Opt" : load_limit(file, it),
"instances" : inst
})
else:
raise Exception('Error loading model')
else:
model = load_others()
if T == 1:
levels = print_graph(model)
return model