-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult_analysis.py
More file actions
70 lines (67 loc) · 2.41 KB
/
result_analysis.py
File metadata and controls
70 lines (67 loc) · 2.41 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import numpy as np
def cal_success_ratio(logs_num, instance_name, model_type, coverage):
fail_num = 0.
for i in range(logs_num):
log_path = f'agents/solving_logs/IS_{model_type}_selectiveNet{coverage}_{i}.log'
log_file = open(log_path, "r", encoding='UTF-8')
lines = log_file.readlines() # 读取文件的所有行
assert len(lines) >= 0, '文件行数不足'
second_line = lines[1].split() # 获取第二行内容
if "failed" in second_line: # 判断第二行是否包含"fail"单词
fail_num += 1
return fail_num/logs_num
if __name__ == '__main__':
# logs_num = 100
# instance_name = '4_independent_set'
# model_type = 'ddpm'
# coverage = 0.2
# print(cal_success_ratio(logs_num, instance_name, model_type, coverage))
instance = "SC"
size = 3000
solver = "ps_gurobi"
if instance == 'SC':
instance_file = "1_set_cover"
log_name = "SC_instance"
start = 900
if size != None:
instance_file = f"1_set_cover_{size}"
start = 0
elif instance == 'CA':
instance_file = '2_combinatorial_auction'
log_name = "CA_instance"
start = 900
elif instance == 'CF':
instance_file = '3_capacity_facility'
log_name = "CF_instance"
start = 900
elif instance == 'IS':
instance_file = '4_independent_set'
log_name = "IS_instance"
start = 0
obj_vals = []
best_objs = []
for i in range(100):
log_path = f'logs/{solver}_logs/{instance_file}/{instance_file[2:]}_{start+i}.log'
log_file = open(log_path, "r", encoding='UTF-8')
lines = log_file.readlines() # 读取文件的所有行
if solver == 'scip':
idx = 0
for line in lines:
idx += 1
if "time" in line:
break
obj_val = float(lines[idx].split("|")[-3])
obj_vals.append(obj_val)
else:
for line in lines:
if 'heuristic' in line:
obj_val = float(line.split()[-1])
if 'Best' in line and 'objective' in line:
best_obj = float(line.split()[2][:-1])
obj_vals.append(obj_val)
best_objs.append(best_obj)
obj_vals = np.array(obj_vals)
best_objs = np.array(best_objs)
print(obj_vals.mean())
print(best_objs.mean())