problems_resource.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002   file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/tags/0.8.0/src/model/problems_resource.cpp $
00003   version : $LastChangedRevision: 1108 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2009-12-06 18:54:18 +0100 (Sun, 06 Dec 2009) $
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  * Copyright (C) 2007 by Johan De Taeye                                    *
00010  *                                                                         *
00011  * This library is free software; you can redistribute it and/or modify it *
00012  * under the terms of the GNU Lesser General Public License as published   *
00013  * by the Free Software Foundation; either version 2.1 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 GNU Lesser *
00019  * General Public License for more details.                                *
00020  *                                                                         *
00021  * You should have received a copy of the GNU Lesser General Public        *
00022  * License along with this library; if not, write to the Free Software     *
00023  * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,*
00024  * USA                                                                     *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 #define FREPPLE_CORE
00029 #include "frepple/model.h"
00030 
00031 namespace frepple
00032 {
00033 
00034 
00035 DECLARE_EXPORT void Resource::updateProblems()
00036 {
00037   // Delete existing problems for this resource
00038   Problem::clearProblems(*this);
00039 
00040   // Hidden entities don't have problems
00041   if (getHidden()) return;
00042 
00043   // Loop through the loadplans
00044   Date excessProblemStart;
00045   Date shortageProblemStart;
00046   bool excessProblem = false;
00047   bool shortageProblem = false;
00048   double curMax(0.0);
00049   double shortageQty(0.0);
00050   double curMin(0.0);
00051   double excessQty(0.0);
00052   for (loadplanlist::const_iterator iter = loadplans.begin();
00053     iter != loadplans.end(); )
00054   {
00055     // Process changes in the maximum or minimum targets
00056     if (iter->getType() == 4)
00057       curMax = iter->getMax();
00058     else if (iter->getType() == 3)
00059       curMin = iter->getMin();
00060 
00061     // Only consider the last loadplan for a certain date
00062     const TimeLine<LoadPlan>::Event *f = &*(iter++);
00063     if (iter!=loadplans.end() && iter->getDate()==f->getDate()) continue;
00064 
00065     // Check against minimum target
00066     double delta = f->getOnhand() - curMin;
00067     if (delta < -ROUNDING_ERROR)
00068     {
00069       if (!shortageProblem)
00070       {
00071         shortageProblemStart = f->getDate();
00072         shortageQty = delta;
00073         shortageProblem = true;
00074       }
00075       else if (delta < shortageQty)
00076         // New shortage qty
00077         shortageQty = delta;
00078     }
00079     else
00080     {
00081       if (shortageProblem)
00082       {
00083         // New problem now ends
00084         if (f->getDate() != shortageProblemStart)
00085           new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00086               f->getDate()), -shortageQty);
00087         shortageProblem = false;
00088       }
00089     }
00090 
00091     // Note that theoretically we can have a minimum and a maximum problem for
00092     // the same moment in time.
00093 
00094     // Check against maximum target
00095     delta = f->getOnhand() - curMax;
00096     if (delta > ROUNDING_ERROR)
00097     {
00098       if (!excessProblem)
00099       {
00100         excessProblemStart = f->getDate();
00101         excessQty = delta;
00102         excessProblem = true;
00103       }
00104       else if (delta > excessQty)
00105         excessQty = delta;
00106     }
00107     else
00108     {
00109       if (excessProblem)
00110       {
00111         // New problem now ends
00112         if (f->getDate() != excessProblemStart)
00113           new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00114               f->getDate()), excessQty);
00115         excessProblem = false;
00116       }
00117     }
00118 
00119   }  // End of for-loop through the loadplans
00120 
00121   // The excess lasts till the end of the horizon...
00122   if (excessProblem)
00123     new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00124         Date::infiniteFuture), excessQty);
00125 
00126   // The shortage lasts till the end of the horizon...
00127   if (shortageProblem)
00128     new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00129         Date::infiniteFuture), -shortageQty);
00130 }
00131 
00132 
00133 DECLARE_EXPORT string ProblemCapacityUnderload::getDescription() const
00134 {
00135   ostringstream ch;
00136   ch << "Resource '" << getResource() << "' has excess capacity of " << qty;
00137   return ch.str();
00138 }
00139 
00140 
00141 DECLARE_EXPORT string ProblemCapacityOverload::getDescription() const
00142 {
00143   ostringstream ch;
00144   ch << "Resource '" << getResource() << "' has capacity shortage of " << qty;
00145   return ch.str();
00146 }
00147 
00148 }

Generated on 16 Apr 2010 for frePPLe by  doxygen 1.6.1