problems_resource.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: http://svn.code.sf.net/p/frepple/code/trunk/src/model/problems_resource.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 #define FREPPLE_CORE
00028 #include "frepple/model.h"
00029 
00030 namespace frepple
00031 {
00032 
00033 
00034 DECLARE_EXPORT void Resource::updateProblems()
00035 {
00036   // Delete existing problems for this resource
00037   Problem::clearProblems(*this);
00038 
00039   // Problem detection disabled on this resource
00040   if (!getDetectProblems()) return;
00041 
00042   // Loop through the loadplans
00043   Date excessProblemStart;
00044   Date shortageProblemStart;
00045   bool excessProblem = false;
00046   bool shortageProblem = false;
00047   double curMax(0.0);
00048   double shortageQty(0.0);
00049   double curMin(0.0);
00050   double excessQty(0.0);
00051   for (loadplanlist::const_iterator iter = loadplans.begin();
00052       iter != loadplans.end(); )
00053   {
00054     // Process changes in the maximum or minimum targets
00055     if (iter->getType() == 4)
00056       curMax = iter->getMax();
00057     else if (iter->getType() == 3)
00058       curMin = iter->getMin();
00059 
00060     // Only consider the last loadplan for a certain date
00061     const TimeLine<LoadPlan>::Event *f = &*(iter++);
00062     if (iter!=loadplans.end() && iter->getDate()==f->getDate()) continue;
00063 
00064     // Check against minimum target
00065     double delta = f->getOnhand() - curMin;
00066     if (delta < -ROUNDING_ERROR)
00067     {
00068       if (!shortageProblem)
00069       {
00070         shortageProblemStart = f->getDate();
00071         shortageQty = delta;
00072         shortageProblem = true;
00073       }
00074       else if (delta < shortageQty)
00075         // New shortage qty
00076         shortageQty = delta;
00077     }
00078     else
00079     {
00080       if (shortageProblem)
00081       {
00082         // New problem now ends
00083         if (f->getDate() != shortageProblemStart)
00084           new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00085               f->getDate()), -shortageQty);
00086         shortageProblem = false;
00087       }
00088     }
00089 
00090     // Note that theoretically we can have a minimum and a maximum problem for
00091     // the same moment in time.
00092 
00093     // Check against maximum target
00094     delta = f->getOnhand() - curMax;
00095     if (delta > ROUNDING_ERROR)
00096     {
00097       if (!excessProblem)
00098       {
00099         excessProblemStart = f->getDate();
00100         excessQty = delta;
00101         excessProblem = true;
00102       }
00103       else if (delta > excessQty)
00104         excessQty = delta;
00105     }
00106     else
00107     {
00108       if (excessProblem)
00109       {
00110         // New problem now ends
00111         if (f->getDate() != excessProblemStart)
00112           new ProblemCapacityOverload(this, excessProblemStart,
00113               f->getDate(), excessQty);
00114         excessProblem = false;
00115       }
00116     }
00117 
00118   }  // End of for-loop through the loadplans
00119 
00120   // The excess lasts till the end of the horizon...
00121   if (excessProblem)
00122     new ProblemCapacityOverload(this, excessProblemStart,
00123         Date::infiniteFuture, excessQty);
00124 
00125   // The shortage lasts till the end of the horizon...
00126   if (shortageProblem)
00127     new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00128         Date::infiniteFuture), -shortageQty);
00129 }
00130 
00131 
00132 DECLARE_EXPORT string ProblemCapacityUnderload::getDescription() const
00133 {
00134   ostringstream ch;
00135   ch << "Resource '" << getResource() << "' has excess capacity of " << qty;
00136   return ch.str();
00137 }
00138 
00139 
00140 DECLARE_EXPORT string ProblemCapacityOverload::getDescription() const
00141 {
00142   ostringstream ch;
00143   ch << "Resource '" << getResource() << "' has capacity shortage of " << qty;
00144   return ch.str();
00145 }
00146 
00147 }

Documentation generated for frePPLe by  doxygen