English
Languages
English
Bengali
Japanese
Spanish



Knapsack

class Knapsack(values, weights, max_weight)[source]

Bases: OptimizationApplication

Optimization application for the “knapsack problem” [1].

References

[1]: “Knapsack problem”, https://en.wikipedia.org/wiki/Knapsack_problem

Parameters:
  • 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

Methods

interpret(result)

Interpret a result as item indices

to_quadratic_program()

Convert a knapsack problem instance into a QuadraticProgram