Knapsack#

class Knapsack(values, weights, max_weight)[ソース]#

ベースクラス: OptimizationApplication

Optimization application for the 「knapsack problem」 [1].

参照

[1]: 「Knapsack problem」, https://en.wikipedia.org/wiki/Knapsack_problem

パラメータ:
  • values (List[int]) – A list of the values of items

  • weights (List[int]) – A list of the weights of items

  • max_weight (int) – The maximum weight capacity

Attributes

max_weight#

Getter of max_weight

戻り値:

The maximal weight for the knapsack problem

Methods

interpret(result)[ソース]#

Interpret a result as item indices

パラメータ:

result (OptimizationResult | ndarray) – The calculated result of the problem

戻り値:

A list of items whose corresponding variable is 1

戻り値の型:

List[int]

static sample_most_likely(state_vector)#

Compute the most likely binary string from state vector.

パラメータ:

state_vector (QuasiDistribution | Statevector | ndarray | Dict) – state vector or counts or quasi-probabilities.

戻り値:

binary string as numpy.ndarray of ints.

例外:

ValueError – if state_vector is not QuasiDistribution, Statevector, np.ndarray, or dict.

戻り値の型:

ndarray

to_quadratic_program()[ソース]#

Convert a knapsack problem instance into a QuadraticProgram

戻り値:

The QuadraticProgram created from the knapsack problem instance.

戻り値の型:

QuadraticProgram