Expand description
0/1 Knapsack and fractional knapsack solvers.
Provides exact DP, greedy heuristic, branch-and-bound, and the classical
fractional (continuous) knapsack. Multi-dimensional knapsack is also
supported via MultiKnapsackProblem.
Structs§
- Knapsack
Item - A single knapsack item with integer weight and value.
- Multi
Knapsack Item - An item for the multi-dimensional knapsack.
Functions§
- fractional_
knapsack - Solve the fractional knapsack in O(n log n) via greedy value-density sort.
- knapsack_
branch_ bound - Exact branch-and-bound for 0/1 knapsack with LP-relaxation bounding.
- knapsack_
dp - Solve the 0/1 knapsack exactly using bottom-up DP in O(n · W) time and space.
- knapsack_
greedy - Greedy 0/1 knapsack: sort by value/weight ratio and greedily include items.
- multi_
knapsack_ greedy - Multi-dimensional 0/1 knapsack solved by greedy + local search.
Type Aliases§
- Knapsack
Result - Result type for knapsack operations.