2 import matplotlib
.pyplot
as plt
3 from matplotlib
.font_manager
import FontProperties
11 def plot_exp1(f_DAGP
, f_DAGP_2
, f_asy_dagp
, f_asy_dagp_2
, max_iter_syn
, node_comp_time_exp1
, \
12 node_comp_time_exp1_2
, neighbors
, Delay_mat_dagp
, Delay_mat_dagp_2
, T_active_exp1
, \
13 T_active_exp1_2
, current_dir
, plot_iter
=20000, save_results_folder
='exp1', plot_time
=43000, itrs
=1750):
15 matplotlib
.rcParams
['text.usetex'] = True
16 plt
.rcParams
['axes.linewidth'] = 2
17 plt
.rcParams
["font.family"] = "Arial"
18 plt
.rcParams
['text.latex.preamble'] = r
'\usepackage{amsmath}'
19 plt
.rcParams
['pdf.fonttype'] = 42
20 font
= FontProperties()
26 if not os
.path
.exists(save_results_folder
):
27 os
.makedirs(save_results_folder
)
29 plt
.figure(1, figsize
=(7, 5))
30 plt
.tick_params(labelsize
=17, width
=3)
31 plt
.plot(f_DAGP
[:plot_iter
], '-m', markevery
= mark_every
,linewidth
= linewidth
)
32 plt
.plot(f_DAGP_2
[:plot_iter
], '--m', markevery
= mark_every
,linewidth
= linewidth
)
33 plt
.plot(f_asy_dagp
[:plot_iter
], '-y', markevery
= mark_every
,linewidth
= linewidth
)
34 plt
.plot(f_asy_dagp_2
[:plot_iter
], '--y', markevery
= mark_every
,linewidth
= linewidth
)
35 plt
.legend([r
'\textbf{DAGP}', r
'\textbf{Throttled-DAGP}', r
'\textbf{ASY-DAGP}', r
'\textbf{ASY-Throttled-DAGP}'], prop
={'size': 16})
36 plt
.xlabel(r
'\textbf{Iterations}', fontsize
=16)
37 plt
.ylabel(r
'\textbf{Objective value}', fontsize
=16)
39 path
= os
.path
.join(save_results_folder
, 'iter')
40 plt
.savefig( path
+ ".pdf", format
= 'pdf')
42 T_sync
= np
.zeros(max_iter_syn
+1)
43 for i
in range(1,max_iter_syn
+1):
44 tmp1
= node_comp_time_exp1
[:,i
]
45 tmp2
= np
.multiply(neighbors
, Delay_mat_dagp
[:,:,i
])
46 tmp3
= np
.max(tmp2
, axis
=0)
49 T_sync
[i
] = T_sync
[i
-1] + tmp5
51 T_sync_2
= np
.zeros(max_iter_syn
+1)
52 for i
in range(1,max_iter_syn
+1):
53 tmp1
= node_comp_time_exp1_2
[:,i
]
54 tmp2
= np
.multiply(neighbors
, Delay_mat_dagp_2
[:,:,i
])
55 tmp3
= np
.max(tmp2
, axis
=0)
58 T_sync_2
[i
] = T_sync_2
[i
-1] + tmp5
60 plt
.figure(2, figsize
=(7, 5))
61 plt
.tick_params(labelsize
=17, width
=3)
62 plt
.plot(T_sync
[:itrs
], f_DAGP
[:itrs
], '-m', markevery
= mark_every
,linewidth
= linewidth
)
63 plt
.plot(T_sync_2
[:itrs
], f_DAGP
[:itrs
], '--m', markevery
= mark_every
,linewidth
= linewidth
)
64 plt
.plot(T_active_exp1
[:plot_time
], f_asy_dagp
[:plot_time
], '-y', markevery
= mark_every
,linewidth
= linewidth
)
65 plt
.plot(T_active_exp1_2
[:plot_time
], f_asy_dagp_2
[:plot_time
], '--y', markevery
= mark_every
,linewidth
= linewidth
)
66 plt
.legend([r
'\textbf{DAGP}', r
'\textbf{Throttled-DAGP}', r
'\textbf{ASY-DAGP}', r
'\textbf{ASY-Throttled-DAGP}'], prop
={'size': 16})
67 plt
.xlabel(r
'\textbf{Time units}', fontsize
=16)
68 plt
.ylabel(r
'\textbf{Objective value}', fontsize
=16)
70 path
= os
.path
.join(save_results_folder
, 'time')
71 plt
.savefig( path
+ ".pdf", format
= 'pdf')
77 def plot_exp2(T_active_exp2
, res_F_asy_dagp
, res_F_asyspa
, res_F_appg
, current_dir
, save_results_folder
, plot_iter
=10050):
78 matplotlib
.rcParams
['text.usetex'] = True
79 plt
.rcParams
['axes.linewidth'] = 2
80 plt
.rcParams
["font.family"] = "Arial"
81 plt
.rcParams
['text.latex.preamble'] = r
'\usepackage{amsmath}'
82 plt
.rcParams
['pdf.fonttype'] = 42
83 font
= FontProperties()
85 font2
= FontProperties()
91 if not os
.path
.exists(save_results_folder
):
92 os
.makedirs(save_results_folder
)
93 plt
.figure(4, figsize
=(7, 5))
94 plt
.tick_params(labelsize
=17, width
=3)
95 plt
.plot(T_active_exp2
[:plot_iter
], res_F_asy_dagp
[:plot_iter
], '-oy', markevery
= mark_every
,linewidth
= linewidth
)
96 plt
.plot(T_active_exp2
[:plot_iter
], res_F_asyspa
[:plot_iter
], '-ob', markevery
= mark_every
,linewidth
= linewidth
)
97 plt
.plot(T_active_exp2
[:plot_iter
], res_F_appg
[:plot_iter
], '-og', markevery
= mark_every
,linewidth
= linewidth
)
98 plt
.legend([r
'\textbf{ASY-DAGP}', r
'\textbf{ASY-SPA}', r
'\textbf{APPG}'], prop
={'size': 16})
99 plt
.xlabel(r
'\textbf{Time units}', fontsize
=16)
100 plt
.ylabel(r
'\textbf{Optimality gap}', fontsize
=16)
102 plt
.ylim( 10**-14, 1)
104 path
= os
.path
.join(save_results_folder
, 'comparison_unconstianedd')
105 plt
.savefig( path
+ ".pdf", format
= 'pdf')
111 def plot_exp3(T_active_exp3
, f_asy_dagp
, f_asy_pgex
, current_dir
, save_results_folder
, plot_iter
=5000):
112 matplotlib
.rcParams
['text.usetex'] = True
113 plt
.rcParams
['axes.linewidth'] = 2
114 plt
.rcParams
["font.family"] = "Arial"
115 plt
.rcParams
['text.latex.preamble'] = r
'\usepackage{amsmath}'
116 plt
.rcParams
['pdf.fonttype'] = 42
117 font
= FontProperties()
122 os
.chdir(current_dir
)
123 if not os
.path
.exists(save_results_folder
):
124 os
.makedirs(save_results_folder
)
126 plt
.figure(1, figsize
=(7, 5))
127 plt
.tick_params(labelsize
=17, width
=3)
128 plt
.plot(T_active_exp3
[:plot_iter
], f_asy_dagp
[:plot_iter
], '-y', markevery
= mark_every
,linewidth
= linewidth
)
129 plt
.plot(T_active_exp3
[:plot_iter
], f_asy_pgex
[:plot_iter
], '-r', markevery
= mark_every
,linewidth
= linewidth
)
130 plt
.legend([r
'\textbf{ASY-DAGP}', r
'\textbf{ASY-PG-EXTRA}'], prop
={'size': 16})
131 plt
.xlabel(r
'\textbf{Time Units}', fontsize
=16)
132 plt
.ylabel(r
'\textbf{Optimality Gap}', fontsize
=16)
136 path
= os
.path
.join(save_results_folder
, 'dagp_vs_asy_pgExtra')
137 plt
.savefig( path
+ ".pdf", format
= 'pdf')
143 def plot_exp4(T_active_exp4
, f_asy_dagp0
, f_asy_dagp1
, f_asy_dagp2
, f_asy_dagp3
, current_dir
, save_results_folder
, plot_iter
=7000):
144 matplotlib
.rcParams
['text.usetex'] = True
145 plt
.rcParams
['axes.linewidth'] = 2
146 plt
.rcParams
["font.family"] = "Arial"
147 plt
.rcParams
['text.latex.preamble'] = r
'\usepackage{amsmath}'
148 plt
.rcParams
['pdf.fonttype'] = 42
149 font
= FontProperties()
154 os
.chdir(current_dir
)
155 if not os
.path
.exists(save_results_folder
):
156 os
.makedirs(save_results_folder
)
158 plt
.figure(3, figsize
=(7, 5))
159 plt
.tick_params(labelsize
=17, width
=3)
160 plt
.plot(T_active_exp4
[:plot_iter
], f_asy_dagp0
[:plot_iter
], '-oy', markevery
= mark_every
,linewidth
= linewidth
)
161 plt
.plot(T_active_exp4
[:plot_iter
], f_asy_dagp1
[:plot_iter
], '-ok', markevery
= mark_every
,linewidth
= linewidth
)
162 plt
.plot(T_active_exp4
[:plot_iter
], f_asy_dagp2
[:plot_iter
], '-or', markevery
= mark_every
,linewidth
= linewidth
)
163 plt
.plot(T_active_exp4
[:plot_iter
], f_asy_dagp3
[:plot_iter
], '-oc', markevery
= mark_every
,linewidth
= linewidth
)
164 plt
.legend([r
'\textbf{ASY-DAGP, $p=0.00$}', r
'\textbf{ASY-DAGP, $p=0.25$}', r
'\textbf{ASY-DAGP, $p=0.50$}', r
'\textbf{ASY-DAGP, $p=0.75$}'], prop
={'size': 16})
165 plt
.xlabel(r
'\textbf{Time units}', fontsize
=16)
166 plt
.ylabel(r
'\textbf{Objective value}', fontsize
=16)
168 path
= os
.path
.join(save_results_folder
, 'drop_iter')
169 plt
.savefig( path
+ ".pdf", format
= 'pdf')