# qiskit_optimization.applications.number_partition のソースコード

```# This code is part of Qiskit.
#
# (C) Copyright IBM 2018, 2021.
#
# obtain a copy of this license in the LICENSE.txt file in the root directory
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""An application class for the number partitioning."""

from typing import List, Union

import numpy as np
from docplex.mp.model import Model

from qiskit_optimization.algorithms import OptimizationResult
from qiskit_optimization.translators import from_docplex_mp
from .optimization_application import OptimizationApplication

[ドキュメント]class NumberPartition(OptimizationApplication):
"""Optimization application for the "number partition"  problem.

References:
: "Partition problem",
https://en.wikipedia.org/wiki/Partition_problem
"""

def __init__(self, number_set: List[int]) -> None:
"""
Args:
number_set: A list of integers
"""
self._number_set = number_set

"""Convert a number partitioning problem instance into a

Returns:
from the number partitioning problem instance.
"""
mdl = Model(name="Number partitioning")
x = {i: mdl.binary_var(name=f"x_{i}") for i in range(len(self._number_set))}
mdl.sum(num * (-2 * x[i] + 1) for i, num in enumerate(self._number_set)) == 0
)
op = from_docplex_mp(mdl)
return op

[ドキュメント]    def interpret(self, result: Union[OptimizationResult, np.ndarray]) -> List[List[int]]:
"""Interpret a result as a list of subsets

Args:
result: The calculated result of the problem

Returns:
A list of subsets whose sum is the half of the total.
"""
x = self._result_to_x(result)
num_subsets = [[], []]  # type: List[List[int]]
for i, value in enumerate(x):
if value == 0:
num_subsets.append(self._number_set[i])
else:
num_subsets.append(self._number_set[i])
return num_subsets
```