@@ -169,43 +169,25 @@ def draw_graph(self, plot=False, path=None):
169
169
None: The method saves the plot as an image at the specified path.
170
170
"""
171
171
g = nx .from_numpy_array (self .topology )
172
- # pos = nx.layout.spectral_layout(g)
173
- # pos = nx.spring_layout(g, pos=pos, iterations=50)
174
172
pos = nx .spring_layout (g , k = 0.15 , iterations = 20 , seed = 42 )
175
173
176
174
fig = plt .figure (num = "Network topology" , dpi = 100 , figsize = (6 , 6 ), frameon = False )
177
175
ax = fig .add_axes ([0 , 0 , 1 , 1 ])
178
176
ax .set_xlim ([- 1.3 , 1.3 ])
179
177
ax .set_ylim ([- 1.3 , 1.3 ])
180
- # ax.axis('off')
181
178
labels = {}
182
179
color_map = []
183
180
for k in range (self .n_nodes ):
184
181
role = str (self .nodes [k ][2 ])
185
182
color_map .append (self .get_node_color (role ))
186
183
labels [k ] = f"P{ k } \n " + str (self .nodes [k ][0 ]) + ":" + str (self .nodes [k ][1 ])
187
184
188
- # nx.draw_networkx_nodes(g, pos_shadow, node_color='k', alpha=0.5)
189
185
nx .draw_networkx_nodes (g , pos , node_color = color_map , linewidths = 2 )
190
186
nx .draw_networkx_labels (g , pos , labels , font_size = 10 , font_weight = "bold" )
191
187
nx .draw_networkx_edges (g , pos , width = 2 )
192
- # plt.margins(0.0)
193
188
194
189
self .add_legend ([str (node [2 ]) for node in self .nodes ])
195
-
196
- # plt.scatter([], [], c="green", label='Central Server')
197
- # plt.scatter([], [], c="orange", label='Aggregator')
198
- # plt.scatter([], [], c="#6182bd", label='Trainer')
199
- # plt.scatter([], [], c="purple", label='Proxy')
200
- # plt.scatter([], [], c="red", label='Idle')
201
- # import sys
202
- # if path is None:
203
- # if not os.path.exists(f"{sys.path[0]}/logs/{self.scenario_name}"):
204
- # os.makedirs(f"{sys.path[0]}/logs/{self.scenario_name}")
205
- # plt.savefig(f"{sys.path[0]}/logs/{self.scenario_name}/topology.png", dpi=100, bbox_inches="tight", pad_inches=0)
206
- # else:
207
190
plt .savefig (f"{ path } " , dpi = 100 , bbox_inches = "tight" , pad_inches = 0 )
208
- # plt.gcf().canvas.draw()
209
191
plt .close ()
210
192
211
193
def generate_topology (self ):
0 commit comments