00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // C 00005 #include <assert.h> 00006 // RMOL 00007 #include <rmol/basic/BasConst_RMOL_Service.hpp> 00008 #include <rmol/field/FldYieldRange.hpp> 00009 #include <rmol/field/FldDistributionParameters.hpp> 00010 #include <rmol/bom/Demand.hpp> 00011 #include <rmol/bom/Bucket.hpp> 00012 #include <rmol/bom/BucketHolder.hpp> 00013 #include <rmol/bom/StudyStatManager.hpp> 00014 #include <rmol/bom/Gaussian.hpp> 00015 #include <rmol/factory/FacSupervisor.hpp> 00016 #include <rmol/factory/FacDemand.hpp> 00017 #include <rmol/factory/FacBucket.hpp> 00018 #include <rmol/factory/FacBucketHolder.hpp> 00019 #include <rmol/factory/FacStudyStatManager.hpp> 00020 #include <rmol/command/FileMgr.hpp> 00021 #include <rmol/service/RMOL_ServiceContext.hpp> 00022 00023 namespace RMOL { 00024 00025 // ////////////////////////////////////////////////////////////////////// 00026 RMOL_ServiceContext:: 00027 RMOL_ServiceContext (const ResourceCapacity_T iResourceCapacity) : 00028 _bucketHolder (NULL), _capacity (iResourceCapacity), 00029 _studyStatManager (NULL), 00030 _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { 00031 init (iResourceCapacity); 00032 } 00033 00034 // ////////////////////////////////////////////////////////////////////// 00035 RMOL_ServiceContext::RMOL_ServiceContext () : 00036 _bucketHolder (NULL), _capacity (DEFAULT_RMOL_SERVICE_CAPACITY), 00037 _studyStatManager (NULL), 00038 _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { 00039 init (DEFAULT_RMOL_SERVICE_CAPACITY); 00040 } 00041 00042 // ////////////////////////////////////////////////////////////////////// 00043 RMOL_ServiceContext::RMOL_ServiceContext (const RMOL_ServiceContext&) : 00044 _bucketHolder (NULL), _capacity (DEFAULT_RMOL_SERVICE_CAPACITY), 00045 _studyStatManager (NULL), 00046 _generatedDemandVectorHolder (DEFAULT_GENERATED_DEMAND_VECTOR_HOLDER) { 00047 init (DEFAULT_RMOL_SERVICE_CAPACITY); 00048 } 00049 00050 // ////////////////////////////////////////////////////////////////////// 00051 RMOL_ServiceContext::~RMOL_ServiceContext() { 00052 } 00053 00054 // ////////////////////////////////////////////////////////////////////// 00055 void RMOL_ServiceContext::init (const ResourceCapacity_T iResourceCapacity) { 00056 _bucketHolder = &FacBucketHolder::instance().create (iResourceCapacity); 00057 } 00058 00059 // ////////////////////////////////////////////////////////////////////// 00060 void RMOL_ServiceContext::setUpStudyStatManager () { 00061 _studyStatManager = &FacStudyStatManager::instance().create(); 00062 } 00063 00064 // ////////////////////////////////////////////////////////////////////// 00065 void RMOL_ServiceContext:: 00066 setResourceCapacity (const ResourceCapacity_T iResourceCapacity) { 00067 _capacity = iResourceCapacity; 00068 init (iResourceCapacity); 00069 } 00070 00071 // ////////////////////////////////////////////////////////////////////// 00072 void RMOL_ServiceContext::addBucket (const double iYieldRange, 00073 const double iDemandMean, 00074 const double iDemandStandardDev) { 00075 const FldYieldRange aYieldRange (iYieldRange); 00076 const FldDistributionParameters aDistribParams (iDemandMean, 00077 iDemandStandardDev); 00078 Demand& aDemand = 00079 FacDemand::instance().create (aDistribParams, aYieldRange); 00080 Bucket& aBucket = FacBucket::instance().create (aYieldRange, aDemand); 00081 00082 assert (_bucketHolder != NULL); 00083 FacBucketHolder::instance().addBucket (*_bucketHolder, aBucket); 00084 } 00085 00086 // ////////////////////////////////////////////////////////////////////// 00087 void RMOL_ServiceContext:: 00088 addBucket (const double iYieldRange, 00089 const double iDemandMean, 00090 const double iDemandStandardDev, 00091 GeneratedDemandVector_T* ioGeneratedDemandVector) { 00092 const FldYieldRange aYieldRange (iYieldRange); 00093 const FldDistributionParameters aDistribParams (iDemandMean, 00094 iDemandStandardDev); 00095 Demand& aDemand = 00096 FacDemand::instance().create (aDistribParams, aYieldRange); 00097 Bucket& aBucket = FacBucket::instance().create (aYieldRange, aDemand); 00098 aBucket.setGeneratedDemandVector (ioGeneratedDemandVector); 00099 00100 assert (_bucketHolder != NULL); 00101 FacBucketHolder::instance().addBucket (*_bucketHolder, aBucket); 00102 } 00103 00104 // ////////////////////////////////////////////////////////////////////// 00105 GeneratedDemandVector_T* RMOL_ServiceContext:: 00106 generateDemand (const int K, const double& iMean, const double& iDeviation) { 00107 // Build a vector of K generated numbers from the given distribution 00108 // N(iMean, iDeviation) and add this vector to the 00109 // GeneratedDemandVector holder. 00110 _generatedDemandVectorHolder.push_back (DEFAULT_GENERATED_DEMAND_VECTOR); 00111 GeneratedDemandVectorHolder_T::reverse_iterator itLastVector = 00112 _generatedDemandVectorHolder.rbegin(); 00113 GeneratedDemandVector_T& lDemandVector = *itLastVector; 00114 lDemandVector.reserve (K); 00115 const FldDistributionParameters aDistributionParam = 00116 FldDistributionParameters::FldDistributionParameters (iMean, iDeviation); 00117 const Gaussian gaussianDemandGenerator (aDistributionParam); 00118 00119 // Generate K numbers 00120 for (int i = 0; i < K; ++i) { 00121 const double lGeneratedDemand = gaussianDemandGenerator.generateVariate (); 00122 lDemandVector.push_back (lGeneratedDemand); 00123 } 00124 00125 return &lDemandVector; 00126 } 00127 00128 // ////////////////////////////////////////////////////////////////////// 00129 GeneratedDemandVector_T* RMOL_ServiceContext:: 00130 generateDemand (GeneratedDemandVector_T* ioFirstVector, 00131 GeneratedDemandVector_T* ioSecondVector) { 00132 if (ioFirstVector == NULL || ioSecondVector == NULL) { 00133 return NULL; 00134 } else { 00135 const unsigned int K = ioFirstVector->size(); 00136 assert (K == ioSecondVector->size()); 00137 _generatedDemandVectorHolder.push_back (DEFAULT_GENERATED_DEMAND_VECTOR); 00138 GeneratedDemandVectorHolder_T::reverse_iterator itLastVector = 00139 _generatedDemandVectorHolder.rbegin(); 00140 GeneratedDemandVector_T& lDemandVector = *itLastVector; 00141 lDemandVector.reserve (K); 00142 for (unsigned int i = 0; i < K; ++i) { 00143 const double lGeneratedDemand = 00144 ioFirstVector->at(i) + ioSecondVector->at(i); 00145 lDemandVector.push_back (lGeneratedDemand); 00146 } 00147 00148 return &lDemandVector; 00149 } 00150 } 00151 00152 // ////////////////////////////////////////////////////////////////////// 00153 void RMOL_ServiceContext:: 00154 readFromInputFile (const std::string& iInputFileName) { 00155 assert (_bucketHolder != NULL); 00156 FileMgr::readAndProcessInputFile (iInputFileName, *_bucketHolder); 00157 } 00158 00159 // ////////////////////////////////////////////////////////////////////// 00160 void RMOL_ServiceContext::buildContextForMC (const int K) { 00161 assert (_bucketHolder != NULL); 00162 for (_bucketHolder->begin(); _bucketHolder->hasNotReachedEnd(); 00163 _bucketHolder->iterate()) { 00164 Bucket& currentBucket = _bucketHolder->getCurrentBucket(); 00165 const double mean = currentBucket.getMean(); 00166 const double standardDeviation = currentBucket.getStandardDeviation(); 00167 GeneratedDemandVector_T* lGeneratedDemandVector = 00168 generateDemand (K, mean, standardDeviation); 00169 currentBucket.setGeneratedDemandVector (lGeneratedDemandVector); 00170 } 00171 } 00172 00173 // ////////////////////////////////////////////////////////////////////// 00174 void RMOL_ServiceContext::reset () { 00175 _capacity = DEFAULT_RMOL_SERVICE_CAPACITY; 00176 _bucketHolder = NULL; 00177 } 00178 00179 }
Generated on Sat Sep 26 13:13:51 2009 for RMOL by Doxygen 1.6.1