- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# KnapModel Class Reference

`#include <KnapModel.h>`

Inheritance diagram for KnapModel:

[legend]
Collaboration diagram for KnapModel:

[legend]
List of all members.

## Public Member Functions
| KnapModel ()
| KnapModel (int cap, std::vector< std::pair< int, int > > items, int *seq)
| ~KnapModel ()
int | getCapacity () const
| Get the capacity of the knapsack.
int | getNumItems () const
| Get the number of items in the knapsack.
int * | getSequence () const
| Get the sequence of items in the knapsack.
virtual void | readParameters (const int argnum, const char *const *arglist)
| Read in Alps and Knap parameters.
std::pair< int, int > | getItem (int i) const
| Get the size of item i.
void | setCapacity (int capacity)
| Set the capacity of the knapsack.
void | setSequence (const int *seq)
| Set the sequence of items in the knapsack.
void | addItem (int size, int cost)
| Set the size of item i.
void | readInstance (const char *dataFile)
| Read in the problem data.
void | orderItems ()
| Order the items based on their cost/size.
virtual AlpsEncoded * | encode () const
| The method that encodes the solution into a buffer.
virtual void | decodeToSelf (AlpsEncoded &)
| The method that decodes model data from the encoded form and fill member data.
## Private Attributes
int | capacity_
| Capacity of the knapsack.
std::vector< std::pair< int, int > > | items_
| List of sizes and profits of the items.
int * | sequence_
| The descent sequence based on ratio: profit/size.
KnapParams * | KnapPar_
| Knap parameters.

## Detailed Description

Definition at line 26 of file KnapModel.h.

## Constructor & Destructor Documentation

KnapModel::KnapModel | ( |  | ) | `[inline]`

Definition at line 44 of file KnapModel.h.

KnapModel::KnapModel | ( | int | cap,
|  | std::vector< std::pair< int, int > > | items,
|  | int * | seq |
| ) |  |  | `[inline]`

Definition at line 45 of file KnapModel.h.

References items_.

KnapModel::~KnapModel | ( |  | ) | `[inline]`

Definition at line 52 of file KnapModel.h.

References KnapPar_, and sequence_.

## Member Function Documentation

int KnapModel::getCapacity | ( |  | ) | const`[inline]`

Get the capacity of the knapsack.

Definition at line 61 of file KnapModel.h.

References capacity_.

int KnapModel::getNumItems | ( |  | ) | const`[inline]`

Get the number of items in the knapsack.

Definition at line 64 of file KnapModel.h.

References items_.

int* KnapModel::getSequence | ( |  | ) | const`[inline]`

Get the sequence of items in the knapsack.

Definition at line 67 of file KnapModel.h.

References sequence_.

virtual void KnapModel::readParameters | ( | const int | argnum,
|  | const char *const * | arglist |
| ) |  |  | `[inline, virtual]`

Read in Alps and Knap parameters.

Reimplemented from AlpsModel.

Definition at line 72 of file KnapModel.h.

References AlpsModel::AlpsPar_, AlpsParams::entry(), KnapPar_, AlpsParams::msgLevel, and AlpsParameterSet::readFromArglist().

std::pair<int, int> KnapModel::getItem | ( | int | i | ) | const`[inline]`

Get the size of item i.

Definition at line 83 of file KnapModel.h.

References items_, and sequence_.

void KnapModel::setCapacity | ( | int | capacity | ) | `[inline]`

Set the capacity of the knapsack.

Definition at line 88 of file KnapModel.h.

References capacity_.

void KnapModel::setSequence | ( | const int * | seq | ) |

Set the sequence of items in the knapsack.

void KnapModel::addItem | ( | int | size,
|  | int | cost |
| ) |  |  | `[inline]`

Set the size of item i.

Definition at line 94 of file KnapModel.h.

References items_.

void KnapModel::readInstance | ( | const char * | dataFile | ) | `[virtual]`

Read in the problem data.

Reimplemented from AlpsModel.

void KnapModel::orderItems | ( |  | ) |

Order the items based on their cost/size.

virtual AlpsEncoded* KnapModel::encode | ( |  | ) | const`[virtual]`

The method that encodes the solution into a buffer.

Reimplemented from AlpsKnowledge.

virtual void KnapModel::decodeToSelf | ( | AlpsEncoded & |  | ) | `[virtual]`

The method that decodes model data from the encoded form and fill member data.

Reimplemented from AlpsModel.

## Member Data Documentation

int KnapModel::capacity_`[private]`

Capacity of the knapsack.

Definition at line 31 of file KnapModel.h.

Referenced by getCapacity(), and setCapacity().

std::vector< std::pair<int, int> > KnapModel::items_`[private]`

List of sizes and profits of the items.

Definition at line 34 of file KnapModel.h.

Referenced by addItem(), getItem(), getNumItems(), and KnapModel().

int* KnapModel::sequence_`[private]`

The descent sequence based on ratio: profit/size.

Definition at line 37 of file KnapModel.h.

Referenced by getItem(), getSequence(), and ~KnapModel().

KnapParams* KnapModel::KnapPar_`[private]`

Knap parameters.

Definition at line 40 of file KnapModel.h.

Referenced by readParameters(), and ~KnapModel().

The documentation for this class was generated from the following file:

- /home/coin/SVN-release/Blis-0.91.2/Alps/examples/Knap/KnapModel.h