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 #define FREPPLE_CORE
00028 #include "frepple/model.h"
00029
00030 namespace frepple
00031 {
00032
00033
00034 DECLARE_EXPORT void Resource::updateProblems()
00035 {
00036
00037 Problem::clearProblems(*this);
00038
00039
00040 if (getHidden()) return;
00041
00042
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
00055 if (iter->getType() == 4)
00056 curMax = iter->getMax();
00057 else if (iter->getType() == 3)
00058 curMin = iter->getMin();
00059
00060
00061 const TimeLine<LoadPlan>::Event *f = &*(iter++);
00062 if (iter!=loadplans.end() && iter->getDate()==f->getDate()) continue;
00063
00064
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
00076 shortageQty = delta;
00077 }
00078 else
00079 {
00080 if (shortageProblem)
00081 {
00082
00083 if (f->getDate() != shortageProblemStart)
00084 new ProblemCapacityUnderload(this, DateRange(shortageProblemStart,
00085 f->getDate()), -shortageQty);
00086 shortageProblem = false;
00087 }
00088 }
00089
00090
00091
00092
00093
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
00111 if (f->getDate() != excessProblemStart)
00112 new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00113 f->getDate()), excessQty);
00114 excessProblem = false;
00115 }
00116 }
00117
00118 }
00119
00120
00121 if (excessProblem)
00122 new ProblemCapacityOverload(this, DateRange(excessProblemStart,
00123 Date::infiniteFuture), excessQty);
00124
00125
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 }