00001
00002
00003
00004
00005
00006
00007 #ifndef LP_OLD
00008 #ifndef AGENTSOLUTION_H_
00009 #define AGENTSOLUTION_H_
00010
00011 #include <typeinfo>
00012
00013 #include "OsiSymSolverInterface.hpp"
00014 #include "SymWarmStart.hpp"
00015 #include "CoinWarmStartBasis.hpp"
00016
00018
00029 class AgentSolution
00030 {
00031 public:
00033
00034 int getNumberOfRows()const;
00035 int getNumberOfColumns()const;
00036 double* getColumnSolution()const;
00037 double getColumnSolution(int index)const;
00038 double* getObjectiveFunctCoeff()const;
00039 double getObjectiveFunctCoeff(int index)const;
00040 double getObjValue()const;
00042
00046 double* getDualRightHandSide()const;
00048
00052 double getDualRightHandSide(int index)const;
00053 double* getSlackRightHandSide()const;
00054 double getSlackRightHandSide(int index)const;
00055 double* getRowActivity()const;
00056 double getRowActivity(int index)const;
00057 bool getTestFlag()const;
00059 double getInfinity() const;
00060 double getTolerance()const;
00062
00066 SymWarmStart* getWarmStartSym()const;
00067 CoinWarmStartBasis* getWarmStartCoin()const;
00069
00071
00072 virtual void setNumberOfRows(const int numberofrows);
00073 virtual void setNumberOfColumns(const int numberofcolumns);
00074 virtual void setColumnSolution(const double* columnsolution_);
00075 virtual int setColumnSolution(const double value,int index);
00076 virtual void setObjectiveFunctCoeff(const double*objectivefunctcoeff_);
00077 virtual int setObjectiveFunctCoeff(const double value,int index);
00078 virtual void setObjValue(const double objvalue_);
00079 virtual void setDualRightHandSide(const double*dualrhs_);
00080 virtual int setDualRightHandSide(const double value,int index);
00081 virtual void setSlackRightHandSide(const double*slackrhs_);
00082 virtual int setSlackRightHandSide(const double value,int index);
00083 virtual void setRowActivity(const double*rowactivities_);
00084 virtual int setRowActivity(const double value,int index);
00085 virtual void setInfinity(double infinity);
00086 virtual void setTestFlag(bool test);
00087 virtual void setTolerance(double eps);
00089
00094 virtual void setWarmStart(const SymWarmStart* const warmstart);
00096 virtual void setWarmStart(const CoinWarmStartBasis* const warmstart);
00098
00103 virtual void load( const int numberofrows_, const int numberofcolumns_, const double*columnsolution_,const double*objectivefunctcoeff_,
00104 const double objvalue_, const double*dualrhs_,const double*slackrhs_,const double*rowactivities_,
00105 const SymWarmStart* warmstart);
00107 virtual void load( const int numberofrows_, const int numberofcolumns_, const double*columnsolution_,const double*objectivefunctcoeff_,
00108 const double objvalue_, const double*dualrhs_,const double*slackrhs_,const double*rowactivities_,
00109 const CoinWarmStartBasis* warmstart);
00111
00113
00114
00115 AgentSolution();
00117 AgentSolution(int numberofrows_, int numberofcols_);
00119 AgentSolution(const AgentSolution& solution);
00121 AgentSolution& operator=(const AgentSolution& rhs);
00123 virtual ~AgentSolution();
00125
00126 private:
00128
00129
00130 int numberofrows;
00132 int numberofcolumns;
00134 mutable double* columnsolution;
00136 mutable double* objectivefunctcoeff;
00138 double objvalue;
00140 mutable double* dualrhs;
00142 mutable double* slackrhs;
00144 mutable double* rowactivities;
00146 double infinity;
00148 bool test;
00150 double eps;
00152
00157 SymWarmStart* lastYearWarmStartSym;
00159 CoinWarmStartBasis* lastYearWarmStartCoin;
00160
00161
00163
00164
00165 void round();
00167 void round(double* vector,int vectorlength);
00169 void round(CoinPackedMatrix *MatrixDouble);
00171 double round(double value);
00176 double truncate(double precision,double& x);
00180 double round(int numberofdecimals_, double& x);
00182 void gutsOfConstructor();
00184 void gutsOfDestructor();
00186 void allocate();
00188 template <class Type> int allocateVector(Type*& pointertovector, long int sizeofvector);
00190 template <class ClassType> void copy(ClassType*& finalObjectPtr_, const ClassType* const originalObjectPtr_);
00192 };
00193
00194 template <class Type>
00195 int AgentSolution::allocateVector(Type*& pointertovector, long int sizeofvector){
00196 if (sizeofvector > 0)
00197 if(pointertovector== NULL){
00198 try{
00199 pointertovector = new Type[sizeofvector];
00200 for (int i = 0; i<sizeofvector;i++) pointertovector[i] = NULL;
00201 }
00202 catch(exception& exceptionObject){
00203 cerr << "Exception: "<< exceptionObject.what()<<endl;
00204 cerr << "Error in "<< typeid(*this).name()<<"::allocateVector(): cannot allocate memory for Type"<< typeid(*pointertovector).name()<<"["<<sizeofvector<<"]" << endl;
00205 exit(0);
00206 }
00207 }
00208 else {
00209 delete[] pointertovector;
00210 pointertovector = NULL;
00211 try{
00212 pointertovector = new Type[sizeofvector];
00213 for (int i = 0; i<sizeofvector;i++) pointertovector[i] = NULL;
00214 }
00215 catch(exception& exceptionObject){
00216 cerr << "Exception: "<< exceptionObject.what()<<endl;
00217 cerr << "Error in "<< typeid(*this).name()<<"::allocateVector(): cannot allocate memory for Type"<< typeid(*pointertovector).name()<<"["<<sizeofvector<<"]" << endl;
00218 exit(0);
00219 }
00220 }
00221 else {
00222 if (test) cerr << "Warning in "<< typeid(*this).name()<<"::allocateVector(): nothing to allocate:"
00223 << "length of array of "<<typeid(*pointertovector).name()<<" is: "<<sizeofvector<<"!" << endl;
00224 return 0;
00225 }
00226 return 1;
00227 }
00228
00229
00230 template <class ClassType> void AgentSolution::copy(ClassType*& finalObjectPtr_, const ClassType* const originalObjectPtr_){
00231 if (originalObjectPtr_ != NULL){
00232 if (finalObjectPtr_ == NULL)
00233 try {
00234 finalObjectPtr_ = new ClassType(*originalObjectPtr_);
00235 }
00236 catch (exception& exceptionObject){
00237 cerr << "Exception: "<< exceptionObject.what() << endl;
00238 cerr << "Error in "<< typeid(*this).name()<<"::copy(): cannot allocate memory for"<< typeid(ClassType).name() << endl;
00239 }
00240 else {
00241 delete finalObjectPtr_;
00242 finalObjectPtr_ = NULL;
00243 try {
00244 finalObjectPtr_ = new ClassType(*originalObjectPtr_);
00245 }
00246 catch (exception& exceptionObject){
00247 cerr << "Exception: "<< exceptionObject.what() << endl;
00248 cerr << "Error in "<< typeid(*this).name()<<"::copy(): cannot allocate memory for"<< typeid(ClassType).name() << endl;
00249 }
00250 }
00251 }
00252 else if (test) cerr << "Warning in "<< typeid(*this).name() << "::copy(): "<<typeid(originalObjectPtr_).name() <<" == NULL!" << endl;
00253 }
00254
00255
00256 #endif
00257 #endif