Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Knapsack.H File Reference

Classical knapsack problem variants (0/1, unbounded, bounded). More...

#include <algorithm>
#include <concepts>
#include <cstddef>
#include <limits>
#include <type_traits>
#include <utility>
#include <ah-errors.H>
#include <tpl_array.H>
Include dependency graph for Knapsack.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Aleph::Knapsack_Item< W, V >
 An item for knapsack problems. More...
 
struct  Aleph::Knapsack_Result< V >
 Result of a knapsack computation. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::knapsack_detail
 

Functions

template<std::integral W>
size_t Aleph::knapsack_detail::to_size_checked (const W value, const char *fn_name, const char *field_name)
 
template<std::integral W, typename V >
Array< size_t > Aleph::knapsack_detail::extract_weights_checked (const Array< Knapsack_Item< W, V > > &items, const char *fn_name)
 
template<typename V , std::integral W>
Knapsack_Result< VAleph::knapsack_01 (const Array< Knapsack_Item< W, V > > &items, W capacity)
 0/1 Knapsack with item reconstruction.
 
template<typename V , std::integral W>
V Aleph::knapsack_01_value (const Array< Knapsack_Item< W, V > > &items, W capacity)
 0/1 Knapsack — value only (space-optimized).
 
template<typename V , std::integral W>
Knapsack_Result< VAleph::knapsack_unbounded (const Array< Knapsack_Item< W, V > > &items, W capacity)
 Unbounded Knapsack with reconstruction.
 
template<typename V , std::integral W>
Knapsack_Result< VAleph::knapsack_bounded (const Array< Knapsack_Item< W, V > > &items, const Array< size_t > &counts, W capacity)
 Bounded Knapsack with reconstruction.
 

Detailed Description

Classical knapsack problem variants (0/1, unbounded, bounded).

Provides dynamic programming solutions for:

  • 0/1 Knapsack: each item used at most once
  • Unbounded Knapsack: unlimited copies of each item
  • Bounded Knapsack: limited copies via binary decomposition

All functions support reconstruction of selected items.

Definition in file Knapsack.H.