Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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)