-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcflp.log.py
156 lines (117 loc) · 4.53 KB
/
cflp.log.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import orloge
import csv
import os
solvers = 'pulp_cbc', 'cplex', 'gurobi'
cut_name = {'GUROBI': {
'Clique': 'CLIQUE',
'Cover': 'COVER',
'Flow cover': 'FLOW',
'Gomory': 'GOMORY',
'MIR': 'MIR',
'Zero half': 'ZERO_HALF',
'Inf proof': 'OUTROS',#'INF_PROOF',
'StrongCG': 'OUTROS',#'SCG',
'Mod-K': 'OUTROS',#'MOD_K',
'RLT': 'OUTROS',#'RLT',
'Relax-and-lift': 'OUTROS'#'RELAX_LIFT'
}, 'CPLEX': {
'Clique': 'CLIQUE',
'Cover': 'COVER',
'Flow': 'FLOW',
'Gomory fractional': 'GOMORY',
'Mixed integer rounding': 'MIR',
# 'Lift and project': 'OUTROS',#'LIFT_PROJECT',
'Zero-half': 'ZERO_HALF'
}, 'CBC': {}
}
concat = lambda v, p = '', sep = '': concat(v[1:], p + sep + v[0], '_') if len(v) else p
cols = [['solver'], ['instance_source_file_name'],['time_limit'],
['time'], #['rootTime'],
['gap'],
['nodes'], # importante
['best_solution'],
['best_bound'],
['matrix','constraints'],
['matrix','variables'],
['matrix','nonzeros'],
['matrix_post','constraints'],
['matrix_post','variables'],
['matrix_post','nonzeros'],
['first_relaxed'], ['first_solution', 'BestInteger'], ['first_solution', 'CutsBestBound'],
['cut_info', 'best_bound'],
['cut_info', 'best_solution'],
['cut_info', 'time']
# ['cut_info'],
]
dir = 'res'
last_index = lambda string, substring, prev_index=-1: prev_index if string.find(substring,prev_index+1) < 0 else last_index(string, substring, string.find(substring, prev_index + 1))
int_end = lambda string, end: int_end(string, end + 1) if end < len(string) and string[end].isdigit() else end
int_start = lambda string, start=0: int_start(string, start + 1) if start < len(string) and not string[start].isdigit() else start
to_int = lambda string: int(string) if len(string) > 0 else 0
for sources in ('single source', 'multi source', 'multi source/customer incompatibilities'):
for folder in ('MESS',):#, 'Beasley', 'Holmberg', 'Sobolev'):#('small', 'large'):#
dir = f'eduardo/{folder}/{sources}'#f'eduardo/Beasley/{sources}/{folder}'#
print('\n\n',dir,'\n')
table_name = 'eduardo/' + folder.lower().replace('/','.') + '.' + ''.join(w[0] for w in sources.split()).lower() + '.cflp.log.csv'#f'eduardo/{sources.split()[0][0].lower()}s.cflp.log.csv' #
table = csv.writer(open(table_name, 'w', encoding='UTF-8'), delimiter=';', quotechar="'")
logs = []
cuts = {}
files = [(a[:int_start(a)], to_int(a[int_start(a): int_end(a, int_start(a))]), a[:last_index(a,'(')], to_int(a.split('.')[-4].split('(')[-1].split(')')[0]), a.split('.')[-3], a) for a in os.listdir(dir) if a.endswith('.sol.log')]
files.sort()
for instance_type, instance_num, file_name, time_limit, sol, log_file in files:
print(repr(instance_type), instance_num, '\t', time_limit,'\t',file_name,'\t',sol)
#log_file = f'resol/{cod}Cap{cap}.txt.{s}.sol.log'
solver = sol.split('_')[-1].upper()
if not solver in cut_name:
continue
#print('\t',end=solver)
log = orloge.get_info_solver(dir + '/' + log_file, solver)
logs.append(log)
log['instance_source_file_name'] = file_name
log['time_limit'] = time_limit#cod
#log['capacity'] = cap
#print(log['cut_info'])
if log['cut_info'] != None and 'cuts' in log['cut_info']:
for c in log['cut_info']['cuts']:
if not c in cut_name[solver]:
cut_name[solver][c] = c.strip().upper().replace('\t',' ').replace(' ','-').replace('-','_')
print(solver,'Cut',c,'included!')
if not cut_name[solver][c] in log['cut_info']:
log['cut_info'][cut_name[solver][c]] = 0
log['cut_info'][cut_name[solver][c]] += log['cut_info']['cuts'][c]
if not c in cuts:
cuts[c] = set()
cuts[c].add(solver)
cuts_table = set()
for c in cuts:
for s in cuts[c]:
cuts_table.add(('cut_info', cut_name[s][c]))
cuts_table = list(cuts_table)
cuts_table.sort()
cols.extend(cuts_table)
h = [(c if type(c) == str else concat(c)) for c in cols]
table.writerow(h)
print('\n')
for log in logs:
data = []
print(log['solver'], '\t', log['instance_source_file_name'], log['time_limit'])
for c in cols:
l = log
for c in c:
if l == None or not c in l:
l = None
break
l = l[c]
if type(l) == float:
l = str(l).replace('.',',')
data.append(l)
#print(data)
table.writerow(data)
table = None
rows = [ln.strip() for ln in open(table_name, 'r', encoding='UTF-8').readlines()]
table = open(table_name, 'w', encoding='UTF-8')
for ln in rows:
if len(ln):
print(ln,file=table)
print('\n',cuts)
print('\n',cut_name)