Skip to content

Instantly share code, notes, and snippets.

@paralax
Created April 20, 2020 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paralax/63a1bb57972f2e064321cc0703e3449d to your computer and use it in GitHub Desktop.
Save paralax/63a1bb57972f2e064321cc0703e3449d to your computer and use it in GitHub Desktop.
playing around with networkx and wolfram's physics thinking
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