#include <KS.hpp>
Public Member Functions | |
| Knapsack (int n, double cap, const double *c, const double *w) | |
| ~Knapsack () | |
| void | setCosts (const double *c) |
| void | setCapacity (double cap) |
| void | optimize (double lb=0.0, double minimp=1e-6) |
| Return true/false depending on whether the problem is feasible. | |
| const int * | getBestSol () const |
| const double | getBestVal () const |
Private Member Functions | |
| void | sortItems (const double *c, const double *w) |
Private Attributes | |
| double | cap_ |
| The capacity of the knapsack. | |
| int | n_ |
| The number of items. | |
| int * | perm_ |
| The permutation corresponding to the ordering (element perm[i] is the i-th in the original order. | |
| const double * | cost_ |
| The cost of each item (the order is after doing the cost/weight ordering). | |
| const double * | weight_ |
| The weight of the items (the order is after doing the cost/weight ordering). | |
| int * | x |
| The optimal solution in terms of the input order. | |
| double | z |
| The optimal solution value. | |
Definition at line 52 of file KS.hpp.
| Knapsack::Knapsack | ( | int | n, | |
| double | cap, | |||
| const double * | c, | |||
| const double * | w | |||
| ) | [inline] |
| Knapsack::~Knapsack | ( | ) | [inline] |
| void Knapsack::sortItems | ( | const double * | c, | |
| const double * | w | |||
| ) | [inline, private] |
Definition at line 55 of file KS.hpp.
References cost_, triplet::i, n_, perm_, ratioComp(), triplet::w, and weight_.
Referenced by Knapsack(), and setCosts().
| void Knapsack::setCosts | ( | const double * | c | ) | [inline] |
| void Knapsack::setCapacity | ( | double | cap | ) | [inline] |
| void Knapsack::optimize | ( | double | lb = 0.0, |
|
| double | minimp = 1e-6 | |||
| ) |
| const int* Knapsack::getBestSol | ( | ) | const [inline] |
| const double Knapsack::getBestVal | ( | ) | const [inline] |
double Knapsack::cap_ [private] |
The capacity of the knapsack.
Definition at line 82 of file KS.hpp.
Referenced by optimize(), and setCapacity().
int Knapsack::n_ [private] |
The number of items.
Definition at line 84 of file KS.hpp.
Referenced by optimize(), and sortItems().
int* Knapsack::perm_ [private] |
The permutation corresponding to the ordering (element perm[i] is the i-th in the original order.
Definition at line 87 of file KS.hpp.
Referenced by optimize(), sortItems(), and ~Knapsack().
const double* Knapsack::cost_ [private] |
The cost of each item (the order is after doing the cost/weight ordering).
Definition at line 90 of file KS.hpp.
Referenced by optimize(), sortItems(), and ~Knapsack().
const double* Knapsack::weight_ [private] |
The weight of the items (the order is after doing the cost/weight ordering).
Definition at line 93 of file KS.hpp.
Referenced by optimize(), setCosts(), sortItems(), and ~Knapsack().
int* Knapsack::x [private] |
The optimal solution in terms of the input order.
Definition at line 96 of file KS.hpp.
Referenced by getBestSol(), optimize(), and ~Knapsack().
double Knapsack::z [private] |
The optimal solution value.
Definition at line 98 of file KS.hpp.
Referenced by getBestVal(), and optimize().
1.4.7