Reputation:
I need to generate a random graph with Watts and Strogatz. I am looking for an identical format to my real data. I have to save it in csv or txt file. It is more like Small World Network As per what i have read in the about Watts and Strogatz is it is undirected graph with no weights. But i need to generate undirected graph with weight.
Real data format
Node Node weight = time in seconds
453 645 343
453 645 533
645 8090 349
645 453 3563
564 645 3533
564 453 345
8090 453 563
8090 645 4525
564 8090 3533
The Degree is 1 and the two node pairs are connected for certain time and that is given in seconds. what is the best way to generate the graph data with Seed (0 to 4) in time (1 to 5), i.e. Seed0_time1 and so on till Seed4_time5. Five instances.
I understand it might be too broad but it would be great if someone can point me toward the right direction and with some code in support. I did look for help here i see hardly any posts that have been answered.
Upvotes: 1
Views: 6330
Reputation: 2590
Have you tried NetworkX? They have a bunch of these small world algorithms, including Watts-Strogatz, and they are fairly easy to use. If you really want an undirected graph with no weights, have a look at the set of Classic random graphs NetworkX can generate. But if you have to go with Watts-Strogatz, below is sample code for using it with NetworkX. Most of the random graph generators return a Graph
object, so here's documentation about the methods available for the Graph
.
import networkx as nx
watts_strogatz = nx.watts_strogatz_graph(200,2,0.15)
nx.nodes(watts_strogatz) # Prints out the nodes
Upvotes: 2