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