BinPacking#

class BinPacking(weights, max_weight, max_number_of_bins=None)[source]#

Bases: OptimizationApplication

Optimization application for the “bin packing” [1] problem.

References

[1]: “Bin packing”, https://en.wikipedia.org/wiki/Bin_packing_problem

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

  • max_weight (int) – The maximum bin weight capacity

  • max_number_of_bins (int | None) – The maximum number of bins by default equal to the number of items

Methods

get_figure(result)[source]#

Get plot of the solution of the Bin Packing Problem.

Parameters:

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

Returns:

A plot of the solution, where x and y represent the bins and sum of the weights respectively.

Return type:

fig

interpret(result)[source]#

Interpret a result as item indices

Parameters:

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

Returns:

A list of lists with the items in each bin

Return type:

items_in_bins

static sample_most_likely(state_vector)#

Compute the most likely binary string from state vector.

Parameters:

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

Returns:

binary string as numpy.ndarray of ints.

Raises:

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

Return type:

ndarray

to_quadratic_program()[source]#

Convert a bin packing problem instance into a QuadraticProgram

Returns:

The QuadraticProgram created from the bin packing problem instance.

Return type:

QuadraticProgram