/home/coin/SVN-release/OS-2.3.5/OS/src/OSCommonInterfaces/OSGeneral.cpp

Go to the documentation of this file.
00001 /* $Id: OSGeneral.cpp 3186 2010-02-06 23:38:35Z Gassmann $ */
00015 #include "OSGeneral.h"
00016 #include "OSParameters.h"
00017 #include "OSErrorClass.h"
00018 #include "OSMathUtil.h"
00019 #include "OSBase64.h"
00020 
00021 #include <iostream>
00022 #include <sstream>
00023 
00024 //#define DEBUG_OSGENERAL
00025 //#define DEBUG_ISEQUAL_ROUTINES
00026 
00027 using namespace std;
00028 using std::cout;
00029 using std::endl;
00030 
00031 GeneralFileHeader::GeneralFileHeader():
00032         name(""),
00033         source(""),
00034         description(""),
00035         fileCreator(""),
00036         licence("")
00037 {
00038 }// end GeneralFileHeader constructor
00039 
00040 GeneralFileHeader::~GeneralFileHeader()
00041 {
00042         #ifdef DEBUG
00043         cout << "inside sparseVector destructor" << endl;
00044         #endif
00045 }// end GeneralFileHeader destructor
00046 
00047 bool GeneralFileHeader::IsEqual(GeneralFileHeader *that)
00048 {
00049 #ifdef DEBUG_OSGENERAL
00050                 cout << "Start comparing in GeneralFileHeader" << endl;
00051 #endif
00052         if (this == NULL)
00053         {       if (that == NULL)
00054                         return true;
00055                 else
00056                 {
00057 #ifdef DEBUG_OSGENERAL
00058                                 cout << "First object is NULL, second is not" << endl;
00059 #endif
00060                         return false;
00061                 }
00062         }
00063         else 
00064         {       if (that == NULL)
00065                 {
00066 #ifdef DEBUG_OSGENERAL
00067                                 cout << "Second object is NULL, first is not" << endl;
00068 #endif
00069                         return false;
00070                 }
00071                 else    
00072                 {       if ((this->name        != that->name)         || 
00073                                 (this->source      != that->source)      ||
00074                                 (this->description != that->description) || 
00075                                 (this->fileCreator != that->fileCreator) || 
00076                                 (this->licence     != that->licence))
00077                         {
00078 #ifdef DEBUG_OSGENERAL
00079                                 cout << "name: "        << this->name        << " vs. " << that->name        << endl;
00080                                 cout << "source: "      << this->source      << " vs. " << that->source      << endl;
00081                                 cout << "description: " << this->description << " vs. " << that->description << endl;
00082                                 cout << "fileCreator: " << this->fileCreator << " vs. " << that->fileCreator << endl;
00083                                 cout << "licence: "     << this->licence     << " vs. " << that->licence     << endl;
00084 #endif  
00085                                 return false;
00086                         }
00087                         return true;
00088                 }
00089         }
00090 }// end of GeneralFileHeader::IsEqual
00091 
00092 bool GeneralFileHeader::setRandom(double density, bool conformant)
00093 {
00094         if (OSRand() <= density) this->name        = "random string";
00095         if (OSRand() <= density) this->source      = "random string";
00096         if (OSRand() <= density) this->description = "random string";
00097         if (OSRand() <= density) this->fileCreator = "random string";
00098         if (OSRand() <= density) this->licence     = "random string";
00099         return true;
00100 }// end of GeneralFileHeader::setRandom
00101 
00102 bool GeneralFileHeader::setHeader(std::string name, std::string source, 
00103                            std::string description, std::string fileCreator, std::string licence)
00104 {
00105         this->name        = name;
00106         this->source      = source;
00107         this->description = description;
00108         this->fileCreator = fileCreator;
00109         this->licence     = licence;
00110         return true;
00111 }// end of GeneralFileHeader::setHeader
00112 
00113 SparseVector::SparseVector( int number_):
00114 number( number_)
00115 {
00116         indexes = new int[ number];
00117         values = new double[ number];
00118         bDeleteArrays = true;
00119 }// end SparseVector constructor
00120 
00121 
00122 SparseVector::SparseVector( ):
00123         bDeleteArrays(true),
00124         indexes( NULL),
00125         values( NULL)
00126 {
00127 }// end SparseVector constructor
00128 
00129 SparseVector::~SparseVector(){
00130         #ifdef DEBUG
00131         cout << "inside sparseVector destructor" << endl;
00132         #endif
00133         if(     bDeleteArrays == true){
00134 #ifdef DEBUG
00135 cout << "delete[] indexes and arrays" << endl;
00136 #endif
00137                 delete[] indexes;
00138                 delete[] values;
00139         }
00140         values = NULL;
00141         indexes = NULL;
00142 }// end SparseVector destructor
00143 
00144 SparseMatrix::SparseMatrix():
00145         bDeleteArrays( true),
00146         isColumnMajor(true),
00147         startSize(0),
00148         valueSize(0),
00149         starts(NULL),
00150         indexes(NULL),
00151         values(NULL)
00152 {
00153 }// end SparseMatrix Constructor
00154 
00155 
00156 
00157 SparseMatrix::SparseMatrix(bool isColumnMajor_, int startSize_, int valueSize_):
00158         isColumnMajor(isColumnMajor_), 
00159         startSize(startSize_),
00160         valueSize(valueSize_)
00161 {
00162         bDeleteArrays = true;
00163         starts = new int[startSize];
00164         indexes = new int[valueSize];
00165         values = new double[valueSize];
00166                 
00167 }//end SparseMatrix constructor
00168 
00169 
00170 SparseMatrix::~SparseMatrix(){
00171         #ifdef DEBUG
00172         cout << "inside SparseMatrix destructor" << endl;
00173         #endif
00174         if( bDeleteArrays == true){
00175                 delete[] starts;
00176                 delete[] indexes;
00177                 delete[] values;
00178 
00179         }
00180         starts = NULL;
00181         indexes = NULL;
00182         values = NULL;
00183 }// end SparseMatrix Destructor
00184 
00185 
00186 bool SparseMatrix::display(int secondaryDim){
00187                 int i, j, k;
00188                 for ( i = 0; i < startSize - 1; i++){                   
00189                         
00190                         if (starts[i] == starts[i + 1]){
00191                                 
00192                                 for ( k = 0; k < secondaryDim; k++){
00193                                         //System.out.print("0,");                                       
00194                                 }                               
00195                         }
00196                         else {
00197                                 for ( j = 0; j < indexes[starts[i]]; j ++){                             
00198                                         //System.out.print("0,");                                       
00199                                 }
00200                                 
00201                                 for ( j = starts[ i ]; j < starts[i + 1]; j++){
00202                                         
00203                                         //System.out.print (values[j] + ",");
00204                                         
00205                                         if ( j < starts[i + 1] - 1){
00206                                                 for ( k = indexes [j] + 1; k < indexes[j + 1]; k++){
00207                                                         //System.out.print("0,");                                       
00208                                                 }
00209                                         }
00210                                         else {
00211                                                 
00212                                                 for ( k = indexes [j] + 1; k < secondaryDim; k++){
00213                                                         //System.out.print("0,");                                       
00214                                                 }
00215                                         }
00216                                 }
00217                         }
00218                         //System.out.println();
00219                 }
00220 
00221                 return true;
00222                 
00223         }//display
00224         
00225 SparseJacobianMatrix::SparseJacobianMatrix():
00226         bDeleteArrays( true),
00227         startSize(0),
00228         valueSize(0),
00229         starts(NULL),
00230         conVals(NULL),
00231         indexes(NULL),
00232         values(NULL)
00233 {
00234 }// end SparseJaccobianMatrix Constructor
00235 
00236 
00237 SparseJacobianMatrix::SparseJacobianMatrix(int startSize_, int valueSize_):
00238         bDeleteArrays( true),
00239         startSize(startSize_),
00240         valueSize(valueSize_)
00241 {
00242         starts = new int[startSize];
00243         conVals = new int[startSize];
00244         indexes = new int[valueSize];
00245         values = new double[valueSize];         
00246 }//end SparseJacobianMatrix constructor
00247 
00248 
00249 SparseJacobianMatrix::~SparseJacobianMatrix(){
00250         #ifdef DEBUG
00251         cout << "inside SparseJacobianMatrix destructor" << endl;
00252         #endif
00253         if(bDeleteArrays == true){
00254                 #ifdef DEBUG
00255                 cout << "delete SparseJacobianArrays" << endl;
00256                 #endif
00257                 delete[] starts;
00258                 delete[] conVals;
00259                 delete[] indexes;
00260                 delete[] values;
00261         }
00262                 starts = NULL;
00263                 conVals = NULL;
00264                 indexes = NULL;
00265                 values = NULL;
00266 }// end SparseJacobianMatrix Destructor
00267 
00268 
00269 SparseHessianMatrix::SparseHessianMatrix():
00270         bDeleteArrays( true),
00271         hessDimension(0),
00272         hessRowIdx( NULL),
00273         hessColIdx( NULL),
00274         hessValues( NULL)
00275 {
00276 }// end SparseHessianMatrix Constructor
00277 
00278 
00279 
00280 SparseHessianMatrix::~SparseHessianMatrix(){
00281         #ifdef DEBUG
00282         cout << "inside SparseHessianMatrix destructor" << endl;
00283         #endif
00284         if(bDeleteArrays == true){
00285                 delete[] hessRowIdx;
00286                 delete[] hessColIdx;
00287                 delete[] hessValues;
00288         }
00289         hessRowIdx = NULL;
00290         hessColIdx = NULL;
00291         hessValues = NULL;
00292 }// end SparseHessianMatrix Destructor
00293 
00294 
00295         
00296 QuadraticTerms::QuadraticTerms():
00297         rowIndexes(NULL),
00298         varOneIndexes(NULL),
00299         varTwoIndexes(NULL),
00300         coefficients(NULL)
00301 {
00302 }
00303 
00304 QuadraticTerms::~QuadraticTerms(){
00305         #ifdef DEBUG
00306         cout << "inside Quadratic Terms destructor" << endl;
00307         #endif
00308         delete[] rowIndexes;
00309         rowIndexes = NULL;
00310         delete[] varOneIndexes;
00311         varOneIndexes = NULL;
00312         delete[] varTwoIndexes;
00313         varTwoIndexes = NULL;
00314         delete[] coefficients;
00315         coefficients = NULL;
00316 }
00317 
00318 
00319 IntVector::IntVector():
00320         bDeleteArrays(true),
00321         numberOfEl(0),
00322         el(NULL)
00323 {  
00324         #ifdef DEBUG
00325         cout << "Inside the IntVector Constructor" << endl;
00326         #endif
00327 } 
00328 
00329 
00330 IntVector::IntVector(int n):
00331         bDeleteArrays(true)
00332 {  
00333         #ifdef DEBUG
00334         cout << "Inside the IntVector Constructor" << endl;
00335         #endif
00336 
00337         numberOfEl = n;
00338         el = new int[n];
00339 } 
00340 
00341 IntVector::~IntVector(){  
00342         #ifdef DEBUG
00343         cout << "Inside the IntVector Destructor" << endl;
00344         #endif
00345         if(     bDeleteArrays == true){
00346                 delete[] el;
00347                 el = NULL;
00348         }
00349 } 
00350 
00351 bool IntVector::setIntVector(int *i, int ni)
00352 {
00353         if (this->numberOfEl != 0)
00354                 delete[] this->el;
00355 
00356         this->numberOfEl = ni;
00357 
00358         this->el = new int[ni];
00359         for (int j=0; j<ni; j++)
00360                 this->el[j] = i[j];
00361 
00362         return true;
00363 }//setIntVector
00364 
00365 bool IntVector::extendIntVector(int i)
00366 {
00367         int ni;
00368 //      if (this == NULL)
00369 //              this = new IntVector();
00370 
00371         if (this->el == NULL)
00372                 ni = 0;
00373         else
00374                 ni = this->numberOfEl;
00375 
00376         int* temp = new int[ni+1];
00377         for (int j = 0; j < ni; ++j)
00378                         temp[j] = this->el[j]; 
00379 
00380         delete[] this->el;
00381 
00382         temp[ni] = i;
00383 
00384         this->el = temp;
00385         this->numberOfEl = ++ni;
00386 
00387         return true;
00388 }//extendIntVector
00389 
00390 int IntVector::getNumberOfEl()
00391 {
00392         return this->numberOfEl;
00393 }
00394 
00395 int IntVector::getEl(int j)
00396 {
00397         if (j < 0 || j >= this->numberOfEl)
00398                 throw ErrorClass("Attempting to access undefined memory in IntVector::getEl(j)");  
00399         return this->el[j];
00400 }
00401 
00402 bool IntVector::getEl(int* i)
00403 {
00404         for (int j=0; j < this->numberOfEl; ++j)
00405                 i[j] = this->el[j];  
00406         return true;
00407 }
00408 
00409 bool IntVector::IsEqual(IntVector *that)
00410 {
00411         #ifdef DEBUG_ISEQUAL_ROUTINES
00412                 cout << "Start comparing in IntVector" << endl;
00413         #endif
00414         if (this == NULL)
00415         {       if (that == NULL)
00416                         return true;
00417                 else
00418                 {
00419                         #ifdef DEBUG_ISEQUAL_ROUTINES
00420                                 cout << "First object is NULL, second is not" << endl;
00421                         #endif
00422                         return false;
00423                 }
00424         }
00425         else 
00426         {       if (that == NULL)
00427                 {
00428                         #ifdef DEBUG_ISEQUAL_ROUTINES
00429                                 cout << "Second object is NULL, first is not" << endl;
00430                         #endif
00431                         return false;
00432                 }
00433                 else    
00434                 {
00435                         if (this->numberOfEl != that->numberOfEl)
00436                         {
00437 #ifdef DEBUG_ISEQUAL_ROUTINES
00438                                 cout << "numberOfEl: " << this->numberOfEl << " vs. " << that->numberOfEl << endl;
00439 #endif  
00440                                 return false;
00441                         }
00442                         for (int i=0; i<this->numberOfEl; i++)
00443                         {
00444                                 if (this->el[i] != that->el[i])
00445                                 {
00446 
00447 #ifdef DEBUG_ISEQUAL_ROUTINES
00448                                         cout << "El[" << i << "]: " << this->el[i] << " vs. " << that->el[i] << endl;
00449 #endif  
00450                                         return false;
00451                                 }
00452                         }
00453                         return true;
00454                 }
00455         }
00456 }//IntVector::IsEqual
00457 
00458 bool IntVector::setRandom(double density, bool conformant, int iMin, int iMax)
00459 {
00460 #ifdef DEBUG_ISEQUAL_ROUTINES
00461         cout << "Set random IntVector" << endl;
00462 #endif
00463         this->numberOfEl = (int)(4*OSRand());
00464 
00465         int n;
00466 
00467         if (conformant) n = this->numberOfEl;
00468         else            n = (int)(4*OSRand());
00469 
00470         el = new int[n];        
00471         for (int i = 0; i < n; i++)
00472                 el[i] = OSiRand(iMin, iMax);
00473         return true;
00474 }//IntVector::setRandom
00475 
00476 
00477 OtherOptionEnumeration::OtherOptionEnumeration():
00478         IntVector(),
00479         value(""),
00480         description("")
00481 {  
00482         #ifdef DEBUG
00483         cout << "Inside the OtherOptionEnumeration Constructor" << endl;
00484         #endif
00485 } 
00486 
00487 OtherOptionEnumeration::OtherOptionEnumeration(int n):
00488         IntVector(n),
00489         value(""),
00490         description("")
00491 {  
00492         #ifdef DEBUG
00493         cout << "Inside the OtherOptionEnumeration Constructor" << endl;
00494         #endif
00495 } 
00496 
00497 OtherOptionEnumeration::~OtherOptionEnumeration()
00498 {  
00499         #ifdef DEBUG
00500         cout << "Inside the OtherOptionEnumeration Destructor" << endl;
00501         #endif
00502 } 
00503 
00504 bool OtherOptionEnumeration::setOtherOptionEnumeration(std::string value, std::string description, int *i, int ni)
00505 {
00506         this->value = value;
00507         this->description = description;
00508         return this->IntVector::setIntVector(i, ni);
00509 }
00510 
00511 std::string OtherOptionEnumeration::getValue()
00512 {
00513         return this->value;
00514 }
00515 
00516 std::string OtherOptionEnumeration::getDescription()
00517 {
00518         return this->description;
00519 }
00520 
00521 
00522 
00523 bool OtherOptionEnumeration::IsEqual(OtherOptionEnumeration *that)
00524 {
00525         #ifdef DEBUG_ISEQUAL_ROUTINES
00526                 cout << "Start comparing in OtherOptionEnumeration" << endl;
00527         #endif
00528         if (this == NULL)
00529         {       if (that == NULL)
00530                         return true;
00531                 else
00532                 {
00533                         #ifdef DEBUG_ISEQUAL_ROUTINES
00534                                 cout << "First object is NULL, second is not" << endl;
00535                         #endif
00536                         return false;
00537                 }
00538         }
00539         else 
00540         {       if (that == NULL)
00541                 {
00542                         #ifdef DEBUG_ISEQUAL_ROUTINES
00543                                 cout << "Second object is NULL, first is not" << endl;
00544                         #endif
00545                         return false;
00546                 }
00547                 else    
00548                 {
00549                         if (this->value != that->value || this->description != that->description)
00550                         {
00551 #ifdef DEBUG_ISEQUAL_ROUTINES
00552                                 cout << "value:       " << this->value       << " vs. " << that->value       << endl;
00553                                 cout << "description: " << this->description << " vs. " << that->description << endl;
00554 #endif  
00555                                 return false;
00556                         }
00557 
00558                         return this->IntVector::IsEqual(that);
00559                 }
00560         }
00561 }//OtherOptionEnumeration::IsEqual
00562 
00563 bool OtherOptionEnumeration::setRandom(double density, bool conformant, int iMin, int iMax)
00564 {
00565         #ifdef DEBUG_ISEQUAL_ROUTINES
00566                 cout << "Set random OtherOptionEnumeration" << endl;
00567         #endif
00568         if (OSRand() <= density) this->value       = "random string";
00569         if (OSRand() <= density) this->description = "random string";
00570 
00571         if (OSRand() <= density) this->IntVector::setRandom(density,conformant,iMin,iMax);
00572         return true;
00573 }//OtherOptionEnumeration::setRandom
00574 
00575 
00576 
00577 DoubleVector::DoubleVector():
00578         bDeleteArrays(true),
00579         el(NULL)
00580 {
00581         #ifdef DEBUG
00582         cout << "Inside the DoubleVector Constructor" << endl;
00583         #endif
00584 
00585 }
00586 
00587 
00588 DoubleVector::~DoubleVector(){  
00589         #ifdef DEBUG
00590         cout << "Inside the DoubleVector Destructor" << endl;
00591         #endif
00592         if(     bDeleteArrays == true){
00593                 delete[] el;
00594                 el = NULL;
00595         }
00596 }
00597 
00598 
00599 bool DoubleVector::IsEqual(DoubleVector *that)
00600 {
00601         #ifdef DEBUG_ISEQUAL_ROUTINES
00602                 cout << "Start comparing in DoubleVector" << endl;
00603         #endif
00604         if (this == NULL)
00605         {       if (that == NULL)
00606                         return true;
00607                 else
00608                 {
00609                         #ifdef DEBUG_ISEQUAL_ROUTINES
00610                                 cout << "First object is NULL, second is not" << endl;
00611                         #endif
00612                         return false;
00613                 }
00614         }
00615         else 
00616         {       if (that == NULL)
00617                 {
00618                         #ifdef DEBUG_ISEQUAL_ROUTINES
00619                                 cout << "Second object is NULL, first is not" << endl;
00620                         #endif
00621                         return false;
00622                 }
00623                 else    
00624                 {
00625                         if (this->numberOfEl != that->numberOfEl)
00626                         {
00627 #ifdef DEBUG_ISEQUAL_ROUTINES
00628                                 cout << "numberOfEl: " << this->numberOfEl << " vs. " << that->numberOfEl << endl;
00629 #endif  
00630                                 return false;
00631                         }
00632                         for (int i=0; i<this->numberOfEl; i++)
00633                         {
00634                                 if (!isEqual(this->el[i], that->el[i]))
00635                                 {
00636 
00637 #ifdef DEBUG_ISEQUAL_ROUTINES
00638                                         cout << "El[" << i << "]: " << this->el[i] << " vs. " << that->el[i] << endl;
00639 #endif  
00640                                         return false;
00641                                 }
00642                         }
00643                         return true;
00644                 }
00645         }
00646 }//DoubleVector::IsEqual
00647 
00648 
00649 BasisStatus::BasisStatus():
00650         basic(NULL),
00651         atLower(NULL),
00652         atUpper(NULL),
00653         isFree(NULL),
00654         superbasic(NULL),
00655         unknown(NULL)
00656 { 
00657         #ifdef DEBUG_OSRESULT
00658         cout << "Inside the BasisStatus Constructor" << endl;
00659         #endif
00660 }//end BasisStatus constructor
00661 
00662 
00663 BasisStatus::~BasisStatus()
00664 {
00665         #ifdef DEBUG_OSRESULT  
00666         cout << "Inside the BasisStatus Destructor" << endl;
00667         #endif
00668         if (basic != NULL)
00669         {
00670                 delete basic;
00671                 basic = NULL;
00672         }
00673         if (atLower != NULL)
00674         {
00675                 delete atLower;
00676                 atLower = NULL;
00677         }
00678         if (atUpper != NULL)
00679         {
00680                 delete atUpper;
00681                 atUpper = NULL;
00682         }
00683         if (isFree != NULL)
00684         {
00685                 delete isFree;
00686                 isFree = NULL;
00687         }
00688         if (superbasic != NULL)
00689         {
00690                 delete superbasic;
00691                 superbasic = NULL;
00692         }
00693         if (unknown != NULL)
00694         {
00695                 delete unknown;
00696                 unknown = NULL;
00697         }
00698 }// end BasisStatus destructor 
00699 
00700 
00701 bool BasisStatus::setIntVector(int status, int *i, int ni)
00702 {
00703         switch (status)
00704         {
00705                 case ENUM_BASIS_STATUS_basic:
00706                 {
00707                         if (this->basic == NULL) this->basic = new IntVector();
00708 //                      else delete[] this->basic;
00709                         return this->basic->setIntVector(i, ni);
00710                 }
00711                 case ENUM_BASIS_STATUS_atLower:
00712                 {
00713                         if (this->atLower == NULL) this->atLower = new IntVector(ni);
00714 //                      else delete[] this->atLower;
00715                         return this->atLower->setIntVector(i, ni);
00716                 }
00717                 case ENUM_BASIS_STATUS_atUpper:
00718                 {
00719                         if (this->atUpper == NULL) this->atUpper = new IntVector(ni);
00720 //                      else delete[] this->atUpper;
00721                         return this->atUpper->setIntVector(i, ni);
00722                 }
00723                 case ENUM_BASIS_STATUS_isFree:
00724                 {
00725                         if (this->isFree == NULL) this->isFree = new IntVector(ni);
00726 //                      else delete[] this->isFree;
00727                         return this->isFree->setIntVector(i, ni);
00728                 }
00729                 case ENUM_BASIS_STATUS_superbasic:
00730                 {
00731                         if (this->superbasic == NULL) this->superbasic = new IntVector(ni);
00732 //                      else delete[] this->superbasic;
00733                         return this->superbasic->setIntVector(i, ni);
00734                 }
00735                 case ENUM_BASIS_STATUS_unknown:
00736                 {
00737                         if (this->unknown == NULL) this->unknown = new IntVector(ni);
00738 //                      else delete[] this->unknown;
00739                         return this->unknown->setIntVector(i, ni);
00740                 }
00741         default:
00742                 throw ErrorClass("Unknown basis status encountered in BasisStatus::setIntVector");  
00743          }
00744 }//BasisStatus::setIntVector
00745 
00746 bool BasisStatus::addIdx(int status, int idx)
00747 {
00748         switch (status)
00749         {
00750                 case ENUM_BASIS_STATUS_basic:
00751                 {
00752                         if (this->basic == NULL) this->basic = new IntVector();
00753                         return this->basic->extendIntVector(idx);
00754                 }
00755                 case ENUM_BASIS_STATUS_atLower:
00756                 {
00757                         if (this->atLower == NULL) this->atLower = new IntVector();
00758                         return this->atLower->extendIntVector(idx);
00759                 }
00760                 case ENUM_BASIS_STATUS_atUpper:
00761                 {
00762                         if (this->atUpper == NULL) this->atUpper = new IntVector();
00763                         return this->atUpper->extendIntVector(idx);
00764                 }
00765                 case ENUM_BASIS_STATUS_isFree:
00766                 {
00767                         if (this->isFree == NULL) this->isFree = new IntVector();
00768                         return this->isFree->extendIntVector(idx);
00769                 }
00770                 case ENUM_BASIS_STATUS_superbasic:
00771                 {
00772                         if (this->superbasic == NULL) this->superbasic = new IntVector();
00773                         return this->superbasic->extendIntVector(idx);
00774                 }
00775                 case ENUM_BASIS_STATUS_unknown:
00776                 {
00777                         if (this->unknown == NULL) this->unknown = new IntVector();
00778                         return this->unknown->extendIntVector(idx);
00779                 }
00780         default:
00781                 throw ErrorClass("Unknown basis status encountered in BasisStatus::addIdx");  
00782          }
00783 }//BasisStatus::addIdx
00784 
00785 
00786 bool BasisStatus::getIntVector(int status, int *i)
00787 {
00788         switch (status)
00789         {
00790                 case ENUM_BASIS_STATUS_basic:
00791                 {
00792                         if (this->basic == NULL) return false;
00793                         return this->basic->getEl(i);
00794                 }
00795                 case ENUM_BASIS_STATUS_atLower:
00796                 {
00797                         if (this->atLower == NULL) return false;
00798                         return this->atLower->getEl(i);
00799                 }
00800                 case ENUM_BASIS_STATUS_atUpper:
00801                 {
00802                         if (this->atUpper == NULL) return false;
00803                         return this->atUpper->getEl(i);
00804                 }
00805                 case ENUM_BASIS_STATUS_isFree:
00806                 {
00807                         if (this->isFree == NULL) return false;
00808                         return this->isFree->getEl(i);
00809                 }
00810                 case ENUM_BASIS_STATUS_superbasic:
00811                 {
00812                         if (this->superbasic == NULL) return false;
00813                         return this->superbasic->getEl(i);
00814                 }
00815                 case ENUM_BASIS_STATUS_unknown:
00816                 {
00817                         if (this->unknown == NULL) return false;
00818                         return this->unknown->getEl(i);
00819                 }
00820         default:
00821                 throw ErrorClass("Unknown basis status encountered in setIntVector");  
00822          }
00823 }//BasisStatus::getIntVector
00824 
00825 
00826 int BasisStatus::getNumberOfEl(int status)
00827 {
00828         switch (status)
00829         {
00830                 case ENUM_BASIS_STATUS_basic:
00831                 {
00832                         if (this->basic == NULL) return -1;
00833                         else return     this->basic->numberOfEl;
00834                 }
00835                 case ENUM_BASIS_STATUS_atLower:
00836                 {
00837                         if (this->atLower == NULL) return -1;
00838                         else return     this->atLower->numberOfEl;
00839                 }
00840                 case ENUM_BASIS_STATUS_atUpper:
00841                 {
00842                         if (this->atUpper == NULL) return -1;
00843                         else return     this->atUpper->numberOfEl;
00844                 }
00845                 case ENUM_BASIS_STATUS_isFree:
00846                 {
00847                         if (this->isFree == NULL) return -1;
00848                         else return     this->isFree->numberOfEl;
00849                 }
00850                 case ENUM_BASIS_STATUS_superbasic:
00851                 {
00852                         if (this->superbasic == NULL) return -1;
00853                         else return     this->superbasic->numberOfEl;
00854                 }
00855                 case ENUM_BASIS_STATUS_unknown:
00856                 {
00857                         if (this->unknown == NULL) return -1;
00858                         else return     this->unknown->numberOfEl;
00859                 }
00860         default:
00861                 throw ErrorClass("Unknown basis status encountered in getBasisStatusNumberOfEl");  
00862          }
00863 }//getNumberOfEl
00864 
00865 
00866 int BasisStatus::getEl(int status, int j)
00867 {
00868         switch (status)
00869         {
00870                 case ENUM_BASIS_STATUS_basic:
00871                 {
00872                         if (this->basic == NULL) 
00873                                 throw ErrorClass("\"basic\" index array never defined in routine BasisStatus::getEl()");
00874                         else return     this->basic->el[j];
00875                 }
00876                 case ENUM_BASIS_STATUS_atLower:
00877                 {
00878                         if (this->atLower == NULL)
00879                                 throw ErrorClass("\"atLower\" index array never defined in routine BasisStatus::getEl()");
00880                         else return     this->atLower->el[j];
00881                 }
00882                 case ENUM_BASIS_STATUS_atUpper:
00883                 {
00884                         if (this->atUpper == NULL)
00885                                 throw ErrorClass("\"atUpper\" index array never defined in routine BasisStatus::getEl()");
00886                         else return     this->atUpper->el[j];
00887                 }
00888                 case ENUM_BASIS_STATUS_isFree:
00889                 {
00890                         if (this->isFree == NULL)
00891                                 throw ErrorClass("\"isFree\" index array never defined in routine BasisStatus::getEl()");
00892                         else return     this->isFree->el[j];
00893                 }
00894                 case ENUM_BASIS_STATUS_superbasic:
00895                 {
00896                         if (this->superbasic == NULL)
00897                                 throw ErrorClass("\"superbasic\" index array never defined in routine BasisStatus::getEl()");
00898                         else return     this->superbasic->el[j];
00899                 }
00900                 case ENUM_BASIS_STATUS_unknown:
00901                 {
00902                         if (this->unknown == NULL)
00903                                 throw ErrorClass("\"unknown\" index array never defined in routine BasisStatus::getEl()");
00904                         else return     this->unknown->el[j];
00905                 }
00906         default:
00907                 throw ErrorClass("Unknown basis status encountered in getBasisStatusNumberOfEl");  
00908          }
00909 }//getEl
00910 
00911 bool BasisStatus::IsEqual(BasisStatus *that)
00912 {
00913 #ifdef DEBUG_ISEQUAL_ROUTINES
00914         cout << "Start comparing in BasisStatus" << endl;
00915 #endif
00916         if (this == NULL)
00917         {       if (that == NULL)
00918                         return true;
00919                 else
00920                 {
00921                         #ifdef DEBUG_ISEQUAL_ROUTINES
00922                                 cout << "First object is NULL, second is not" << endl;
00923                         #endif
00924                         return false;
00925                 }
00926         }
00927         else 
00928         {       if (that == NULL)
00929                 {
00930                         #ifdef DEBUG_ISEQUAL_ROUTINES
00931                                 cout << "Second object is NULL, first is not" << endl;
00932                         #endif
00933                         return false;
00934                 }
00935                 else    
00936                 {
00937                         if (      !this->basic->IsEqual(that->basic)      ) return false;
00938                         if (    !this->atLower->IsEqual(that->atLower)    ) return false;
00939                         if (    !this->atUpper->IsEqual(that->atUpper)    ) return false;
00940                         if (     !this->isFree->IsEqual(that->isFree)     ) return false;
00941                         if ( !this->superbasic->IsEqual(that->superbasic) ) return false;
00942                         if (    !this->unknown->IsEqual(that->unknown)    ) return false;
00943 
00944                         return true;
00945                 }
00946         }
00947 }//BasisStatus::IsEqual
00948 
00949 bool BasisStatus::setRandom(double density, bool conformant, int iMin, int iMax)
00950 {
00951 #ifdef DEBUG_ISEQUAL_ROUTINES
00952         cout << "Set random BasisStatus" << endl;
00953 #endif
00954         if (OSRand() <= density) 
00955         {
00956                 this->basic = new IntVector();
00957                 this->basic->setRandom(density, conformant, iMin, iMax);
00958         }
00959         if (OSRand() <= density)
00960         {
00961                 this->atLower = new IntVector();
00962                 this->atLower->setRandom(density, conformant, iMin, iMax);
00963         }
00964         if (OSRand() <= density)
00965         {
00966                 this->atUpper = new IntVector();
00967                 this->atUpper->setRandom(density, conformant, iMin, iMax);
00968         }
00969         if (OSRand() <= density)
00970         {
00971                 this->isFree = new IntVector();
00972                 this->isFree->setRandom(density, conformant, iMin, iMax);
00973         }
00974         if (OSRand() <= density)
00975         {
00976                 this->superbasic = new IntVector();
00977                 this->superbasic->setRandom(density, conformant, iMin, iMax);
00978         }
00979         if (OSRand() <= density)
00980         {
00981                 this->unknown = new IntVector();
00982                 this->unknown->setRandom(density, conformant, iMin, iMax);
00983         }
00984 
00985         return true;
00986 }//BasisStatus::setRandom
00987 
00988 
00989 StorageCapacity::StorageCapacity():
00990         unit("byte"),
00991         description(""),
00992         value(0.0)
00993 {
00994 }// end StorageCapacity constructor
00995 
00996 StorageCapacity::~StorageCapacity()
00997 {
00998         #ifdef DEBUG
00999         cout << "inside StorageCapacity destructor" << endl;
01000         #endif
01001 }// end StorageCapacity destructor
01002 
01003 bool StorageCapacity::IsEqual(StorageCapacity *that)
01004 {
01005         if (this == NULL)
01006         {       if (that == NULL)
01007                         return true;
01008                 else
01009                 {
01010                         #ifdef DEBUG_OSGENERAL
01011                                 cout << "First object is NULL, second is not" << endl;
01012                         #endif
01013                         return false;
01014                 }
01015         }
01016         else 
01017         {       if (that == NULL)
01018                 {
01019                         #ifdef DEBUG_OSGENERAL
01020                                 cout << "Second object is NULL, first is not" << endl;
01021                         #endif
01022                         return false;
01023                 }
01024                 else    
01025                 {       if ((this->unit        != that->unit)        || 
01026                                 (this->description != that->description) || 
01027                                 !isEqual(this->value, that->value))
01028                         {
01029 #ifdef DEBUG_OSGENERAL
01030                                 cout << "unit: "        << this->unit        << " vs. " << that->unit        << endl;
01031                                 cout << "description: " << this->description << " vs. " << that->description << endl;
01032                                 cout << "value: "       << this->value       << " vs. " << that->value       << endl;
01033 #endif  
01034                                 return false;
01035                         }
01036                         return true;
01037                 }
01038         }
01039 }// end of StorageCapacity::IsEqual
01040 
01041 bool StorageCapacity::setRandom(double density, bool conformant)
01042 {
01043         if (OSRand() <= density) 
01044         {
01045                 double temp = OSRand();
01046                 if (conformant) temp = 0.5*temp;
01047 
01048                 if      (temp <= 0.25) this->unit = "byte";
01049                 else if (temp <= 0.50) this->unit = "megabyte";
01050                 else if (temp <= 0.75) this->unit = "";
01051                 else                   this->unit = "overbyte";
01052         } 
01053         if (OSRand() <= density) this->description   = "random string";
01054         if (OSRand() <= density) 
01055         {
01056                 if (OSRand() <= 0.5) this->value = 3.14156;
01057                 else                 this->value = 2.71828;
01058         }
01059         return true;
01060 }// end of StorageCapacity::setRandom
01061 
01062 
01063 CPUSpeed::CPUSpeed():
01064         unit("hertz"),
01065         description(""),
01066         value(0.0)
01067 {
01068 }// end CPUSpeed constructor
01069 
01070 CPUSpeed::~CPUSpeed()
01071 {
01072         #ifdef DEBUG
01073         cout << "inside CPUSpeed destructor" << endl;
01074         #endif
01075 }// end CPUSpeed destructor
01076 
01077 bool CPUSpeed::IsEqual(CPUSpeed *that)
01078 {
01079         if (this == NULL)
01080         {       if (that == NULL)
01081                         return true;
01082                 else
01083                 {
01084                         #ifdef DEBUG_OSGENERAL
01085                                 cout << "First object is NULL, second is not" << endl;
01086                         #endif
01087                         return false;
01088                 }
01089         }
01090         else 
01091         {       if (that == NULL)
01092                 {
01093                         #ifdef DEBUG_OSGENERAL
01094                                 cout << "Second object is NULL, first is not" << endl;
01095                         #endif
01096                         return false;
01097                 }
01098                 else    
01099                 {       if ((this->unit        != that->unit)        || 
01100                                 (this->description != that->description) || 
01101 //                              (this->value       != that->value))
01102                                 !isEqual(this->value, that->value))
01103                         {
01104 #ifdef DEBUG_OSGENERAL
01105                                 cout << "unit: "        << this->unit        << " vs. " << that->unit        << endl;
01106                                 cout << "description: " << this->description << " vs. " << that->description << endl;
01107                                 cout << "value: "       << this->value       << " vs. " << that->value       << endl;
01108 #endif  
01109                                 return false;
01110                         }
01111                         return true;
01112                 }
01113         }
01114 }// end of CPUSpeed::IsEqual
01115 
01116 bool CPUSpeed::setRandom(double density, bool conformant)
01117 {
01118         if (OSRand() <= density) 
01119         {
01120                 double temp = OSRand();
01121                 if (conformant) temp = 0.5*temp;
01122 
01123                 if      (temp <= 0.25) this->unit = "hertz";
01124                 else if (temp <= 0.50) this->unit = "gigaflops";
01125                 else if (temp <= 0.75) this->unit = "";
01126                 else                   this->unit = "bellyflops";
01127         } 
01128         if (OSRand() <= density) this->description   = "random string";
01129         if (OSRand() <= density) 
01130         {
01131                 if (OSRand() <= 0.5) this->value = 3.14156;
01132                 else                 this->value = 2.71828;
01133         }
01134         return true;
01135 }// end of CPUSpeed::setRandom
01136 
01137 
01138 CPUNumber::CPUNumber():
01139         description(""),
01140         value(0)
01141 {
01142 }// end CPUNumber constructor
01143 
01144 CPUNumber::~CPUNumber()
01145 {
01146         #ifdef DEBUG
01147         cout << "inside CPUNumber destructor" << endl;
01148         #endif
01149 }// end CPUNumber destructor
01150 
01151 bool CPUNumber::IsEqual(CPUNumber *that)
01152 {
01153         if (this == NULL)
01154         {       if (that == NULL)
01155                         return true;
01156                 else
01157                 {
01158                         #ifdef DEBUG_OSGENERAL
01159                                 cout << "First object is NULL, second is not" << endl;
01160                         #endif
01161                         return false;
01162                 }
01163         }
01164         else 
01165         {       if (that == NULL)
01166                 {
01167                         #ifdef DEBUG_OSGENERAL
01168                                 cout << "Second object is NULL, first is not" << endl;
01169                         #endif
01170                         return false;
01171                 }
01172                 else    
01173                 {       if ((this->description != that->description) || 
01174                                 (this->value       != that->value))
01175                         {
01176 #ifdef DEBUG_OSGENERAL
01177                                 cout << "description: " << this->description << " vs. " << that->description << endl;
01178                                 cout << "value: "       << this->value       << " vs. " << that->value       << endl;
01179 #endif  
01180                                 return false;
01181                         }
01182                         return true;
01183                 }
01184         }
01185 }// end of CPUNumber::IsEqual
01186 
01187 bool CPUNumber::setRandom(double density, bool conformant)
01188 {
01189         if (OSRand() <= density) this->description = "random string";
01190         if (OSRand() <= density) this->value = (int)(4*OSRand());
01191         return true;
01192 }// end of CPUNumber::setRandom
01193 
01194 
01195 TimeSpan::TimeSpan():
01196         unit("second"),
01197         value(0.0)
01198 {
01199 }// end TimeSpan constructor
01200 
01201 TimeSpan::~TimeSpan()
01202 {
01203         #ifdef DEBUG
01204         cout << "inside TimeSpan destructor" << endl;
01205         #endif
01206 }// end TimeSpan destructor
01207 
01208 bool TimeSpan::IsEqual(TimeSpan *that)
01209 {
01210         if (this == NULL)
01211         {       if (that == NULL)
01212                         return true;
01213                 else
01214                 {
01215                         #ifdef DEBUG_OSGENERAL
01216                                 cout << "First object is NULL, second is not" << endl;
01217                         #endif
01218                         return false;
01219                 }
01220         }
01221         else 
01222         {       if (that == NULL)
01223                 {
01224                         #ifdef DEBUG_OSGENERAL
01225                                 cout << "Second object is NULL, first is not" << endl;
01226                         #endif
01227                         return false;
01228                 }
01229                 else    
01230                 {       if (!isEqual(this->value,  that->value) ||
01231                                                  this->unit != that->unit )  
01232                                 
01233                         {
01234 #ifdef DEBUG_OSGENERAL
01235                                 cout << "unit: "  << this->unit  << " vs. " << that->unit  << endl;
01236                                 cout << "value: " << this->value << " vs. " << that->value << endl;
01237 #endif  
01238                                 return false;
01239                         }
01240                         return true;
01241                 }
01242         }
01243 }// end of TimeSpan::IsEqual
01244 
01245 bool TimeSpan::setRandom(double density, bool conformant)
01246 {
01247         if (OSRand() <= density) 
01248         {
01249                 double temp = OSRand();
01250                 if (conformant) temp = 0.5*temp;
01251 
01252                 if      (temp <= 0.25) this->unit = "second";
01253                 else if (temp <= 0.50) this->unit = "tick";
01254                 else if (temp <= 0.75) this->unit = "";
01255                 else                   this->unit = "flea";
01256         } 
01257         if (OSRand() <= density) 
01258         {
01259                 if (OSRand() <= 0.5) this->value = 3.14156;
01260                 else                 this->value = 2.71828;
01261         }
01262         return true;
01263 }// end of TimeSpan::setRandom
01264 
01265 

Generated on Thu Mar 31 03:12:47 2011 by  doxygen 1.4.7