【发布时间】:2023-03-09 16:30:01
【问题描述】:
我想按照 Barabasi-Albert 算法生成一个无标度网络,该算法涉及 growth 和 preferential attachment。
我使用以下脚本来创建网络:
import networkx as nx
import matplotlib.pyplot as plt
n=100 #Number of nodes
m=4 #Number of initial links
seed=100
G=nx.barabasi_albert_graph(n, m, seed)
nx.draw(G)
plt.show()
我对节点的定位方式不满意。我希望它们根据类似于常规网格的预定义方案定位,同时仍保持无标度特征:
我可以创建一个反映我的网格的位置字典:
pos = dict( (n, n) for n in G.nodes() )
labels = dict( ((i, j), i + (n-1-j) * n ) for i, j in G.nodes() )
inds=labels.keys()
vals=labels.values()
inds.sort()
vals.sort()
pos2=dict(zip(vals,inds))
我的问题:如何修改脚本以获得pos2中指定的节点位置的Barabasi-Albert图,也就是说根据我的网格?
【问题讨论】:
标签: python dictionary grid networkx