The Classical Knapsack Problem Solver
The Solver
OperationsResearchModels.solve
— Methodsolve(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));
KnapsackProblem
OperationsResearchModels.Knapsack.KnapsackProblem
— Typeknapsack(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.
KnapsackResult
OperationsResearchModels.Knapsack.KnapsackResult
— TypeKnapsackResult
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.