dimod.generators.random_multi_knapsack#

random_multi_knapsack(num_items: int, num_bins: int, seed: int = 32, value_range: Tuple[int, int] = (10, 50), weight_range: Tuple[int, int] = (10, 50)) ConstrainedQuadraticModel[source]#

Generate a constrained quadratic model encoding a multiple-knapsack problem.

Given the number of items and the number of bins, generates a multiple-knapsack problem, formulated as a ConstrainedQuadraticModel. Values and weights for each item are uniformly sampled within the specified ranges. Capacities of bins are randomly assigned.

Parameters:
  • num_items – Number of items.

  • num_bins – Number of bins.

  • seed – Seed for RNG.

  • value_range – Range of the randomly generated values for each item.

  • weight_range – Range of the randomly generated weights for each item.

Returns:

A constrained quadratic model encoding the multiple-knapsack problem. Variables are labelled as x_{i}_{j}, where x_{i}_{j} == 1 means that item i is placed in bin j.