ADS
Algorithms and Data Structures
Toggle main menu visibility
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
"
51
#include "
ADS/dictionary/ChainedHashTable.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
64
namespace
ADS
65
{
66
94
inline
std::pair< long , std::vector< std::size_t > >
95
knapsack
(
const
std::vector< long > & p ,
const
std::vector< long > & v ,
96
long
C );
97
120
inline
long
knapsackMemo
(
const
std::vector< long > & p ,
121
const
std::vector< long > & v ,
long
C ,
122
long
* solved =
nullptr
);
123
125
inline
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
/*--------------------------------------------------------------------------*/
ChainedHashTable.h
The hash table with lists of overflow of section 7.2.1, a realization of the DICTIONARY [see ADT....
Contract.h
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
ADS::knapsack
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
ADS::knapsackMemo
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...
ADS::zaino
long zaino(const std::vector< long > &p, const std::vector< long > &v, long C, long *solved=nullptr)
knapsackMemo() under the name of the book
ADS
Definition
ADT.h:96
ADS
optimization
Knapsack.h
Generated by
1.17.0