Anders and Briegel in Python
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
667B

  1. import networkx as nx
  2. import numpy as np
  3. import graphstate
  4. import clifford
  5. import util
  6. class NXGraphState(graphstate.GraphState, nx.Graph):
  7. """ This is GraphState with NetworkX-like abilities """
  8. def __init__(self, *args, **kwargs):
  9. graphstate.GraphState.__init__(self, *args, **kwargs)
  10. def layout(self):
  11. """ Automatically lay out the graph """
  12. pos = nx.spring_layout(self, dim=3, scale=np.sqrt(self.order()))
  13. middle = np.average(pos.values(), axis=0)
  14. pos = {key: value - middle for key, value in pos.items()}
  15. for key, (x, y, z) in pos.items():
  16. self.node[key]["position"] = util.xyz(x, y, z)