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 Resource::updateProblems()
00036 {
00037
00038 Problem::clearProblems(*this);
00039
00040
00041 if (getHidden()) return;
00042
00043
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
00056 if (iter->getType() == 4)
00057 curMax = iter->getMax();
00058 else if (iter->getType() == 3)
00059 curMin = iter->getMin();
00060
00061
00062 const TimeLine<LoadPlan>::Event *f = &*(iter++);
00063 if (iter!=loadplans.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 shortageProblemStart = f->getDate();
00072 shortageQty = delta;
00073 shortageProblem = true;
00074 }
00075 else if (delta < shortageQty)
00076
00077 shortageQty = delta;
00078 }
00079 else
00080 {
00081 if (shortageProblem)
00082 {
00083
00084 if (f->getDate() != shortageProblemStart)
00085 new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00086 f->getDate()), -shortageQty);
00087 shortageProblem = false;
00088 }
00089 }
00090
00091
00092
00093
00094
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
00112 if (f->getDate() != excessProblemStart)
00113 new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00114 f->getDate()), excessQty);
00115 excessProblem = false;
00116 }
00117 }
00118
00119 }
00120
00121
00122 if (excessProblem)
00123 new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00124 Date::infiniteFuture), excessQty);
00125
00126
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 }