Operational Research Library  1.0
Public Member Functions | List of all members
operational_research::KnapsackProblem Class Reference

#include <KnapsackProblem.h>

Inheritance diagram for operational_research::KnapsackProblem:
Inheritance graph
Collaboration diagram for operational_research::KnapsackProblem:
Collaboration graph

Public Member Functions

 KnapsackProblem (unsigned int objects, const std::vector< double > &weights, const std::vector< double > &profits, double capacity)
 Constructor. More...
 
 KnapsackProblem (unsigned int objects, double capacity, double minWeight, double maxWeight, double minProfit, double maxProfit, bool integerValues=false)
 Constructor. More...
 
 KnapsackProblem (const std::string &filename)
 Constructor. More...
 
void setData (unsigned int objects, const std::vector< double > &weights, const std::vector< double > &profits, double capacity)
 Setter for knapsack problem data. More...
 
void generateData (unsigned int objects, double capacity, double minWeight, double maxWeight, double minProfit, double maxProfit, bool integerValues=false)
 Generates knapsack problem data according to setup. More...
 
void readDataFromFile (const std::string &filename)
 Reads knapsack problem data from a file with a filename. More...
 
void writeDataToFile (const std::string &filename)
 Writes knapsack problem data to a file with a filename. More...
 
void showData ()
 Shows knapsack problem data. More...
 
double evaluateKP (const std::vector< unsigned int > &schedule)
 Evaluates knapsack problem. More...
 
double evaluateKP (const std::vector< unsigned int > &schedule, const std::string &filename)
 Evaluates knapsack problem to file with a filename. More...
 
double getCapacity () const
 Getter for knapsack capacity. More...
 
unsigned int getObjects () const
 Getter for number of objects. More...
 
const std::vector< double > & getProfits () const
 Getter for profits of objects. More...
 
const std::vector< double > & getWeights () const
 Getter for weights of objects. More...
 
- Public Member Functions inherited from operational_research::IData
virtual ~IData ()
 Virtual destructor. More...
 

Detailed Description

Author
Milan Hlinak
Date
04/14/15

Constructor & Destructor Documentation

operational_research::KnapsackProblem::KnapsackProblem ( unsigned int  objects,
const std::vector< double > &  weights,
const std::vector< double > &  profits,
double  capacity 
)

Constructor.

Parameters
objectsNumber of objects.
weightsWeights of objects.
profitsProfits of objects.
capacityKnapsack capacity.
Exceptions
std::invalid_argumentexception.
operational_research::KnapsackProblem::KnapsackProblem ( unsigned int  objects,
double  capacity,
double  minWeight,
double  maxWeight,
double  minProfit,
double  maxProfit,
bool  integerValues = false 
)

Constructor.

Parameters
objectsNumber of objects.
capacityKnapsack capacity.
minWeightMinimal weight of object.
maxWeightMaximal weight of object.
minProfitMinimal profit of object.
maxProfitMaximal profit of object.
integerValuesTrue if generated data is integer values, false if generated data is real values.
Exceptions
std::invalid_argumentexception.
operational_research::KnapsackProblem::KnapsackProblem ( const std::string &  filename)

Constructor.

Parameters
filenameFilename.
Exceptions
std::runtime_errorexception.
std::invalid_argumentexception.

Member Function Documentation

double operational_research::KnapsackProblem::evaluateKP ( const std::vector< unsigned int > &  schedule)

Evaluates knapsack problem.

Parameters
scheduleSchedule.
Returns
Cost function value for given schedule.
Exceptions
std::invalid_argumentexception.
double operational_research::KnapsackProblem::evaluateKP ( const std::vector< unsigned int > &  schedule,
const std::string &  filename 
)

Evaluates knapsack problem to file with a filename.

Parameters
scheduleSchedule.
filenameFilename.
Returns
Cost function value for given schedule.
Exceptions
std::invalid_argumentexception.
std::runtime_errorexception.
void operational_research::KnapsackProblem::generateData ( unsigned int  objects,
double  capacity,
double  minWeight,
double  maxWeight,
double  minProfit,
double  maxProfit,
bool  integerValues = false 
)

Generates knapsack problem data according to setup.

Parameters
objectsNumber of objects.
capacityKnapsack capacity.
minWeightMinimal weight of object.
maxWeightMaximal weight of object.
minProfitMinimal profit of object.
maxProfitMaximal profit of object.
integerValuesTrue if generated data is integer values, false if generated data is real values.
Exceptions
std::invalid_argumentexception.
double operational_research::KnapsackProblem::getCapacity ( ) const
inline

Getter for knapsack capacity.

Returns
Knapsack capacity.
unsigned int operational_research::KnapsackProblem::getObjects ( ) const
inline

Getter for number of objects.

Returns
Number of objects.
const std::vector<double>& operational_research::KnapsackProblem::getProfits ( ) const
inline

Getter for profits of objects.

Returns
Profits of objects.
const std::vector<double>& operational_research::KnapsackProblem::getWeights ( ) const
inline

Getter for weights of objects.

Returns
Weights of objects.
void operational_research::KnapsackProblem::readDataFromFile ( const std::string &  filename)
virtual

Reads knapsack problem data from a file with a filename.

Parameters
filenameFilename.
Exceptions
std::runtime_errorexception.
std::invalid_argumentexception.

Implements operational_research::IData.

void operational_research::KnapsackProblem::setData ( unsigned int  objects,
const std::vector< double > &  weights,
const std::vector< double > &  profits,
double  capacity 
)

Setter for knapsack problem data.

Parameters
objectsNumber of objects.
weightsWeights of objects.
profitsProfits of objects.
capacityKnapsack capacity.
Exceptions
std::invalid_argumentexception.
void operational_research::KnapsackProblem::showData ( )
virtual

Shows knapsack problem data.

Implements operational_research::IData.

void operational_research::KnapsackProblem::writeDataToFile ( const std::string &  filename)
virtual

Writes knapsack problem data to a file with a filename.

Parameters
filenameFilename.
Exceptions
std::runtime_errorexception.

Implements operational_research::IData.


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