How to seed graph generator in python-igraph?

╄→尐↘猪︶ㄣ 提交于 2020-01-24 18:01:26

问题


Is there any way to seed the following Watts-Strogatz graph generated using python-igraph, so that each time I run the script I get the same realization of SW graph ?

import igraph
graph = igraph.Graph.Watts_Strogatz(1, N, nei, p)

where N is the number of nodes, nei the number of connected neighbors, and p the rewiring probability.


回答1:


igraph uses the built-in RNG of Python so you can seed that:

In [1]: import random
In [2]: random.seed(1234)
In [3]: g=Graph.Watts_Strogatz(1, 100, 2, 0.25)
In [4]: random.seed(1234)
In [5]: g2=Graph.Watts_Strogatz(1, 100, 2, 0.25)
In [6]: g.get_edgelist() == g2.get_edgelist()
Out[6]:  True


来源:https://stackoverflow.com/questions/25718008/how-to-seed-graph-generator-in-python-igraph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!