Created
April 20, 2020 16:00
-
-
Save paralax/63a1bb57972f2e064321cc0703e3449d to your computer and use it in GitHub Desktop.
playing around with networkx and wolfram's physics thinking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import matplotlib.pyplot as plt | |
g = nx.DiGraph(((1,2), (2,3), (3,4), (2,4))) | |
def wolfram(g): | |
ns = [ (x, n) for x,n in g.out_degree() if n == 2 ] | |
print(list(ns)) | |
nns = [] | |
for x, _ in ns: | |
print(list(g.successors(x))) | |
y, z = list(g.successors(x)) | |
g.remove_edge(x,y) | |
g.remove_edge(x,z) | |
w = max(g.nodes()) + 1 | |
nns.extend([(x,z), (x,w), (y,w), (z,w)]) | |
g.add_edges_from(nns) | |
return g | |
for _ in range(10): | |
g = wolfram(g) | |
nx.draw(g, pos=nx.spring_layout(g), node_size=1, arrows=False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment