Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "forecast.h"
00029
00030 namespace module_forecast
00031 {
00032
00033 Forecast::MapOfForecasts Forecast::ForecastDictionary;
00034 bool Forecast::Customer_Then_Item_Hierarchy = true;
00035 bool Forecast::Match_Using_Delivery_Operation = true;
00036 TimePeriod Forecast::Net_Late(0L);
00037 TimePeriod Forecast::Net_Early(0L);
00038 unsigned long Forecast::Forecast_Iterations(15L);
00039 double Forecast::Forecast_MadAlfa(0.95);
00040 unsigned long Forecast::Forecast_Skip(5);
00041
00042
00043 MODULE_EXPORT const char* initialize(const CommandLoadLibrary::ParameterList& z)
00044 {
00045
00046 static bool init = false;
00047 static const char* name = "forecast";
00048 if (init)
00049 {
00050 logger << "Warning: Initializing module forecast more than once." << endl;
00051 return name;
00052 }
00053 init = true;
00054
00055
00056 for (CommandLoadLibrary::ParameterList::const_iterator x = z.begin();
00057 x != z.end(); ++x)
00058 try
00059 {
00060
00061 if (x->first == "Net_CustomerThenItemHierarchy")
00062 Forecast::setCustomerThenItemHierarchy(x->second.getBool());
00063 else if (x->first == "Net_MatchUsingDeliveryOperation")
00064 Forecast::setMatchUsingDeliveryOperation(x->second.getBool());
00065 else if (x->first == "Net_NetEarly")
00066 Forecast::setNetEarly(x->second.getTimeperiod());
00067 else if (x->first == "Net_NetLate")
00068 Forecast::setNetLate(x->second.getTimeperiod());
00069
00070 else if (x->first == "Forecast_Iterations")
00071 Forecast::setForecastIterations(x->second.getUnsignedLong());
00072 else if (x->first == "Forecast_madAlfa")
00073 Forecast::setForecastMadAlfa(x->second.getDouble());
00074 else if (x->first == "Forecast_Skip")
00075 Forecast::setForecastSkip(x->second.getUnsignedLong());
00076
00077 else if (x->first == "MovingAverage_buckets")
00078 Forecast::MovingAverage::setDefaultBuckets(x->second.getUnsignedLong());
00079
00080 else if (x->first == "Forecast_SingleExponential_initialAlfa")
00081 Forecast::SingleExponential::setInitialAlfa(x->second.getDouble());
00082 else if (x->first == "Forecast_SingleExponential_minAlfa")
00083 Forecast::SingleExponential::setMinAlfa(x->second.getDouble());
00084 else if (x->first == "Forecast_SingleExponential_maxAlfa")
00085 Forecast::SingleExponential::setMaxAlfa(x->second.getDouble());
00086
00087 else if (x->first == "Forecast_DoubleExponential_initialAlfa")
00088 Forecast::DoubleExponential::setInitialAlfa(x->second.getDouble());
00089 else if (x->first == "Forecast_DoubleExponential_minAlfa")
00090 Forecast::DoubleExponential::setMinAlfa(x->second.getDouble());
00091 else if (x->first == "Forecast_DoubleExponential_maxAlfa")
00092 Forecast::DoubleExponential::setMaxAlfa(x->second.getDouble());
00093 else if (x->first == "Forecast_DoubleExponential_initialGamma")
00094 Forecast::DoubleExponential::setInitialGamma(x->second.getDouble());
00095 else if (x->first == "Forecast_DoubleExponential_minGamma")
00096 Forecast::DoubleExponential::setMinGamma(x->second.getDouble());
00097 else if (x->first == "Forecast_DoubleExponential_maxGamma")
00098 Forecast::DoubleExponential::setMaxGamma(x->second.getDouble());
00099
00100 else
00101 logger << "Warning: Unrecognized parameter '" << x->first << "'" << endl;
00102 }
00103 catch (exception &e)
00104 {
00105
00106 logger << "Error: " << e.what() << endl;
00107 }
00108 catch (...)
00109 {
00110 logger << "Error: unknown exception" << endl;
00111 }
00112
00113 try
00114 {
00115
00116 PyThreadState *myThreadState = PyGILState_GetThisThreadState();
00117 if (!Py_IsInitialized() || !myThreadState)
00118 throw RuntimeException("Python isn't initialized correctly");
00119 try
00120 {
00121
00122 PyEval_RestoreThread(myThreadState);
00123
00124 if (Forecast::initialize())
00125 throw RuntimeException("Error registering forecast");
00126 if (ForecastBucket::initialize())
00127 throw RuntimeException("Error registering forecastbucket");
00128 if (ForecastSolver::initialize())
00129 throw RuntimeException("Error registering forecastsolver");
00130 }
00131
00132 catch (...)
00133 {
00134 PyEval_ReleaseLock();
00135 throw;
00136 }
00137 PyEval_ReleaseLock();
00138 }
00139 catch (exception &e)
00140 {
00141
00142 logger << "Error: " << e.what() << endl;
00143 }
00144 catch (...)
00145 {
00146 logger << "Error: unknown exception" << endl;
00147 }
00148
00149
00150 return name;
00151 }
00152
00153 }