problems_demand.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 Demand::updateProblems()
00036 {
00037
00038
00039
00040
00041
00042 bool needsNotPlanned(false);
00043 bool needsEarly(false);
00044 bool needsLate(false);
00045 bool needsShort(false);
00046 bool needsExcess(false);
00047
00048
00049 if (!getHidden())
00050 {
00051 if (deli.empty())
00052 {
00053
00054 if (getQuantity()>0.0) needsNotPlanned = true;
00055 }
00056 else
00057 {
00058
00059 for (OperationPlan_list::iterator i = deli.begin(); i!=deli.end(); ++i)
00060 {
00061
00062 long d(getDue() - (*i)->getDates().getEnd());
00063 if (d < 0L) needsLate = true;
00064
00065 else if (d > 0L) needsEarly = true;
00066 }
00067
00068
00069 double plannedqty = getPlannedQuantity();
00070 if (plannedqty + ROUNDING_ERROR < qty) needsShort = true;
00071
00072
00073 if (plannedqty - ROUNDING_ERROR > qty) needsExcess = true;
00074 }
00075 }
00076
00077
00078 for (Problem::const_iterator j = Problem::begin(this, false);
00079 j!=Problem::end(); )
00080 {
00081
00082
00083 Problem& curprob = *j;
00084 ++j;
00085
00086
00087
00088
00089 if (typeid(curprob) == typeid(ProblemEarly))
00090 {
00091
00092 if (needsEarly) needsEarly = false;
00093
00094 else delete &curprob;
00095 }
00096 else if (typeid(curprob) == typeid(ProblemDemandNotPlanned))
00097 {
00098 if (needsNotPlanned) needsNotPlanned = false;
00099 else delete &curprob;
00100 }
00101 else if (typeid(curprob) == typeid(ProblemLate))
00102 {
00103 if (needsLate) needsLate = false;
00104 else delete &curprob;
00105 }
00106 else if (typeid(curprob) == typeid(ProblemShort))
00107 {
00108 if (needsShort) needsShort = false;
00109 else delete &curprob;
00110 }
00111 else if (typeid(curprob) == typeid(ProblemExcess))
00112 {
00113 if (needsExcess) needsExcess = false;
00114 else delete &curprob;
00115 }
00116
00117
00118 }
00119
00120
00121 if (needsNotPlanned) new ProblemDemandNotPlanned(this);
00122 if (needsLate) new ProblemLate(this);
00123 if (needsEarly) new ProblemEarly(this);
00124 if (needsShort) new ProblemShort(this);
00125 if (needsExcess) new ProblemExcess(this);
00126 }
00127
00128
00129 DECLARE_EXPORT string ProblemLate::getDescription() const
00130 {
00131 assert(getDemand() && !getDemand()->getDelivery().empty());
00132 TimePeriod t(getDemand()->getLatestDelivery()->getDates().getEnd()
00133 - getDemand()->getDue());
00134 return string("Demand '") + getDemand()->getName() + "' planned "
00135 + string(t) + " after its due date";
00136 }
00137
00138
00139 DECLARE_EXPORT string ProblemEarly::getDescription() const
00140 {
00141 assert(getDemand() && !getDemand()->getDelivery().empty());
00142 TimePeriod t(getDemand()->getDue()
00143 - getDemand()->getEarliestDelivery()->getDates().getEnd());
00144 return string("Demand '") + getDemand()->getName() + "' planned "
00145 + string(t) + " before its due date";
00146 }
00147
00148 }