-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplot_first_order.py
51 lines (43 loc) · 1.22 KB
/
plot_first_order.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
#!/usr/bin/python3
# Petter Strandmark
import sys
import matplotlib.pyplot as plt
LOOKING_FOR_DATA = 1
READING_DATA = 2
state = LOOKING_FOR_DATA
iterations = []
objectives = []
relative_changes_in_x = []
relative_changes_in_y = []
feasibilities = []
optimal_value = None
for line in sys.stdin.readlines():
if state == LOOKING_FOR_DATA:
if "--------" in line:
state = READING_DATA
print("Found convergence data.")
elif "Optimal value:" in line:
optimal_value = float(line.split(":")[1])
print("Found optimal value:", optimal_value)
elif state == READING_DATA:
try:
iteration, objective, rel_change_x, rel_change_y, feasibility = \
[float(n) for n in line.split()]
iterations.append(iteration)
objectives.append(objective)
relative_changes_in_x.append(rel_change_x)
relative_changes_in_y.append(rel_change_y)
feasibilities.append(feasibility)
except:
state = LOOKING_FOR_DATA
plt.semilogy(iterations,
feasibilities)
plt.xlabel("Iteration")
plt.title("Feasibility")
plt.show()
if optimal_value:
plt.semilogy(iterations,
[abs(obj - optimal_value) for obj in objectives])
plt.xlabel("Iteration")
plt.title("Objective value error")
plt.show()