problems_buffer.cpp
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 #define FREPPLE_CORE
00029 #include "frepple/model.h"
00030
00031 namespace frepple
00032 {
00033
00034
00035 DECLARE_EXPORT void Buffer::updateProblems()
00036 {
00037
00038 Problem::clearProblems(*this);
00039
00040
00041 if (getHidden()) return;
00042
00043
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
00056 if (iter->getType() == 4)
00057 curMax = iter->getMax();
00058 else if (iter->getType() == 3)
00059 curMin = iter->getMin();
00060
00061
00062 const TimeLine<FlowPlan>::Event *f = &*(iter++);
00063 if (iter!=flowplans.end() && iter->getDate()==f->getDate()) continue;
00064
00065
00066 double delta = f->getOnhand() - curMin;
00067 if (delta < -ROUNDING_ERROR)
00068 {
00069 if (!shortageProblem)
00070 {
00071
00072 shortageProblemStart = f->getDate();
00073 shortageQty = delta;
00074 shortageProblem = true;
00075 }
00076 else if (delta < shortageQty)
00077
00078 shortageQty = delta;
00079 }
00080 else
00081 {
00082 if (shortageProblem)
00083 {
00084
00085 if (f->getDate() != shortageProblemStart)
00086 new ProblemMaterialShortage
00087 (this, shortageProblemStart, f->getDate(), -shortageQty);
00088 shortageProblem = false;
00089 }
00090 }
00091
00092
00093
00094
00095
00096 delta = f->getOnhand() - curMax;
00097 if (delta > ROUNDING_ERROR)
00098 {
00099 if (!excessProblem)
00100 {
00101
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
00114
00115 if (f->getDate() != excessProblemStart)
00116 new ProblemMaterialExcess
00117 (this, excessProblemStart, f->getDate(), excessQty);
00118 excessProblem = false;
00119 }
00120 }
00121
00122 }
00123
00124
00125 if (excessProblem)
00126 new ProblemMaterialExcess
00127 (this, excessProblemStart, Date::infiniteFuture, excessQty);
00128
00129
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 }