Good day,
I am trying to vizualize a supply chain network with Python Mesa. I have managed to vizualize the network, however there is no clear layout of the supply chain. I have defined the portrayal, with the folowing function:
def supply_network(G):
portrayal = dict()
portrayal["nodes"] = [
{
"id": node_id,
"size": 3,
"color": "#CC0000" if node_id[0] == 'S' else '#ff5100' if node_id[0] == 'W' else '#616BF9' if node_id[0] == 'A' else '#F9F142',
"label": None,
}
for (node_id, agents) in G.nodes.data("agent")
]
portrayal["edges"] = [
{"id": edge_id, "source": edge[0], "target": edge[1], 'distance': edge[2]['distance'], "color": "#000000"}
for edge_id, edge in enumerate(G.edges(data=True))
]
return portrayal
which provides the network in .json format.
[{'id': 0,
'source': 'S_C_1',
'target': 'WH_G_1',
'distance': 8699.71476,
'color': '#000000'},
{'id': 1,
'source': 'WH_G_1',
'target': 'S_C_2',
'distance': 8703.94796,
'color': '#000000'},
{'id': 2,
'source': 'WH_G_1',
'target': 'S_C_3',
'distance': 8708.564081,
'color': '#000000'},
{'id': 3,
'source': 'WH_G_1',
'target': 'S_C_4',
'distance': 8698.159713,
'color': '#000000'},
{'id': 4,
'source': 'WH_G_1',
'target': 'S_C_5',
'distance': 8751.0441,
'color': '#000000'}
and than the function is provided to the NetworkModule of mesa.
grid = NetworkModule(supply_network, 750, 750, library="sigma")
However, the output looks like this:
How to vizualize the network with a more clear layout? Do I need to provide weight of edges with distance?