models.h
Go to the documentation of this file.
#ifndef MODELS_H
#define MODELS_H
#include"data.h"
#include"costfunctions.h"
/*
* Model
*/
class Model{
public:
//Virtual Constructor & Destructor for any model type
Model();
Model(const Model&);
Model(Data);
virtual ~Model(){delete m_cost;};
//Link model to data set and cost function
virtual void setModelData(Data);
virtual void setExpData(Data);
virtual void setCost(CostFunction*);
//Virtual solution, parameters, neighbor solution and cost getter
virtual Data getSol() const = 0;
virtual void setParam(std::vector<double>){};
virtual std::vector<double> getParam() const = 0;
virtual std::vector<double> getNeighbor(double) const = 0;
virtual double getCost() = 0;
//Virtual export model parameters
virtual void exportModel() const = 0;
virtual void displayModel() const = 0;
protected:
Data m_data; //Data set containing points obtained using model
Data exp_data; //Data set containing experimental points to approximate
CostFunction* m_cost; //Pointer to cost function to minimize
};
/*
* Linear Approximation model
*/
class LinearApprox : public Model{
public:
//Virtual Constructor & Destructor for this model
LinearApprox();
LinearApprox(const LinearApprox&);
LinearApprox(Data);
LinearApprox(Data,std::vector<double>);
~LinearApprox(){};
//Set data model, experimental data and cost function
void setModelData(Data);
void setExpData(Data);
void setCost(CostFunction*);
//Solution, neighbor and cost getter
Data getSol() const;
void setParam(std::vector<double>);
std::vector<double> getParam() const;
std::vector<double> getNeighbor(double) const;
double getCost();
//Export model parameters
void exportModel() const;
void displayModel() const;
//Set and get parameters for this model
Data getExpData() const;
void setSlope(double);
double getSlope() const;
void setOffset(double);
double getOffset() const;
private:
std::vector<double> param;
};
/*
* Polynomial Approximation model
*/
class PolynomialApprox : public Model{
public:
//Virtual Constructor & Destructor for this model
PolynomialApprox();
PolynomialApprox(const PolynomialApprox&);
PolynomialApprox(int);
PolynomialApprox(Data,int);
PolynomialApprox(Data,std::vector<double>);
~PolynomialApprox(){};
//Set data model, experimental data and cost function
void setModelData(Data);
void setExpData(Data);
void setCost(CostFunction*);
//Solution, neighbor and cost getter
Data getSol() const;
void setParam(std::vector<double>);
std::vector<double> getParam() const;
std::vector<double> getNeighbor(double) const;
double getCost();
//Export model parameters
void exportModel() const;
void displayModel() const;
//Set and get parameters for this model
Data getExpData() const;
private:
std::vector<double> param;
};
/*
* Traveling SalesPerson problem
*/
class TSP : public Model{
public:
//Virtual Constructor & Destructor for this model
TSP();
TSP(const TSP&);
TSP(Data);
TSP(Data,std::vector<int>);
~TSP(){};
//Set data model, experimental data and cost function
void setModelData(Data);
void setExpData(Data);
void setCost(CostFunction*);
//Solution, neighbor and cost getter
Data getSol() const;
void setParam(std::vector<double>);
std::vector<double> getParam() const;
std::vector<double> getNeighbor(double) const;
double getCost();
//Export model parameters
void exportModel() const;
void displayModel() const;
//Set and get parameters for this model
Data getExpData() const;
void setOrder(std::vector<int>);
std::vector<int> getOrder() const;
private:
std::vector<int> order;
};
#endif
Model::m_data
Data m_data
Definition: models.h:32
Model::getParam
virtual std::vector< double > getParam() const =0
PolynomialApprox::setExpData
void setExpData(Data)
Definition: models.cpp:274
TSP::setParam
void setParam(std::vector< double >)
Definition: models.cpp:461
PolynomialApprox::setParam
void setParam(std::vector< double >)
Definition: models.cpp:297
LinearApprox::displayModel
void displayModel() const
Definition: models.cpp:147
LinearApprox::getSol
Data getSol() const
Definition: models.cpp:108
TSP::getParam
std::vector< double > getParam() const
Definition: models.cpp:471
Model::displayModel
virtual void displayModel() const =0
LinearApprox::exportModel
void exportModel() const
Definition: models.cpp:142
PolynomialApprox::getNeighbor
std::vector< double > getNeighbor(double) const
Definition: models.cpp:311
PolynomialApprox::PolynomialApprox
PolynomialApprox()
Definition: models.cpp:217
LinearApprox::getCost
double getCost()
Definition: models.cpp:134
PolynomialApprox::setCost
void setCost(CostFunction *)
Definition: models.cpp:285
TSP::displayModel
void displayModel() const
Definition: models.cpp:542
TSP::setOrder
void setOrder(std::vector< int >)
Definition: models.cpp:563
TSP::getCost
double getCost()
Definition: models.cpp:527
Model::setExpData
virtual void setExpData(Data)
Definition: models.cpp:34
Model::exportModel
virtual void exportModel() const =0
Model::getCost
virtual double getCost()=0
LinearApprox::setModelData
void setModelData(Data)
Definition: models.cpp:87
PolynomialApprox::exportModel
void exportModel() const
Definition: models.cpp:329
Data
Definition: data.h:12
Model::setModelData
virtual void setModelData(Data)
Definition: models.cpp:30
Model::Model
Model()
Definition: models.cpp:10
CostFunction
Definition: costfunctions.h:10
PolynomialApprox
Definition: models.h:76
LinearApprox::setCost
void setCost(CostFunction *)
Definition: models.cpp:101
LinearApprox::getSlope
double getSlope() const
Definition: models.cpp:179
PolynomialApprox::setModelData
void setModelData(Data)
Definition: models.cpp:270
TSP::setExpData
void setExpData(Data)
Definition: models.cpp:431
PolynomialApprox::getExpData
Data getExpData() const
Definition: models.cpp:354
LinearApprox::LinearApprox
LinearApprox()
Definition: models.cpp:50
LinearApprox
Definition: models.h:41
TSP::~TSP
~TSP()
Definition: models.h:116
LinearApprox::getNeighbor
std::vector< double > getNeighbor(double) const
Definition: models.cpp:126
PolynomialApprox::getSol
Data getSol() const
Definition: models.cpp:293
Model::getNeighbor
virtual std::vector< double > getNeighbor(double) const =0
TSP::exportModel
void exportModel() const
Definition: models.cpp:535
TSP::setModelData
void setModelData(Data)
Definition: models.cpp:427
TSP
Definition: models.h:109
Model
Definition: models.h:11
LinearApprox::getOffset
double getOffset() const
Definition: models.cpp:193
TSP::getSol
Data getSol() const
Definition: models.cpp:457
LinearApprox::getParam
std::vector< double > getParam() const
Definition: models.cpp:122
PolynomialApprox::displayModel
void displayModel() const
Definition: models.cpp:336
data.h
LinearApprox::setExpData
void setExpData(Data)
Definition: models.cpp:91
LinearApprox::~LinearApprox
~LinearApprox()
Definition: models.h:48
LinearApprox::setSlope
void setSlope(double)
Definition: models.cpp:169
TSP::TSP
TSP()
Definition: models.cpp:380
Model::getSol
virtual Data getSol() const =0
TSP::setCost
void setCost(CostFunction *)
Definition: models.cpp:450
costfunctions.h
LinearApprox::getExpData
Data getExpData() const
Definition: models.cpp:165
Model::setCost
virtual void setCost(CostFunction *)
Definition: models.cpp:38
PolynomialApprox::getCost
double getCost()
Definition: models.cpp:321
TSP::getOrder
std::vector< int > getOrder() const
Definition: models.cpp:573
TSP::getNeighbor
std::vector< double > getNeighbor(double) const
Definition: models.cpp:509
PolynomialApprox::getParam
std::vector< double > getParam() const
Definition: models.cpp:307
Model::~Model
virtual ~Model()
Definition: models.h:17
LinearApprox::setOffset
void setOffset(double)
Definition: models.cpp:183
LinearApprox::setParam
void setParam(std::vector< double >)
Definition: models.cpp:112
TSP::getExpData
Data getExpData() const
Definition: models.cpp:559
Model::m_cost
CostFunction * m_cost
Definition: models.h:34
PolynomialApprox::~PolynomialApprox
~PolynomialApprox()
Definition: models.h:84
Model::setParam
virtual void setParam(std::vector< double >)
Definition: models.h:24
Model::exp_data
Data exp_data
Definition: models.h:33