Skip to content

Instantly share code, notes, and snippets.

@adamobeng
Created March 8, 2013 22:28
Show Gist options
  • Save adamobeng/5120436 to your computer and use it in GitHub Desktop.
Save adamobeng/5120436 to your computer and use it in GitHub Desktop.
Response to this SOCNET post <http://lists.ufl.edu/cgi-bin/wa?A2=ind1303&L=SOCNET&T=0&F=&S=&P=185750> Copyright (C) 2013 Adam Obeng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limit…
strict digraph "fast_gnp_random_graph(10,0.2)" {
1 -> 0 [weight=0.85784681863];
1 -> 9 [weight=0.446412404196];
1 -> 6 [weight=0.154317919969];
2 -> 5 [weight=0.625265147359];
2 -> 6 [weight=0.646490491015];
3 -> 0 [weight=0.0314493433996];
3 -> 1 [weight=0.679579531344];
4 -> 5 [weight=0.839968183284];
5 -> 1 [weight=0.325702378388];
5 -> 6 [weight=0.202474697063];
5 -> 7 [weight=0.541832673518];
6 -> 0 [weight=0.896564262162];
6 -> 7 [weight=0.217043461536];
7 -> 0 [weight=0.305489723841];
7 -> 1 [weight=0.858152144914];
7 -> 8 [weight=0.142028663227];
7 -> 9 [weight=0.946092301818];
9 -> 8 [weight=0.626423028336];
}
import networkx as nx
import random
n = 10 # `n` is the number of nodes
p = 0.2 # p is the probability of edge existing
G = nx.fast_gnp_random_graph(n, p, directed=True)
for e in G.edges_iter():
# We're not actually adding edges, just updating the weight on all of the
# edges which already exist
# The `[e]` is because add_edges_from() expects a list of edge tuples...
G.add_edges_from([e], weight=random.random())
nx.write_dot(G, 'graph.dot')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment