Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

networkx - Python Mesa - how to vizualize supply chain

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:

enter image description here

How to vizualize the network with a more clear layout? Do I need to provide weight of edges with distance?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...