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