Guest User

Untitled

a guest
Feb 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. import networkx as nx
  2. import dwave_networkx as dnx
  3. import matplotlib.pyplot as plt
  4.  
  5. from dwave.system.samplers import DWaveSampler
  6. from dwave.system.composites import EmbeddingComposite
  7.  
  8. sampler = EmbeddingComposite(DWaveSampler(config_file='~/Library/Application Support/dwave/dwave.conf', solver='DW_2000Q_2_1'))
  9. G = nx.Graph()
  10. G.add_edges_from([(1,2),(1,4),(1,5),(2,3),(2,5),(2,7),(3,4),(3,6),(4,5),(5,6),(5,7)])
  11. S = dnx.maximum_independent_set(G, sampler=sampler, num_reads=100)
  12.  
  13. print('MIS size found is', len(S))
  14. print(S)
  15.  
  16. k = G.subgraph(S)
  17. notS = list(set(G.nodes())-set(S))
  18. othersubgraph = G.subgraph(notS)
  19. pos = nx.spring_layout(G)
  20.  
  21. plt.figure()
  22. nx.draw(G, pos=pos)
  23. nx.draw(k, pos=pos)
  24. nx.draw(othersubgraph, pos=pos, node_cplor='b')
  25. plt.show()
Add Comment
Please, Sign In to add comment