forked from rxdiffarbitrary/rxdiffarbitrary
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_log_bounds_evolution.py
More file actions
128 lines (100 loc) · 2.77 KB
/
Copy pathprocess_log_bounds_evolution.py
File metadata and controls
128 lines (100 loc) · 2.77 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
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
import sys
from process_logs import LogFile
if __name__ == '__main__':
log_file = sys.argv[1]
try:
plot_file = sys.argv[2]
except IndexError:
plot_file = None
try:
sec_limit = int(sys.argv[3])
except IndexError:
sec_limit = 2**128
print("Processing", log_file)
F = LogFile(log_file=log_file, sec_limit=sec_limit)
F.plot_evolution(plot_file=plot_file)
'''
import re
import sys
times = []
lower = []
upper = []
timesX = []
lowerX = []
timesY = []
upperY = []
prev = -1
log_file = sys.argv[1]
try:
plot_file = sys.argv[2]
except IndexError:
plot_file = None
try:
sec_limit = int(sys.argv[3])
except IndexError:
sec_limit = 2**128
print("Processing", log_file)
model_count = 0
for line in open(log_file):
if line.startswith("Gurobi Optimizer"):
model_count += 1
if model_count >= 2:
break
continue
match = re.search(r"\s+[\d.\-]+\s+[\d.\-]+s$", line)
# Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
if not match:
if line.strip().endswith("s"):
if line.strip().endswith("threads"): continue
if line.strip().endswith("nonzeros"): continue
if line.strip().endswith("constraints"): continue
if line.strip().endswith("columns"): continue
if line.startswith("Presolve"): continue
# make sure we don't miss useful lines
print("skip", repr(line))
continue
# continue
*_, incumb, bound, gap, spd, time = line.strip().split()
if incumb == "-":
incumb = 0.0
else:
incumb = float(incumb)
bound = float(bound)
time = int(time.rstrip("s"))
if incumb > 40:
continue
# print(time, bound, "...", incumb, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" if bound_improved else "")
if "neqopt" in log_file:
bound_improved = (int(prev) != int(bound))
else:
bound_improved = not lower or (bound - max(lower)) > 1e-9
if bound_improved:
timesX.append(time)
lowerX.append(bound)
if not upper or -(incumb - min(upper)) > 1e-9:
timesY.append(time)
upperY.append(incumb)
times.append(time)
lower.append(bound)
upper.append(incumb)
# print(line.strip())
# print(time, bound, incumb)
# print()
prev = bound
if time > sec_limit:
break
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.plot(timesX, lowerX, "x", color="blue")
ax.plot(times, lower, "-", color="blue")
ax.plot(timesY, upperY, "x", color="red")
ax.plot(times, upper, "-", color="red")
ax.set(xlabel='time (s)', ylabel='-log(prob)', title='')
ax.grid()
if plot_file:
fig.savefig(plot_file)
else:
fig.savefig("test.png")
plt.show()
'''