Вот некоторый код для добавления весов ребер или получения случайных положений узлов (возможно, вы хотите их масштабировать).
import networkx as nx
import random
num_nodes = 10
prob = .25
G = nx.erdos_renyi_graph(n=num_nodes, p=prob)
# you need to add this in the __init__ of VirusOnNetwork
for u, v in G.edges():
# add random weights between 0 and 10
G[u][v]["weight"] = random.random() * 10
# you can access these weights in the same way (G[from_node][target_node]["weight"]
print(G.edges(data=True))
# [(0, 5, {'weight': 2.3337749464751454}), (0, 9, {'weight': 6.127630949347937}), (1, 4, {'weight': 9.048896640242369}), (2, 4, {'weight': 1.4236964132196228}), (2, 6, {'weight': 4.749936581386136}), (2, 9, {'weight': 2.037644705935693}), (3, 5, {'weight': 2.296192134297448}), (3, 7, {'weight': 1.5250362478641677}), (3, 9, {'weight': 7.362866019415747}), (4, 6, {'weight': 7.365668938333058}), (5, 6, {'weight': 1.1855367672698724}), (5, 8, {'weight': 3.219373770451519}), (7, 9, {'weight': 4.025563800958256})]
# alternative node positions
# you can store them in the graph or as separate attribute of your model
pos = nx.random_layout(G)
print(pos)
#{0: array([0.8604371 , 0.19834588], dtype=float32), 1: array([0.13099413, 0.97313595], dtype=float32), 2: array([0.30455875, 0.8844262 ], dtype=float32), 3: array([0.575425, 0.517468], dtype=float32), 4: array([0.7437008 , 0.89525336], dtype=float32), 5: array([0.9664812 , 0.21694745], dtype=float32), 6: array([0.89979964, 0.33603832], dtype=float32), 7: array([0.7894464, 0.7614578], dtype=float32), 8: array([0.44350627, 0.9081728 ], dtype=float32), 9: array([0.8049214 , 0.20761919], dtype=float32)}
# you can use this position for visualisation with networkx
nx.draw(G, pos)