The Classical Knapsack Problem Solver

The Solver

OperationsResearchModels.solveMethod
solve(problem::KnapsackProblem)::KnapsackResult

Description

Solves the knapsack problem.

Arguments

  • problem::KnapsackProblem: The problem in type of KnapsackProblem.

Output

  • KnapsackResult: The custom data type that holds selected items, model, and objective value.

Example

julia> values = [10, 20, 30, 40, 50];
julia> weights = [1, 2, 3, 4, 5];
julia> capacity = 10;
julia> solve(KnapsackProblem(values, weights, capacity));
source

KnapsackProblem

OperationsResearchModels.Knapsack.KnapsackProblemType
knapsack(values::Vector{Float64}, weights::Vector{Float64}, capacity::Float64)::KnapsackResult

Description

Defines the knapsack problem.

Fields

  • values::Vector{Float64}: The values of the items.
  • weights::Vector{Float64}: The weights of the items.
  • capacity::Float64: The maximum capacity of the knapsack.

Output

  • KnapsackResult: The custom data type that holds selected items, model, and objective value.
source

KnapsackResult

OperationsResearchModels.Knapsack.KnapsackResultType
KnapsackResult

Description

A structure to hold the result of the knapsack problem.

Fields

  • selected: A vector of booleans indicating which items are selected.
  • model: The JuMP model used to solve the problem.
  • objective: The objective value of the model.
source