I need to solve a maxcut problem of a graph having 4 nodes and 5 edges, but I have to do it both with a quadratic solution and a linear one. I need to transform the quadratic maxcut problem to the linear one by adding some constraints but I have no idea how to do it.
This is the version I found of the quadratic one:
import numpy as np
from qiskit_optimization import QuadraticProgram
from qiskit_optimization.algorithms import MinimumEigenOptimizer
from qiskit import BasicAer
from qiskit.algorithms import QAOA
from qiskit.algorithms.optimizers import SPSA
# Generate a graph of 4 nodes
n = 4
graph = nx.Graph()
graph.add_nodes_from(np.arange(0, n, 1))
elist = [(0, 1, 1.0), (0, 2, 1.0), (0, 3, 1.0), (1, 2, 1.0), (2, 3, 1.0)]
graph.add_weighted_edges_from(elist)
# Compute the weight matrix from the graph
w = nx.adjacency_matrix(graph)
print(w)
# Formulate the problem as quadratic program
problem = QuadraticProgram()
_ = [problem.binary_var('x{}'.format(i)) for i in range(n)] # create n binary variables
linear = w.dot(np.ones(n))
quadratic = -w
problem.maximize(linear=linear, quadratic=quadratic)
print(problem.export_as_lp_string())
Now I should formulate the problem as linear, by adding the following constraints: (link of the image below)
<(https://i.stack.imgur.com/Cu00W.jpg)>
Thanks in advance for helping