Number Partitioning Problem
Number Partitioning Problem is a problem to make two groups that sum of the each groups are the same.
Reference
Ising formulations of many NP problems
Andrew Lucas
Ising hamiltonian
And then we create a hamiltonian of
It will be
Example
Let's try solve a simple example. Now we have a list of natural number
[3,6,5,6,5,2,6,8,5,8]
and we make two groups. The hamiltonian is very simple
#sum 38
num = [3,6,5,6,5,2,6,5]
from blueqat import vqe
from blueqat.pauli import Z
hamiltonian = (num[0]*Z(0)+num[1]*Z(1)+num[2]*Z(2)+num[3]*Z(3)+num[4]*Z(4)+num[5]*Z(5)+num[6]*Z(6)+num[7]*Z(7))**2
step = 2
result = vqe.Vqe(vqe.QaoaAnsatz(hamiltonian.simplify(), step)).run()
b = sum([x*y for (x,y) in zip(num, list(result.most_common(1)[0][0]))])
#answer 19
print(b)
result.most_common(12)
19
(((0, 1, 1, 1, 0, 1, 0, 0), 0.008320427578059642),
((0, 1, 0, 0, 1, 1, 1, 0), 0.008320427578059642),
((1, 0, 1, 1, 0, 0, 0, 1), 0.008320427578059642),
((1, 0, 0, 0, 1, 0, 1, 1), 0.008320427578059642),
((1, 0, 1, 1, 1, 0, 0, 0), 0.008320427578059638),
((1, 0, 1, 0, 1, 0, 1, 0), 0.008320427578059638),
((0, 1, 0, 1, 0, 1, 0, 1), 0.008320427578059638),
((0, 1, 0, 0, 0, 1, 1, 1), 0.008320427578059638),
((1, 1, 1, 0, 1, 0, 0, 0), 0.008320427578059637),
((0, 0, 0, 1, 0, 1, 1, 1), 0.008320427578059637),
((0, 1, 0, 1, 1, 1, 0, 0), 0.008320427578059635),
((1, 0, 1, 0, 0, 0, 1, 1), 0.008320427578059635))
Finally we got two groups the sum is each 19.