problems_buffer.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_buffer.cpp $
00003   version : $LastChangedRevision: 1013 $  $LastChangedBy: jdetaeye $
00004   date : $LastChangedDate: 2009-08-06 17:41:53 +0200 (Thu, 06 Aug 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 Buffer::updateProblems()
00036 {
00037   // Delete existing problems for this buffer
00038   Problem::clearProblems(*this);
00039 
00040   // Hidden entities don't have problems
00041   if (getHidden()) return;
00042 
00043   // Loop through the flowplans
00044   Date excessProblemStart;
00045   Date shortageProblemStart;
00046   bool shortageProblem = false;
00047   bool excessProblem = false;
00048   double curMax(0.0);
00049   double shortageQty(0.0);
00050   double curMin(0.0);
00051   double excessQty(0.0);
00052   for (flowplanlist::const_iterator iter = flowplans.begin();
00053     iter != flowplans.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 flowplan for a certain date
00062     const TimeLine<FlowPlan>::Event *f = &*(iter++);
00063     if (iter!=flowplans.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         // Start of a problem
00072         shortageProblemStart = f->getDate();
00073         shortageQty = delta;
00074         shortageProblem = true;
00075       }
00076       else if (delta < shortageQty)
00077         // New shortage qty
00078         shortageQty = delta;
00079     }
00080     else
00081     {
00082       if (shortageProblem)
00083       {
00084         // New problem now ends
00085         if (f->getDate() != shortageProblemStart)
00086           new ProblemMaterialShortage
00087             (this, shortageProblemStart, f->getDate(), -shortageQty);
00088         shortageProblem = false;
00089       }
00090     }
00091 
00092     // Note that theoretically we can have a minimum and a maximum problem for
00093     // the same moment in time.
00094 
00095     // Check against maximum target
00096     delta = f->getOnhand() - curMax;
00097     if (delta > ROUNDING_ERROR)
00098     {
00099       if (!excessProblem)
00100       {
00101         // New problem starts here
00102         excessProblemStart = f->getDate();
00103         excessQty = delta;
00104         excessProblem = true;
00105       }
00106       else if (delta > excessQty)
00107         excessQty = delta;
00108     }
00109     else
00110     {
00111       if (excessProblem)
00112       {
00113         // New excess qty
00114         // New problem now ends
00115         if (f->getDate() != excessProblemStart)
00116           new ProblemMaterialExcess
00117             (this, excessProblemStart, f->getDate(), excessQty);
00118         excessProblem = false;
00119       }
00120     }
00121 
00122   }  // End of for-loop through the flowplans
00123 
00124   // The excess lasts till the end of the horizon...
00125   if (excessProblem)
00126     new ProblemMaterialExcess
00127       (this, excessProblemStart, Date::infiniteFuture, excessQty);
00128 
00129   // The shortage lasts till the end of the horizon...
00130   if (shortageProblem)
00131     new ProblemMaterialShortage
00132       (this, shortageProblemStart, Date::infiniteFuture, -shortageQty);
00133 }
00134 
00135 
00136 
00137 DECLARE_EXPORT string ProblemMaterialExcess::getDescription() const
00138 {
00139   ostringstream ch;
00140   ch << "Buffer '" << getBuffer() << "' has material excess of " << qty;
00141   return ch.str();
00142 }
00143 
00144 
00145 DECLARE_EXPORT string ProblemMaterialShortage::getDescription() const
00146 {
00147   ostringstream ch;
00148   ch << "Buffer '" << getBuffer() << "' has material shortage of " << qty;
00149   return ch.str();
00150 }
00151 
00152 
00153 }

Generated on 16 Apr 2010 for frePPLe by  doxygen 1.6.1