import networkx as nx
# Create a graph
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (0, 2)])
# Formulate as QUBO
Q = {}
for u, v in G.edges():
Q[(u, u)] = Q.get((u, u), 0) + 1
Q[(v, v)] = Q.get((v, v), 0) + 1
Q[(u, v)] = Q.get((u, v), 0) - 2
# Convert to BQM and solve
bqm = dimod.BinaryQuadraticModel.from_qubo(Q)
model = dynex.BQM(bqm)
sampler = dynex.DynexSampler(model)
sampleset = sampler.sample(num_reads=100)
# Interpret results
solution = sampleset.first.sample
partition_0 = [node for node, val in solution.items() if val == 0]
partition_1 = [node for node, val in solution.items() if val == 1]
print(f"Partition 0: {partition_0}")
print(f"Partition 1: {partition_1}")
print(f"Cut size: {-sampleset.first.energy}")