forecast/module.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/modules/forecast/module.cpp $
00003   version : $LastChangedRevision: 1713 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2012-07-18 11:46:01 +0200 (Wed, 18 Jul 2012) $
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  * Copyright (C) 2007-2012 by Johan De Taeye, frePPLe bvba                 *
00010  *                                                                         *
00011  * This library is free software; you can redistribute it and/or modify it *
00012  * under the terms of the GNU Affero General Public License as published   *
00013  * by the Free Software Foundation; either version 3 of the License, or    *
00014  * (at your option) any later version.                                     *
00015  *                                                                         *
00016  * This library is distributed in the hope that it will be useful,         *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
00019  * GNU Affero General Public License for more details.                     *
00020  *                                                                         *
00021  * You should have received a copy of the GNU Affero General Public        *
00022  * License along with this program.                                        *
00023  * If not, see <http://www.gnu.org/licenses/>.                             *
00024  *                                                                         *
00025  ***************************************************************************/
00026 
00027 #include "forecast.h"
00028 
00029 namespace module_forecast
00030 {
00031 
00032 Forecast::MapOfForecasts Forecast::ForecastDictionary;
00033 bool Forecast::Customer_Then_Item_Hierarchy = true;
00034 bool Forecast::Match_Using_Delivery_Operation = true;
00035 TimePeriod Forecast::Net_Late(0L);
00036 TimePeriod Forecast::Net_Early(0L);
00037 unsigned long Forecast::Forecast_Iterations(15L);
00038 double Forecast::Forecast_SmapeAlfa(0.95);
00039 unsigned long Forecast::Forecast_Skip(5);
00040 
00041 
00042 MODULE_EXPORT const char* initialize(const Environment::ParameterList& z)
00043 {
00044   // Initialize only once
00045   static bool init = false;
00046   static const char* name = "forecast";
00047   if (init)
00048   {
00049     logger << "Warning: Initializing module forecast more than once." << endl;
00050     return name;
00051   }
00052   init = true;
00053 
00054   // Process the module parameters
00055   for (Environment::ParameterList::const_iterator x = z.begin();
00056       x != z.end(); ++x)
00057     try
00058     {
00059       // Forecast buckets
00060       if (x->first == "DueAtEndOfBucket")
00061         ForecastBucket::setDueAtEndOfBucket(x->second.getBool());
00062       // Netting
00063       else if (x->first == "Net_CustomerThenItemHierarchy")
00064         Forecast::setCustomerThenItemHierarchy(x->second.getBool());
00065       else if (x->first == "Net_MatchUsingDeliveryOperation")
00066         Forecast::setMatchUsingDeliveryOperation(x->second.getBool());
00067       else if (x->first == "Net_NetEarly")
00068         Forecast::setNetEarly(x->second.getTimeperiod());
00069       else if (x->first == "Net_NetLate")
00070         Forecast::setNetLate(x->second.getTimeperiod());
00071       // Forecasting
00072       else if (x->first == "Forecast_Iterations")
00073         Forecast::setForecastIterations(x->second.getUnsignedLong());
00074       else if (x->first == "Forecast_SmapeAlfa")
00075         Forecast::setForecastSmapeAlfa(x->second.getDouble());
00076       else if (x->first == "Forecast_Skip")
00077         Forecast::setForecastSkip(x->second.getUnsignedLong());
00078       // Moving average forecast method
00079       else if (x->first == "MovingAverage_buckets")
00080         Forecast::MovingAverage::setDefaultBuckets(x->second.getUnsignedLong());
00081       // Single exponential forecast method
00082       else if (x->first == "Forecast_SingleExponential_initialAlfa")
00083         Forecast::SingleExponential::setInitialAlfa(x->second.getDouble());
00084       else if (x->first == "Forecast_SingleExponential_minAlfa")
00085         Forecast::SingleExponential::setMinAlfa(x->second.getDouble());
00086       else if (x->first == "Forecast_SingleExponential_maxAlfa")
00087         Forecast::SingleExponential::setMaxAlfa(x->second.getDouble());
00088       // Double exponential forecast method
00089       else if (x->first == "Forecast_DoubleExponential_initialAlfa")
00090         Forecast::DoubleExponential::setInitialAlfa(x->second.getDouble());
00091       else if (x->first == "Forecast_DoubleExponential_minAlfa")
00092         Forecast::DoubleExponential::setMinAlfa(x->second.getDouble());
00093       else if (x->first == "Forecast_DoubleExponential_maxAlfa")
00094         Forecast::DoubleExponential::setMaxAlfa(x->second.getDouble());
00095       else if (x->first == "Forecast_DoubleExponential_initialGamma")
00096         Forecast::DoubleExponential::setInitialGamma(x->second.getDouble());
00097       else if (x->first == "Forecast_DoubleExponential_minGamma")
00098         Forecast::DoubleExponential::setMinGamma(x->second.getDouble());
00099       else if (x->first == "Forecast_DoubleExponential_maxGamma")
00100         Forecast::DoubleExponential::setMaxGamma(x->second.getDouble());
00101       else if (x->first == "Forecast_DoubleExponential_dampenTrend")
00102         Forecast::DoubleExponential::setDampenTrend(x->second.getDouble());
00103       // Seasonal forecast method
00104       else if (x->first == "Forecast_Seasonal_initialAlfa")
00105         Forecast::Seasonal::setInitialAlfa(x->second.getDouble());
00106       else if (x->first == "Forecast_Seasonal_minAlfa")
00107         Forecast::Seasonal::setMinAlfa(x->second.getDouble());
00108       else if (x->first == "Forecast_Seasonal_maxAlfa")
00109         Forecast::Seasonal::setMaxAlfa(x->second.getDouble());
00110       else if (x->first == "Forecast_Seasonal_initialBeta")
00111         Forecast::Seasonal::setInitialGamma(x->second.getDouble());
00112       else if (x->first == "Forecast_Seasonal_minBeta")
00113         Forecast::Seasonal::setMinBeta(x->second.getDouble());
00114       else if (x->first == "Forecast_Seasonal_maxBeta")
00115         Forecast::Seasonal::setMaxBeta(x->second.getDouble());
00116       else if (x->first == "Forecast_Seasonal_initialGamma")
00117         Forecast::Seasonal::setInitialBeta(x->second.getDouble());
00118       else if (x->first == "Forecast_Seasonal_minGamma")
00119         Forecast::Seasonal::setMinGamma(x->second.getDouble());
00120       else if (x->first == "Forecast_Seasonal_maxGamma")
00121         Forecast::Seasonal::setMaxGamma(x->second.getDouble());
00122       else if (x->first == "Forecast_Seasonal_dampenTrend")
00123         Forecast::Seasonal::setDampenTrend(x->second.getDouble());
00124       else if (x->first == "Forecast_Seasonal_minPeriod")
00125         Forecast::Seasonal::setMinPeriod(x->second.getInt());
00126       else if (x->first == "Forecast_Seasonal_maxPeriod")
00127         Forecast::Seasonal::setMaxPeriod(x->second.getInt());
00128       // Croston forecast method
00129       else if (x->first == "Forecast_Croston_initialAlfa")
00130         Forecast::Croston::setInitialAlfa(x->second.getDouble());
00131       else if (x->first == "Forecast_Croston_minAlfa")
00132         Forecast::Croston::setMinAlfa(x->second.getDouble());
00133       else if (x->first == "Forecast_Croston_maxAlfa")
00134         Forecast::Croston::setMaxAlfa(x->second.getDouble());
00135       else if (x->first == "Forecast_Croston_minIntermittence")
00136         Forecast::Croston::setMinIntermittence(x->second.getDouble());
00137       // That's bullshit
00138       else
00139         logger << "Warning: Unrecognized parameter '" << x->first << "'" << endl;
00140     }
00141     catch (const exception &e)
00142     {
00143       // Avoid throwing errors during the initialization!
00144       logger << "Error: " << e.what() << endl;
00145     }
00146     catch (...)
00147     {
00148       logger << "Error: unknown exception" << endl;
00149     }
00150 
00151   // Register the Python extensions
00152   PyGILState_STATE state = PyGILState_Ensure();
00153   try
00154   {
00155     // Register new Python data types
00156     if (Forecast::initialize())
00157       throw RuntimeException("Error registering forecast");
00158     if (ForecastBucket::initialize())
00159       throw RuntimeException("Error registering forecastbucket");
00160     if (ForecastSolver::initialize())
00161       throw RuntimeException("Error registering forecastsolver");
00162     PyGILState_Release(state);
00163   }
00164   catch (const exception &e)
00165   {
00166     PyGILState_Release(state);
00167     logger << "Error: " << e.what() << endl;
00168   }
00169   catch (...)
00170   {
00171     PyGILState_Release(state);
00172     logger << "Error: unknown exception" << endl;
00173   }
00174 
00175   // Return the name of the module
00176   return name;
00177 }
00178 
00179 }       // end namespace

Documentation generated for frePPLe by  doxygen