Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import networkx as nx
- import dwave_networkx as dnx
- import matplotlib.pyplot as plt
- from dwave.system.samplers import DWaveSampler
- from dwave.system.composites import EmbeddingComposite
- sampler = EmbeddingComposite(DWaveSampler(config_file='~/Library/Application Support/dwave/dwave.conf', solver='DW_2000Q_2_1'))
- G = nx.Graph()
- 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)])
- S = dnx.maximum_independent_set(G, sampler=sampler, num_reads=100)
- print('MIS size found is', len(S))
- print(S)
- k = G.subgraph(S)
- notS = list(set(G.nodes())-set(S))
- othersubgraph = G.subgraph(notS)
- pos = nx.spring_layout(G)
- plt.figure()
- nx.draw(G, pos=pos)
- nx.draw(k, pos=pos)
- nx.draw(othersubgraph, pos=pos, node_cplor='b')
- plt.show()
Add Comment
Please, Sign In to add comment