The Classical Knapsack Problem Solver
KnapsackProblem
OperationsResearchModels.Knapsack.KnapsackProblem — TypeKnapsackProblemDescription
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.
The Solver
OperationsResearchModels.solve — Methodsolve(problem::KnapsackProblem)::KnapsackResultDescription
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
values = [10, 20, 30, 40, 50];
weights = [1, 2, 3, 4, 5];
capacity = 10;
solve(KnapsackProblem(values, weights, capacity));KnapsackResult
OperationsResearchModels.Knapsack.KnapsackResult — TypeKnapsackResultDescription
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.