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