ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Knapsack.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File Knapsack.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
38/*--------------------------------------------------------------------------*/
39/*----------------------------- DEFINITIONS --------------------------------*/
40/*--------------------------------------------------------------------------*/
41
42#ifndef __ADS_Knapsack
43 #define __ADS_Knapsack
44/* self-identification: #endif constant */
45
46/*--------------------------------------------------------------------------*/
47/*------------------------------ INCLUDES ----------------------------------*/
48/*--------------------------------------------------------------------------*/
49
50#include "ADS/Contract.h"
52
53#include <algorithm>
54#include <cstddef>
55#include <deque>
56#include <limits>
57#include <utility>
58#include <vector>
59
60/*--------------------------------------------------------------------------*/
61/*--------------------------- NAMESPACE ------------------------------------*/
62/*--------------------------------------------------------------------------*/
63
64namespace ADS
65{
66
94inline std::pair< long , std::vector< std::size_t > >
95knapsack( const std::vector< long > & p , const std::vector< long > & v ,
96 long C );
97
120inline long knapsackMemo( const std::vector< long > & p ,
121 const std::vector< long > & v , long C ,
122 long * solved = nullptr );
123
125inline long zaino( const std::vector< long > & p ,
126 const std::vector< long > & v , long C ,
127 long * solved = nullptr );
128
129/*--------------------------------------------------------------------------*/
130
131} // end( namespace ADS )
132
133/*--------------------------------------------------------------------------*/
134/*-------------------------- IMPLEMENTATION --------------------------------*/
135/*--------------------------------------------------------------------------*/
136
137#include "ADS/optimization/impl/Knapsack.tpp"
138
139/*--------------------------------------------------------------------------*/
140
141#endif /* Knapsack.h included */
142
143/*--------------------------------------------------------------------------*/
144/*-------------------------- End File Knapsack.h ---------------------------*/
145/*--------------------------------------------------------------------------*/
The hash table with lists of overflow of section 7.2.1, a realization of the DICTIONARY [see ADT....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::pair< long, std::vector< std::size_t > > knapsack(const std::vector< long > &p, const std::vector< long > &v, long C)
the best profit and a set of objects, by places, of the 0-1 knapsack
long knapsackMemo(const std::vector< long > &p, const std::vector< long > &v, long C, long *solved=nullptr)
the best profit by memoization in a hash table (the zaino() of the book); the number of subproblems s...
long zaino(const std::vector< long > &p, const std::vector< long > &v, long C, long *solved=nullptr)
knapsackMemo() under the name of the book
Definition ADT.h:96