Bin Packing

BinPackingProblem

The Solver

OperationsResearchModels.solve — Method
solve(problem::BinPackingProblem)::BinPackingResult

Solve a bin packing problem.

Description

Suppose we have a set of items with given sizes and a set of bins with given capacities. The goal is to assign each item to a bin such that the total size of items in each bin does not exceed its capacity, and the number of used bins is minimized. For example we have items with sizes [2, 3, 2, 3] and bins with capacities [5, 5]. The optimal assignment would be to place the first two items in the first bin and the last two items in the second bin.

Arguments

  • problem::BinPackingProblem: The bin packing problem to solve.

Returns

  • BinPackingResult: The result of the bin packing problem.

Example

problem = BinPackingProblem([2, 3, 2, 3], [5, 5])

result = solve(problem)

println("Used bins: ", result.used_bins)

println("Bin assignments: ", result.bin_assignments)


# Expected output:
# Used bins: [1, 2]
# Bin assignments: [1, 1, 2, 2] or [2, 2, 1, 1]
source

BinPackingResult

OperationsResearchModels.BinPacking.BinPackingResult — Type

BinPackingResult represents the result of a bin packing problem.

Fields

  • used_bins::Vector{Int}: The indices of the bins that are used.
  • bin_assignments::Vector{Int}: The bin assignment for each item.
  • model::JuMP.Model: The JuMP model used to solve the problem.
source