-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_search_path.py
138 lines (125 loc) · 3.59 KB
/
plot_search_path.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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
def visualize_dsda(
incumbent_path, exploration, feas_x, feas_y, objs, file_name, x_label, y_label
):
sc = plt.scatter(feas_x, feas_y, s=80, c=objs, cmap='viridis_r')
for i in range(len(incumbent_path) - 1):
plt.annotate(
'',
xy=incumbent_path[i + 1],
xytext=incumbent_path[i],
arrowprops=dict(arrowstyle="->", color='black', linestyle='solid'),
)
for i in exploration:
plt.annotate(
'',
xy=i[1],
xytext=i[0],
arrowprops=dict(arrowstyle="->", color='black', linestyle='dotted'),
)
# Create a custom legend for the arrow
custom_line1 = [
Line2D(
[0],
[0],
color='black',
lw=1,
linestyle='solid',
marker='>',
markeredgewidth=0.5,
markersize=4,
),
Line2D(
[0],
[0],
color='black',
lw=1,
linestyle='dotted',
marker='>',
markeredgewidth=0.5,
markersize=4,
),
]
# Add the legend to the plot
plt.legend(custom_line1, ['Incumbent', 'Exploration'])
cbar = plt.colorbar(sc)
cbar.set_label('Objective function', rotation=90)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.savefig(file_name)
plt.figure().clear()
feasible_solution = {
(1, 2): -197.14013122689622,
(1, 3): -206.36041265432806,
(1, 4): -212.00878719112268,
(1, 5): -207.62611633572016,
(1, 6): -196.93118428995865,
(1, 7): -178.63847525562682,
(1, 8): -146.87850122234687,
(1, 9): -87.5338894428716,
(2, 3): -117.07438084784795,
(2, 4): -137.1797042946188,
(2, 5): -192.870848809807,
(2, 6): -192.88392569521721,
(2, 7): -175.94473700875903,
(2, 8): -144.71276519403037,
(2, 9): -85.82696130620648,
(3, 4): -77.19743879461578,
(3, 5): -88.41538101128177,
(3, 6): -119.38309938589616,
(3, 7): -170.89539354574913,
(3, 8): -141.82503814335138,
(3, 9): -83.55206301486514,
(4, 5): -55.81190616713566,
(4, 6): -62.4732860007934,
(4, 7): -77.86237831841856,
(4, 8): -135.07901900226858,
(4, 9): -80.51745201314861,
(5, 6): -43.41238657553521,
(5, 7): -47.28320969606174,
(5, 8): -54.212220237141665,
(5, 9): -66.30029047415469,
(6, 7): -36.01889379296989,
(6, 8): -37.96970292827284,
(6, 9): -39.58228460866401,
(7, 8): -31.679373632369185,
(7, 9): -32.196321090299925,
(8, 9): -29.327202909495576,
(9, 9): -28.596739202011523,
}
feas_x = []
feas_y = []
objs = []
for key in feasible_solution:
feas_x.append(key[0])
feas_y.append(key[1])
objs.append(feasible_solution[key])
# Plot search path of LD-SDA L2
incumbent_path = [(1, 2), (1, 3), (1, 4)]
exploration = [[(1, 4), (1, 5)], [(1, 4), (2, 4)]]
visualize_dsda(
incumbent_path=incumbent_path,
exploration=exploration,
feas_x=feas_x,
feas_y=feas_y,
objs=objs,
file_name='figures/search_path_LD-SDA_L2.pdf',
x_label='$Z_{s,1}$',
y_label='$Z_{s,2}$',
)
# Plot search path of LD-SDA Linf
incumbent_path = [(1, 2), (1, 3), (1, 4)]
exploration = [[(1, 2), (2, 3)], [(1, 4), (1, 5)], [(1, 4), (2, 4)], [(1, 4), (2, 5)]]
visualize_dsda(
incumbent_path=incumbent_path,
exploration=exploration,
feas_x=feas_x,
feas_y=feas_y,
objs=objs,
file_name='figures/search_path_LD-SDA_Linf.pdf',
x_label='$Z_{s,1}$',
y_label='$Z_{s,2}$',
)