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 #ifndef MODEL_H
00029 #define MODEL_H
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "frepple/utils.h"
00041 #include "frepple/timeline.h"
00042 using namespace frepple::utils;
00043
00044 namespace frepple
00045 {
00046
00047 class Flow;
00048 class FlowEnd;
00049 class FlowPlan;
00050 class LoadPlan;
00051 class Resource;
00052 class ResourceInfinite;
00053 class Problem;
00054 class Demand;
00055 class OperationPlan;
00056 class Item;
00057 class Operation;
00058 class OperationPlanState;
00059 class OperationFixedTime;
00060 class OperationTimePer;
00061 class OperationRouting;
00062 class OperationAlternate;
00063 class Buffer;
00064 class BufferInfinite;
00065 class BufferProcure;
00066 class Plan;
00067 class Plannable;
00068 class Calendar;
00069 class Load;
00070 class Location;
00071 class Customer;
00072 class HasProblems;
00073 class Solvable;
00074 class PeggingIterator;
00075
00076
00077
00078 class LibraryModel
00079 {
00080 public:
00081 static void initialize();
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 class Calendar : public HasName<Calendar>
00095 {
00096 public:
00097 class BucketIterator;
00098 class EventIterator;
00099
00100
00101
00102
00103
00104
00105
00106 class Bucket : public Object, public NonCopyable
00107 {
00108 friend class Calendar;
00109 friend class BucketIterator;
00110 friend class EventIterator;
00111 private:
00112
00113 string nm;
00114
00115
00116 Date startdate;
00117
00118
00119 Date enddate;
00120
00121
00122 Bucket* nextBucket;
00123
00124
00125 Bucket* prevBucket;
00126
00127
00128
00129
00130 int priority;
00131
00132
00133 Calendar *cal;
00134
00135
00136
00137
00138
00139 DECLARE_EXPORT void nextEvent(EventIterator*, Date) const;
00140
00141
00142
00143
00144
00145 DECLARE_EXPORT void prevEvent(EventIterator*, Date) const;
00146
00147 protected:
00148
00149 Bucket(Calendar *c, Date start, Date end, string name) : nm(name),
00150 startdate(start), enddate(end), nextBucket(NULL), prevBucket(NULL),
00151 priority(0), cal(c) {initType(metadata);}
00152
00153
00154 DECLARE_EXPORT void writeHeader(XMLOutput *, const Keyword&) const;
00155
00156 public:
00157
00158 Calendar* getCalendar() const {return cal;}
00159
00160
00161
00162
00163
00164
00165 void getValue() const {}
00166
00167
00168
00169
00170 void setValue() {}
00171
00172
00173
00174
00175
00176
00177
00178
00179 string getName() const {return nm.empty() ? string(startdate) : nm;}
00180
00181
00182
00183 bool useDefaultName() const {return nm.empty();}
00184
00185
00186 void setName(const string& s) {nm=s;}
00187
00188
00189 Date getEnd() const {return enddate;}
00190
00191
00192 void setEnd(const Date& d) {enddate = d;}
00193
00194
00195 Date getStart() const {return startdate;}
00196
00197
00198 void setStart(const Date& d) {startdate = d;}
00199
00200
00201
00202
00203
00204
00205 int getPriority() const {return priority;}
00206
00207
00208
00209
00210
00211
00212 void setPriority(int f) {priority = f;}
00213
00214
00215 bool checkValid(Date d) const
00216 {
00217 return true;
00218 }
00219
00220
00221 virtual bool getBool() const {return true;}
00222
00223 virtual DECLARE_EXPORT void writeElement
00224 (XMLOutput*, const Keyword&, mode=DEFAULT) const;
00225
00226
00227
00228
00229
00230 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
00231
00232 virtual const MetaClass& getType() const
00233 {return *metadata;}
00234 virtual size_t getSize() const
00235 {return sizeof(Bucket) + nm.size();}
00236 static DECLARE_EXPORT const MetaCategory* metadata;
00237 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00238 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00239 static int initialize();
00240 };
00241
00242
00243 Calendar(const string& n) : HasName<Calendar>(n), firstBucket(NULL) {}
00244
00245
00246
00247
00248 DECLARE_EXPORT ~Calendar();
00249
00250
00251 virtual bool getBool() const {return false;}
00252
00253
00254
00255
00256
00257
00258
00259 DECLARE_EXPORT Bucket* createBucket(const AttributeList&);
00260
00261
00262 DECLARE_EXPORT Bucket* addBucket(Date, Date, string);
00263
00264
00265 DECLARE_EXPORT void removeBucket(Bucket* bkt);
00266
00267
00268
00269
00270
00271
00272 DECLARE_EXPORT Bucket* findBucket(Date d, bool fwd = true) const;
00273
00274
00275
00276
00277
00278 DECLARE_EXPORT Bucket* findBucket(const string&) const;
00279
00280
00281
00282 class EventIterator
00283 {
00284 friend class Calendar::Bucket;
00285 protected:
00286 const Calendar* theCalendar;
00287 const Bucket* curBucket;
00288 Date curDate;
00289 double curPriority;
00290 public:
00291 const Date& getDate() const {return curDate;}
00292 const Bucket* getBucket() const {return curBucket;}
00293 const Calendar* getCalendar() const {return theCalendar;}
00294 EventIterator(const Calendar* c, Date d = Date::infinitePast,
00295 bool forward = true) : theCalendar(c), curDate(d)
00296 {
00297 if (!c)
00298 throw LogicException("Creating iterator for NULL calendar");
00299 curBucket = c->findBucket(d,forward);
00300 };
00301 DECLARE_EXPORT EventIterator& operator++();
00302 DECLARE_EXPORT EventIterator& operator--();
00303 EventIterator operator++(int)
00304 {EventIterator tmp = *this; ++*this; return tmp;}
00305 EventIterator operator--(int)
00306 {EventIterator tmp = *this; --*this; return tmp;}
00307 };
00308
00309
00310 class BucketIterator
00311 {
00312 private:
00313 Bucket* curBucket;
00314 public:
00315 BucketIterator(Bucket* b = NULL) : curBucket(b) {}
00316 bool operator != (const BucketIterator &b) const
00317 {return b.curBucket != curBucket;}
00318 bool operator == (const BucketIterator &b) const
00319 {return b.curBucket == curBucket;}
00320 BucketIterator& operator++()
00321 {if (curBucket) curBucket = curBucket->nextBucket; return *this;}
00322 BucketIterator operator++(int)
00323 {BucketIterator tmp = *this; ++*this; return tmp;}
00324 BucketIterator& operator--()
00325 {if(curBucket) curBucket = curBucket->prevBucket; return *this;}
00326 BucketIterator operator--(int)
00327 {BucketIterator tmp = *this; --*this; return tmp;}
00328 Bucket* operator ->() const {return curBucket;}
00329 Bucket& operator *() const {return *curBucket;}
00330 };
00331
00332
00333 BucketIterator beginBuckets() const {return BucketIterator(firstBucket);}
00334
00335
00336 BucketIterator endBuckets() const {return BucketIterator(NULL);}
00337
00338 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
00339 void endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement) {}
00340 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
00341 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00342 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00343 static int initialize();
00344
00345 static DECLARE_EXPORT PyObject* getEvents(PyObject*, PyObject*, PyObject*);
00346
00347 virtual const MetaClass& getType() const {return *metadata;}
00348 static DECLARE_EXPORT const MetaCategory* metadata;
00349
00350 virtual size_t getSize() const
00351 {
00352 size_t i = sizeof(Calendar) + getName().size();
00353 for (BucketIterator j = beginBuckets(); j!= endBuckets(); ++j)
00354 i += j->getSize();
00355 return i;
00356 }
00357
00358 protected:
00359
00360 int lowestPriority() const
00361 {
00362 int min = 0;
00363 for (BucketIterator i = beginBuckets(); i != endBuckets(); ++i)
00364 if (i->getPriority() < min) min = i->getPriority();
00365 return min;
00366 }
00367
00368 private:
00369
00370
00371 Bucket* firstBucket;
00372
00373
00374
00375 virtual Bucket* createNewBucket(Date start, Date end, string name)
00376 {return new Bucket(this, start,end,name);}
00377 };
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 template <typename T> class CalendarValue : public Calendar
00389 {
00390 public:
00391
00392
00393
00394
00395 class BucketValue : public Calendar::Bucket
00396 {
00397 friend class CalendarValue<T>;
00398 private:
00399
00400 T val;
00401
00402
00403 BucketValue(CalendarValue<T> *c, Date start, Date end, string name)
00404 : Bucket(c,start,end,name), val(c->getDefault()) {}
00405
00406 public:
00407
00408 const T& getValue() const {return val;}
00409
00410
00411 bool getBool() const {return val != 0;}
00412
00413
00414 void setValue(const T& v) {val = v;}
00415
00416 void writeElement
00417 (XMLOutput *o, const Keyword& tag, mode m = DEFAULT) const
00418 {
00419 assert(m == DEFAULT || m == FULL);
00420 writeHeader(o, tag);
00421 if (getPriority()) o->writeElement(Tags::tag_priority, getPriority());
00422 o->writeElement(Tags::tag_value, val);
00423 o->EndObject(tag);
00424 }
00425
00426 void endElement (XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00427 {
00428 if (pAttr.isA(Tags::tag_value))
00429 pElement >> val;
00430 else
00431 Bucket::endElement(pIn, pAttr, pElement);
00432 }
00433
00434 virtual const MetaClass& getType() const
00435 {return *Calendar::Bucket::metadata;}
00436
00437 virtual size_t getSize() const
00438 {return sizeof(typename CalendarValue<T>::BucketValue) + getName().size();}
00439 };
00440
00441
00442
00443 class EventIterator : public Calendar::EventIterator
00444 {
00445 public:
00446
00447 EventIterator(const Calendar* c, Date d = Date::infinitePast,
00448 bool f = true) : Calendar::EventIterator(c,d,f) {}
00449
00450
00451 T getValue()
00452 {
00453 typedef CalendarValue<T> calendarvaluetype;
00454 typedef typename CalendarValue<T>::BucketValue bucketvaluetype;
00455 return curBucket ?
00456 static_cast<const bucketvaluetype*>(curBucket)->getValue() :
00457 static_cast<const calendarvaluetype*>(theCalendar)->getDefault();
00458 }
00459 };
00460
00461
00462 CalendarValue(const string& n) : Calendar(n) {}
00463
00464
00465 const T& getValue(const Date d) const
00466 {
00467 BucketValue* x = static_cast<BucketValue*>(findBucket(d));
00468 return x ? x->getValue() : defaultValue;
00469 }
00470
00471
00472
00473 void setValue(Date start, Date end, const T& v)
00474 {
00475 BucketValue* x = static_cast<BucketValue*>(findBucket(start));
00476 if (x && x->getStart() == start && x->getEnd() <= end)
00477
00478
00479 x->setEnd(end);
00480 else
00481
00482 x = static_cast<BucketValue*>(addBucket(start,end,""));
00483 x->setValue(v);
00484 x->setPriority(lowestPriority()-1);
00485 }
00486
00487 virtual const MetaClass& getType() const = 0;
00488
00489 const T& getValue(Calendar::BucketIterator& i) const
00490 {return reinterpret_cast<BucketValue&>(*i).getValue();}
00491
00492
00493 virtual T getDefault() const {return defaultValue;}
00494
00495
00496 virtual bool getBool() const {return defaultValue != 0;}
00497
00498
00499 virtual void setDefault(const T v) {defaultValue = v;}
00500
00501 void writeElement(XMLOutput *o, const Keyword& tag, mode m=DEFAULT) const
00502 {
00503
00504 if (m == REFERENCE)
00505 {
00506 o->writeElement
00507 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00508 return;
00509 }
00510
00511
00512 if (m != NOHEADER) o->BeginObject
00513 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00514
00515
00516 o->writeElement(Tags::tag_default, getDefault());
00517
00518
00519 o->BeginObject (Tags::tag_buckets);
00520 for (BucketIterator i = beginBuckets(); i != endBuckets(); ++i)
00521
00522
00523 o->writeElement(Tags::tag_bucket, *i, FULL);
00524 o->EndObject(Tags::tag_buckets);
00525
00526 o->EndObject(tag);
00527 }
00528
00529 void endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00530 {
00531 if (pAttr.isA(Tags::tag_default))
00532 pElement >> defaultValue;
00533 else
00534 Calendar::endElement(pIn, pAttr, pElement);
00535 }
00536
00537 private:
00538
00539
00540
00541 Bucket* createNewBucket(Date start, Date end, string name)
00542 {return new BucketValue(this,start,end,name);}
00543
00544
00545 T defaultValue;
00546 };
00547
00548
00549
00550 template <> DECLARE_EXPORT bool CalendarValue<string>::getBool() const;
00551 template <> DECLARE_EXPORT bool CalendarValue<string>::BucketValue::getBool() const;
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563 template <typename T> class CalendarPointer : public Calendar
00564 {
00565 public:
00566
00567
00568
00569
00570 class BucketPointer : public Calendar::Bucket
00571 {
00572 friend class CalendarPointer<T>;
00573 private:
00574
00575 T* val;
00576
00577
00578 BucketPointer(CalendarPointer<T> *c, Date start, Date end, string name)
00579 : Bucket(c,start,end,name), val(c->getDefault()) {};
00580
00581 public:
00582
00583 T* getValue() const {return val;}
00584
00585
00586 bool getBool() const {return val != NULL;}
00587
00588
00589 void setValue(T* v) {val = v;}
00590
00591 void writeElement
00592 (XMLOutput *o, const Keyword& tag, mode m = DEFAULT) const
00593 {
00594 assert(m == DEFAULT || m == FULL);
00595 writeHeader(o, tag);
00596 if (getPriority()) o->writeElement(Tags::tag_priority, getPriority());
00597 if (val) o->writeElement(Tags::tag_value, val);
00598 o->EndObject(tag);
00599 }
00600
00601 void beginElement(XMLInput& pIn, const Attribute& pAttr)
00602 {
00603 if (pAttr.isA(Tags::tag_value))
00604 pIn.readto(
00605 MetaCategory::ControllerDefault(T::metadata,pIn.getAttributes())
00606 );
00607 else
00608 Bucket::beginElement(pIn, pAttr);
00609 }
00610
00611 void endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00612 {
00613 if (pAttr.isA(Tags::tag_value))
00614 {
00615 T *o = dynamic_cast<T*>(pIn.getPreviousObject());
00616 if (!o)
00617 throw LogicException
00618 ("Incorrect object type during read operation");
00619 val = o;
00620 }
00621 else
00622 Bucket::endElement(pIn, pAttr, pElement);
00623 }
00624
00625 virtual const MetaClass& getType() const
00626 {return *Calendar::Bucket::metadata;}
00627
00628 virtual size_t getSize() const
00629 {return sizeof(typename CalendarPointer<T>::BucketPointer) + getName().size();}
00630 };
00631
00632
00633
00634 class EventIterator : public Calendar::EventIterator
00635 {
00636 public:
00637
00638 EventIterator(const Calendar* c, Date d = Date::infinitePast,
00639 bool f = true) : Calendar::EventIterator(c,d,f) {}
00640
00641
00642 const T* getValue()
00643 {
00644 typedef CalendarPointer<T> calendarpointertype;
00645 typedef typename CalendarPointer<T>::BucketPointer bucketpointertype;
00646 return curBucket ?
00647 static_cast<const bucketpointertype*>(curBucket)->getValue() :
00648 static_cast<const calendarpointertype*>(theCalendar)->getDefault();
00649 }
00650 };
00651
00652
00653 CalendarPointer(const string& n) : Calendar(n), defaultValue(NULL) {}
00654
00655
00656 T* getValue(const Date d) const
00657 {
00658 BucketPointer* x = static_cast<BucketPointer*>(findBucket(d));
00659 return x ? x->getValue() : defaultValue;
00660 }
00661
00662
00663 virtual bool getBool() const {return defaultValue != NULL;}
00664
00665
00666
00667 void setValue(Date start, Date end, T* v)
00668 {
00669 BucketPointer* x = static_cast<BucketPointer*>(findBucket(start));
00670 if (x && x->getStart() == start && x->getEnd() <= end)
00671
00672
00673 x->setEnd(end);
00674 else
00675
00676 x = static_cast<BucketPointer*>(addBucket(start,end,""));
00677 x->setValue(v);
00678 x->setPriority(lowestPriority()-1);
00679 }
00680
00681
00682 virtual T* getDefault() const {return defaultValue;}
00683
00684
00685 virtual void setDefault(T* v) {defaultValue = v;}
00686
00687 virtual const MetaClass& getType() const = 0;
00688
00689 void writeElement(XMLOutput *o, const Keyword& tag, mode m=DEFAULT) const
00690 {
00691
00692 if (m == REFERENCE)
00693 {
00694 o->writeElement
00695 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00696 return;
00697 }
00698
00699
00700 if (m != NOHEADER) o->BeginObject
00701 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00702
00703
00704 if (defaultValue) o->writeElement(Tags::tag_default, defaultValue);
00705
00706
00707 o->BeginObject (Tags::tag_buckets);
00708 for (BucketIterator i = beginBuckets(); i != endBuckets(); ++i)
00709
00710
00711 o->writeElement(Tags::tag_bucket, *i, FULL);
00712 o->EndObject(Tags::tag_buckets);
00713
00714 o->EndObject(tag);
00715 }
00716
00717 void beginElement(XMLInput& pIn, const Attribute& pAttr)
00718 {
00719 if (pAttr.isA (Tags::tag_default))
00720 pIn.readto(T::reader(T::metadata,pIn.getAttributes()));
00721 else
00722 Calendar::beginElement(pIn, pAttr);
00723 }
00724
00725 void endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00726 {
00727 if (pAttr.isA(Tags::tag_default))
00728 {
00729 T *o = dynamic_cast<T*>(pIn.getPreviousObject());
00730 if (!o)
00731 throw LogicException("Incorrect object type during read operation");
00732 defaultValue = o;
00733 }
00734 else
00735 Calendar::endElement(pIn, pAttr, pElement);
00736 }
00737
00738 private:
00739
00740
00741
00742 Bucket* createNewBucket(Date start, Date end, string name)
00743 {return new BucketPointer(this,start,end,name);}
00744
00745
00746 T* defaultValue;
00747 };
00748
00749
00750
00751
00752 class CalendarVoid : public Calendar
00753 {
00754 public:
00755 CalendarVoid(const string& n) : Calendar(n) {initType(metadata);}
00756 virtual const MetaClass& getType() const {return *metadata;}
00757 static DECLARE_EXPORT const MetaClass* metadata;
00758 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00759 static int initialize();
00760 };
00761
00762
00763
00764 class CalendarDouble : public CalendarValue<double>
00765 {
00766 public:
00767 CalendarDouble(const string& n) : CalendarValue<double>(n)
00768 {setDefault(0.0); initType(metadata);}
00769 DECLARE_EXPORT ~CalendarDouble();
00770 virtual const MetaClass& getType() const {return *metadata;}
00771 static DECLARE_EXPORT const MetaClass* metadata;
00772 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00773 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00774 static int initialize();
00775
00776 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00777 };
00778
00779
00780
00781 class CalendarInt : public CalendarValue<int>
00782 {
00783 public:
00784 CalendarInt(const string& n) : CalendarValue<int>(n)
00785 {setDefault(0); initType(metadata);}
00786 virtual const MetaClass& getType() const {return *metadata;}
00787 static DECLARE_EXPORT const MetaClass* metadata;
00788 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00789 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00790 static int initialize();
00791
00792 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00793 };
00794
00795
00796
00797 class CalendarBool : public CalendarValue<bool>
00798 {
00799 public:
00800 CalendarBool(const string& n) : CalendarValue<bool>(n)
00801 {setDefault(false); initType(metadata);}
00802 DECLARE_EXPORT ~CalendarBool();
00803 virtual const MetaClass& getType() const {return *metadata;}
00804 static DECLARE_EXPORT const MetaClass* metadata;
00805 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00806 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00807 static int initialize();
00808
00809 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00810 };
00811
00812
00813
00814 class CalendarString : public CalendarValue<string>
00815 {
00816 public:
00817 CalendarString(const string& n) : CalendarValue<string>(n) {initType(metadata);}
00818 virtual const MetaClass& getType() const {return *metadata;}
00819 bool getBool() const {return getDefault().empty();}
00820 static DECLARE_EXPORT const MetaClass* metadata;
00821 virtual size_t getSize() const
00822 {
00823 size_t i = sizeof(CalendarString);
00824 for (BucketIterator j = beginBuckets(); j!= endBuckets(); ++j)
00825 i += j->getSize()
00826 + static_cast<CalendarValue<string>::BucketValue&>(*j).getValue().size();
00827 return i;
00828 }
00829 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00830 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00831 static int initialize();
00832
00833 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00834 };
00835
00836
00837
00838 class CalendarOperation : public CalendarPointer<Operation>
00839 {
00840 public:
00841 CalendarOperation(const string& n) : CalendarPointer<Operation>(n)
00842 {initType(metadata);}
00843 virtual const MetaClass& getType() const {return *metadata;}
00844 static DECLARE_EXPORT const MetaClass* metadata;
00845 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
00846 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
00847 static int initialize();
00848
00849 static DECLARE_EXPORT PyObject* setPythonValue(PyObject*, PyObject*, PyObject*);
00850 };
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874 class Problem : public NonCopyable, public Object
00875 {
00876 public:
00877 class const_iterator;
00878 friend class const_iterator;
00879
00880
00881
00882
00883
00884
00885 explicit Problem(HasProblems *p) : owner(p)
00886 {
00887 if (!owner) throw LogicException("Invalid problem creation");
00888 initType(metadata);
00889 }
00890
00891
00892 static int initialize();
00893
00894
00895
00896
00897 virtual ~Problem() {}
00898
00899
00900 virtual const DateRange getDateRange() const = 0;
00901
00902
00903 virtual string getDescription() const = 0;
00904
00905
00906 virtual string getEntity() const = 0;
00907
00908
00909
00910
00911
00912
00913 virtual bool isFeasible() const = 0;
00914
00915
00916
00917
00918
00919 virtual double getWeight() const = 0;
00920
00921 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
00922 void endElement(XMLInput&, const Attribute&, const DataElement&) {}
00923 static DECLARE_EXPORT void writer(const MetaCategory*, XMLOutput*);
00924
00925 PyObject* getattro(const Attribute&);
00926
00927 PyObject* str() const
00928 {
00929 return PythonObject(getDescription());
00930 }
00931
00932
00933
00934 static DECLARE_EXPORT const_iterator begin();
00935
00936
00937
00938
00939
00940
00941
00942 static DECLARE_EXPORT const_iterator begin(HasProblems*, bool = true);
00943
00944
00945 static DECLARE_EXPORT const const_iterator end();
00946
00947
00948
00949
00950
00951 static DECLARE_EXPORT void clearProblems();
00952
00953
00954
00955
00956
00957 static DECLARE_EXPORT void clearProblems(HasProblems& p, bool setchanged = true);
00958
00959
00960 virtual Object* getOwner() const = 0;
00961
00962
00963 virtual const MetaClass& getType() const {return *metadata;}
00964
00965
00966 static DECLARE_EXPORT const MetaCategory* metadata;
00967
00968 protected:
00969
00970 HasProblems *owner;
00971
00972
00973
00974
00975 Problem *nextProblem;
00976
00977
00978
00979
00980
00981
00982
00983
00984 DECLARE_EXPORT void addProblem();
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995 DECLARE_EXPORT void removeProblem();
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009 DECLARE_EXPORT bool operator < (const Problem& a) const;
01010 };
01011
01012
01013
01014
01015
01016
01017
01018
01019 class HasProblems
01020 {
01021 friend class Problem::const_iterator;
01022 friend class Problem;
01023 public:
01024 class EntityIterator;
01025
01026
01027 static DECLARE_EXPORT EntityIterator beginEntity();
01028
01029
01030 static DECLARE_EXPORT EntityIterator endEntity();
01031
01032
01033 HasProblems() : firstProblem(NULL) {}
01034
01035
01036
01037 virtual ~HasProblems() {Problem::clearProblems(*this, false);}
01038
01039
01040 virtual Plannable* getEntity() const = 0;
01041
01042
01043
01044
01045
01046
01047
01048 virtual void updateProblems() = 0;
01049
01050 private:
01051
01052
01053 Problem* firstProblem;
01054 };
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065 class Solver : public HasName<Solver>
01066 {
01067 public:
01068 explicit Solver(const string& n) : HasName<Solver>(n), loglevel(0) {}
01069 virtual ~Solver() {}
01070
01071 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
01072 virtual DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
01073 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
01074 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
01075 static int initialize();
01076
01077 static DECLARE_EXPORT PyObject* solve(PyObject*, PyObject*);
01078
01079 virtual void solve(void* = NULL) = 0;
01080 virtual void solve(const Demand*,void* = NULL)
01081 {throw LogicException("Called undefined solve(Demand*) method");}
01082 virtual void solve(const Operation*,void* = NULL)
01083 {throw LogicException("Called undefined solve(Operation*) method");}
01084 virtual void solve(const OperationFixedTime* o, void* v = NULL)
01085 {solve(reinterpret_cast<const Operation*>(o),v);}
01086 virtual void solve(const OperationTimePer* o, void* v = NULL)
01087 {solve(reinterpret_cast<const Operation*>(o),v);}
01088 virtual void solve(const OperationRouting* o, void* v = NULL)
01089 {solve(reinterpret_cast<const Operation*>(o),v);}
01090 virtual void solve(const OperationAlternate* o, void* v = NULL)
01091 {solve(reinterpret_cast<const Operation*>(o),v);}
01092 virtual void solve(const Resource*,void* = NULL)
01093 {throw LogicException("Called undefined solve(Resource*) method");}
01094 virtual void solve(const ResourceInfinite* r, void* v = NULL)
01095 {solve(reinterpret_cast<const Resource*>(r),v);}
01096 virtual void solve(const Buffer*,void* = NULL)
01097 {throw LogicException("Called undefined solve(Buffer*) method");}
01098 virtual void solve(const BufferInfinite* b, void* v = NULL)
01099 {solve(reinterpret_cast<const Buffer*>(b),v);}
01100 virtual void solve(const BufferProcure* b, void* v = NULL)
01101 {solve(reinterpret_cast<const Buffer*>(b),v);}
01102 virtual void solve(const Load* b, void* v = NULL)
01103 {throw LogicException("Called undefined solve(Load*) method");}
01104 virtual void solve(const Flow* b, void* v = NULL)
01105 {throw LogicException("Called undefined solve(Flow*) method");}
01106 virtual void solve(const FlowEnd* b, void* v = NULL)
01107 {solve(reinterpret_cast<const Flow*>(b),v);}
01108 virtual void solve(const Solvable*,void* = NULL)
01109 {throw LogicException("Called undefined solve(Solvable*) method");}
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124 unsigned short getLogLevel() const {return loglevel;}
01125
01126
01127 void setLogLevel(unsigned short v) {loglevel = v;}
01128
01129 virtual const MetaClass& getType() const {return *metadata;}
01130 static DECLARE_EXPORT const MetaCategory* metadata;
01131
01132 private:
01133
01134 unsigned short loglevel;
01135 };
01136
01137
01138
01139
01140
01141 class Solvable
01142 {
01143 public:
01144
01145
01146
01147
01148
01149 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
01150
01151
01152 virtual ~Solvable() {}
01153 };
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164 class Plannable : public HasProblems, public Solvable
01165 {
01166 public:
01167
01168 Plannable() : useProblemDetection(true), changed(true)
01169 {anyChange = true;}
01170
01171
01172 DECLARE_EXPORT void setDetectProblems(bool b);
01173
01174
01175 bool getDetectProblems() const {return useProblemDetection;}
01176
01177
01178
01179 static DECLARE_EXPORT void computeProblems();
01180
01181
01182
01183 bool getChanged() const {return changed;}
01184
01185
01186
01187 void setChanged(bool b = true) {changed=b; if (b) anyChange=true;}
01188
01189
01190 Plannable* getEntity() const {return const_cast<Plannable*>(this);}
01191
01192 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
01193 virtual DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
01194
01195 private:
01196
01197 bool useProblemDetection;
01198
01199
01200
01201 bool changed;
01202
01203
01204
01205
01206 static DECLARE_EXPORT bool anyChange;
01207
01208
01209
01210
01211
01212 static DECLARE_EXPORT bool computationBusy;
01213 };
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230 class HasLevel
01231 {
01232
01233 #if defined(_MSC_VER) || defined(__BORLANDC__)
01234
01235
01236 friend class HasLevel;
01237 #endif
01238
01239 private:
01240
01241
01242
01243
01244 static DECLARE_EXPORT bool recomputeLevels;
01245
01246
01247
01248
01249
01250 static DECLARE_EXPORT bool computationBusy;
01251
01252
01253 static DECLARE_EXPORT unsigned short numberOfClusters;
01254
01255
01256 static DECLARE_EXPORT unsigned short numberOfHangingClusters;
01257
01258
01259
01260
01261
01262 short lvl;
01263
01264
01265 unsigned short cluster;
01266
01267 protected:
01268
01269
01270
01271
01272 HasLevel() : lvl(0), cluster(0) {}
01273
01274
01275
01276
01277
01278 HasLevel(const HasLevel& o) : lvl(o.lvl), cluster(o.cluster) {}
01279
01280
01281
01282
01283 ~HasLevel() {recomputeLevels = true;}
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302 static DECLARE_EXPORT void computeLevels();
01303
01304 public:
01305
01306
01307
01308 static unsigned short getNumberOfClusters()
01309 {
01310 if (recomputeLevels || computationBusy) computeLevels();
01311 return numberOfClusters;
01312 }
01313
01314
01315
01316
01317
01318
01319 static unsigned short getNumberOfHangingClusters()
01320 {
01321 if (recomputeLevels || computationBusy) computeLevels();
01322 return numberOfHangingClusters;
01323 }
01324
01325
01326 short getLevel() const
01327 {
01328 if (recomputeLevels || computationBusy) computeLevels();
01329 return lvl;
01330 }
01331
01332
01333 unsigned short getCluster() const
01334 {
01335 if (recomputeLevels || computationBusy) computeLevels();
01336 return cluster;
01337 }
01338
01339
01340
01341
01342
01343
01344 static void triggerLazyRecomputation() {recomputeLevels = true;}
01345 };
01346
01347
01348
01349
01350
01351
01352
01353
01354 class Location : public HasHierarchy<Location>, public HasDescription
01355 {
01356 public:
01357
01358 explicit Location(const string& n) : HasHierarchy<Location>(n), available(NULL) {}
01359
01360
01361 virtual DECLARE_EXPORT ~Location();
01362
01363
01364
01365
01366
01367 CalendarBool *getAvailable() const {return available;}
01368
01369
01370 void setAvailable(CalendarBool* b) {available = b;}
01371
01372 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
01373 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
01374 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
01375 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
01376 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
01377 size_t extrasize() const
01378 {return getName().size() + HasDescription::extrasize();}
01379 virtual const MetaClass& getType() const {return *metadata;}
01380 static DECLARE_EXPORT const MetaCategory* metadata;
01381 static int initialize();
01382
01383 private:
01384
01385
01386
01387 CalendarBool* available;
01388 };
01389
01390
01391
01392 class LocationDefault : public Location
01393 {
01394 public:
01395 explicit LocationDefault(const string& str) : Location(str) {initType(metadata);}
01396 virtual const MetaClass& getType() const {return *metadata;}
01397 static DECLARE_EXPORT const MetaClass* metadata;
01398 virtual size_t getSize() const
01399 {return sizeof(LocationDefault) + Location::extrasize();}
01400 static int initialize();
01401 };
01402
01403
01404
01405
01406
01407
01408
01409 class Customer : public HasHierarchy<Customer>, public HasDescription
01410 {
01411 public:
01412 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
01413 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
01414 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
01415 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
01416 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
01417 size_t extrasize() const
01418 {return getName().size() + HasDescription::extrasize();}
01419 Customer(const string& n) : HasHierarchy<Customer>(n) {}
01420 virtual DECLARE_EXPORT ~Customer();
01421 virtual const MetaClass& getType() const {return *metadata;}
01422 static DECLARE_EXPORT const MetaCategory* metadata;
01423 static int initialize();
01424 };
01425
01426
01427
01428 class CustomerDefault : public Customer
01429 {
01430 public:
01431 explicit CustomerDefault(const string& str) : Customer(str) {initType(metadata);}
01432 virtual const MetaClass& getType() const {return *metadata;}
01433 static DECLARE_EXPORT const MetaClass* metadata;
01434 virtual size_t getSize() const
01435 {return sizeof(CustomerDefault) + Customer::extrasize();}
01436 static int initialize();
01437 };
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448 class Operation : public HasName<Operation>,
01449 public HasLevel, public Plannable, public HasDescription
01450 {
01451 friend class Flow;
01452 friend class Load;
01453 friend class OperationPlan;
01454 friend class OperationRouting;
01455 friend class OperationAlternate;
01456
01457 protected:
01458
01459 explicit Operation(const string& str) : HasName<Operation>(str),
01460 loc(NULL), size_minimum(1.0), size_multiple(0.0), size_maximum(DBL_MAX),
01461 cost(0.0), hidden(false), first_opplan(NULL), last_opplan(NULL) {}
01462
01463
01464
01465
01466
01467 virtual bool extraInstantiate(OperationPlan* o) {return true;}
01468
01469 public:
01470
01471 virtual DECLARE_EXPORT ~Operation();
01472
01473
01474 OperationPlan* getFirstOpPlan() const {return first_opplan;}
01475
01476
01477
01478
01479 TimePeriod getPreTime() const {return pre_time;}
01480
01481
01482
01483
01484
01485
01486
01487 void setPreTime(TimePeriod t)
01488 {
01489 if (t<TimePeriod(0L))
01490 throw DataException("No negative pre-operation time allowed");
01491 pre_time=t;
01492 setChanged();
01493 }
01494
01495
01496
01497
01498 TimePeriod getPostTime() const {return post_time;}
01499
01500
01501
01502
01503
01504
01505
01506 void setPostTime(TimePeriod t)
01507 {
01508 if (t<TimePeriod(0L))
01509 throw DataException("No negative post-operation time allowed");
01510 post_time=t;
01511 setChanged();
01512 }
01513
01514
01515
01516
01517
01518
01519 double getCost() const {return cost;}
01520
01521
01522
01523
01524 void setCost(const double c)
01525 {
01526 if (c >= 0) cost = c;
01527 else throw DataException("Operation cost must be positive");
01528 }
01529
01530 typedef Association<Operation,Buffer,Flow>::ListA flowlist;
01531 typedef Association<Operation,Resource,Load>::ListA loadlist;
01532
01533
01534
01535 DECLARE_EXPORT OperationPlan* createOperationPlan(double, Date,
01536 Date, Demand* = NULL, OperationPlan* = NULL, unsigned long = 0,
01537 bool makeflowsloads=true) const;
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555 DECLARE_EXPORT DateRange calculateOperationTime
01556 (Date thedate, TimePeriod duration, bool forward,
01557 TimePeriod* actualduration = NULL) const;
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569
01570
01571
01572 DECLARE_EXPORT DateRange calculateOperationTime
01573 (Date start, Date end, TimePeriod* actualduration = NULL) const;
01574
01575
01576
01577
01578
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607
01608
01609
01610
01611
01612
01613 virtual OperationPlanState setOperationPlanParameters
01614 (OperationPlan*, double, Date, Date, bool=true, bool=true) const = 0;
01615
01616
01617
01618 Location* getLocation() const {return loc;}
01619
01620
01621
01622 void setLocation(Location* l) {loc = l;}
01623
01624
01625 const flowlist& getFlows() const {return flowdata;}
01626
01627
01628 const loadlist& getLoads() const {return loaddata;}
01629
01630
01631
01632 Flow* findFlow(const Buffer* b, Date d) const
01633 {return flowdata.find(b,d);}
01634
01635
01636
01637 Load* findLoad(const Resource* r, Date d) const
01638 {return loaddata.find(r,d);}
01639
01640
01641
01642
01643 DECLARE_EXPORT void deleteOperationPlans(bool deleteLockedOpplans = false);
01644
01645
01646
01647
01648 void setSizeMinimum(double f)
01649 {
01650 if (f<0)
01651 throw DataException("Operation can't have a negative minimum size");
01652 size_minimum = f;
01653 setChanged();
01654 }
01655
01656
01657 double getSizeMinimum() const {return size_minimum;}
01658
01659
01660 void setSizeMultiple(double f)
01661 {
01662 if (f<0)
01663 throw DataException("Operation can't have a negative multiple size");
01664 size_multiple = f;
01665 setChanged();
01666 }
01667
01668
01669 double getSizeMultiple() const {return size_multiple;}
01670
01671
01672 void setSizeMaximum(double f)
01673 {
01674 if (f < size_minimum)
01675 throw DataException("Operation maximum size must be higher than the minimum size");
01676 if (f <= 0)
01677 throw DataException("Operation maximum size must be greater than 0");
01678 size_maximum = f;
01679 setChanged();
01680 }
01681
01682
01683 double getSizeMaximum() const {return size_maximum;}
01684
01685 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
01686 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
01687 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
01688 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
01689 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
01690 static int initialize();
01691
01692 size_t extrasize() const
01693 {return getName().size() + HasDescription::extrasize();}
01694
01695 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
01696
01697 typedef list<Operation*> Operationlist;
01698
01699
01700 virtual const Operationlist& getSubOperations() const {return nosubOperations;}
01701
01702
01703
01704
01705 const Operationlist& getSuperOperations() const {return superoplist;}
01706
01707
01708
01709 void addSuperOperation(Operation * o) {superoplist.push_front(o);}
01710
01711
01712
01713 virtual void removeSubOperation(Operation *o) {}
01714
01715
01716 void removeSuperOperation(Operation *o)
01717 {superoplist.remove(o); o->removeSubOperation(this);}
01718
01719
01720 TimePeriod getFence() const {return fence;}
01721
01722
01723 void setFence(TimePeriod t) {if (fence!=t) setChanged(); fence=t;}
01724
01725 virtual DECLARE_EXPORT void updateProblems();
01726
01727 void setHidden(bool b) {if (hidden!=b) setChanged(); hidden = b;}
01728 bool getHidden() const {return hidden;}
01729
01730 static DECLARE_EXPORT const MetaCategory* metadata;
01731
01732 protected:
01733 DECLARE_EXPORT void initOperationPlan(OperationPlan*, double,
01734 const Date&, const Date&, Demand*, OperationPlan*, unsigned long,
01735 bool = true) const;
01736
01737 private:
01738
01739 Operationlist superoplist;
01740
01741
01742
01743
01744
01745 static DECLARE_EXPORT Operationlist nosubOperations;
01746
01747
01748
01749
01750 Location* loc;
01751
01752
01753 TimePeriod post_time;
01754
01755
01756 TimePeriod pre_time;
01757
01758
01759
01760
01761
01762 TimePeriod fence;
01763
01764
01765 flowlist flowdata;
01766
01767
01768 loadlist loaddata;
01769
01770
01771
01772
01773 double size_minimum;
01774
01775
01776 double size_multiple;
01777
01778
01779 double size_maximum;
01780
01781
01782
01783
01784 double cost;
01785
01786
01787 bool hidden;
01788
01789
01790
01791
01792
01793 OperationPlan* first_opplan;
01794
01795
01796
01797
01798
01799 OperationPlan* last_opplan;
01800 };
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823 class OperationPlan
01824 : public Object, public HasProblems, public NonCopyable
01825 {
01826 friend class FlowPlan;
01827 friend class LoadPlan;
01828 friend class Demand;
01829 friend class Operation;
01830 friend class OperationAlternate;
01831 friend class OperationRouting;
01832 friend class ProblemPrecedence;
01833
01834 public:
01835 class FlowPlanIterator;
01836
01837
01838 FlowPlanIterator beginFlowPlans() const;
01839
01840
01841 FlowPlanIterator endFlowPlans() const;
01842
01843
01844 int sizeFlowPlans() const;
01845
01846 class LoadPlanIterator;
01847
01848
01849 LoadPlanIterator beginLoadPlans() const;
01850
01851
01852 LoadPlanIterator endLoadPlans() const;
01853
01854
01855 int sizeLoadPlans() const;
01856
01857
01858
01859
01860
01861
01862 class iterator
01863 {
01864 public:
01865
01866
01867 iterator(const Operation* x) : op(Operation::end()), mode(1)
01868 {
01869 opplan = x ? x->getFirstOpPlan() : NULL;
01870 }
01871
01872
01873
01874 iterator(const OperationPlan* x) : op(Operation::end()), mode(2)
01875 {
01876 opplan = x ? x->firstsubopplan : NULL;
01877 }
01878
01879
01880 iterator() : op(Operation::begin()), mode(3)
01881 {
01882
01883
01884 while (op!=Operation::end() && !op->getFirstOpPlan()) ++op;
01885 if (op!=Operation::end())
01886 opplan = op->getFirstOpPlan();
01887 else
01888 opplan = NULL;
01889 }
01890
01891
01892 iterator(const iterator& it) : opplan(it.opplan), op(it.op), mode(it.mode) {}
01893
01894
01895 OperationPlan& operator*() const {return *opplan;}
01896
01897
01898 OperationPlan* operator->() const {return opplan;}
01899
01900
01901
01902 iterator& operator++()
01903 {
01904 if (mode == 2)
01905 opplan = opplan->nextsubopplan;
01906 else
01907 opplan = opplan->next;
01908
01909 if (!opplan && mode == 3)
01910 {
01911 do ++op;
01912 while (op!=Operation::end() && (!op->getFirstOpPlan() || op->getHidden()));
01913 if (op!=Operation::end())
01914 opplan = op->getFirstOpPlan();
01915 else
01916 opplan = NULL;
01917 }
01918 return *this;
01919 }
01920
01921
01922
01923 iterator operator++(int)
01924 {
01925 iterator tmp(*this);
01926 if (mode == 2)
01927 opplan = opplan->nextsubopplan;
01928 else
01929 opplan = opplan->next;
01930
01931 if (!opplan && mode==3)
01932 {
01933 do ++op; while (op!=Operation::end() && !op->getFirstOpPlan());
01934 if (op!=Operation::end())
01935 opplan = op->getFirstOpPlan();
01936 else
01937 opplan = NULL;
01938 }
01939 return tmp;
01940 }
01941
01942
01943 bool operator==(const iterator& y) const {return opplan == y.opplan;}
01944
01945
01946 bool operator!=(const iterator& y) const {return opplan != y.opplan;}
01947
01948 private:
01949
01950 OperationPlan* opplan;
01951
01952
01953 Operation::iterator op;
01954
01955
01956
01957
01958
01959
01960 short mode;
01961 };
01962
01963 friend class iterator;
01964
01965 static iterator end() {return iterator(static_cast<Operation*>(NULL));}
01966
01967 static iterator begin() {return iterator();}
01968
01969
01970 static bool empty() {return begin()==end();}
01971
01972
01973
01974
01975
01976 static unsigned long size()
01977 {
01978 unsigned long cnt = 0;
01979 for (OperationPlan::iterator i = begin(); i != end(); ++i) ++cnt;
01980 return cnt;
01981 }
01982
01983
01984
01985
01986
01987
01988 static DECLARE_EXPORT Object* createOperationPlan(const MetaClass*, const AttributeList&);
01989
01990
01991 virtual DECLARE_EXPORT ~OperationPlan();
01992
01993 virtual DECLARE_EXPORT void setChanged(bool b = true);
01994
01995
01996 double getQuantity() const {return quantity;}
01997
01998
01999
02000
02001
02002
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012 virtual DECLARE_EXPORT double setQuantity(double f,
02013 bool roundDown = false, bool update = true, bool execute = true);
02014
02015
02016
02017
02018 Demand* getDemand() const {return dmd;}
02019
02020
02021 DECLARE_EXPORT void setDemand(Demand* l);
02022
02023
02024 DECLARE_EXPORT double getPenalty() const;
02025
02026
02027
02028
02029 DECLARE_EXPORT TimePeriod getUnavailable() const;
02030
02031
02032
02033
02034 bool getLocked() const {return flags & IS_LOCKED;}
02035
02036
02037
02038
02039 static DECLARE_EXPORT void deleteOperationPlans(Operation* o, bool deleteLocked=false);
02040
02041
02042
02043
02044 virtual DECLARE_EXPORT void setLocked(bool b = true);
02045
02046
02047 Operation* getOperation() const {return oper;}
02048
02049
02050
02051
02052
02053
02054
02055
02056 void setStartAndEnd(Date st, Date nd)
02057 {
02058 dates.setStartAndEnd(st,nd);
02059 update();
02060 }
02061
02062
02063
02064
02065 void restore(const OperationPlanState& x);
02066
02067
02068
02069
02070 void DECLARE_EXPORT setOwner(OperationPlan* o);
02071
02072
02073
02074
02075
02076
02077
02078
02079
02080 OperationPlan* getOwner() const {return owner;}
02081
02082
02083
02084
02085
02086
02087 const OperationPlan* getTopOwner() const
02088 {
02089 if (owner)
02090 {
02091
02092 OperationPlan* o(owner);
02093 while (o->owner) o = o->owner;
02094 return o;
02095 }
02096 else
02097
02098 return this;
02099 }
02100
02101
02102 const DateRange & getDates() const {return dates;}
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112 unsigned long getIdentifier() const {return id;}
02113
02114
02115
02116
02117
02118
02119
02120
02121 virtual DECLARE_EXPORT void setEnd(Date);
02122
02123
02124
02125
02126
02127
02128
02129
02130 virtual DECLARE_EXPORT void setStart(Date);
02131
02132 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02133 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
02134 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02135 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02136 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02137 static int initialize();
02138
02139 PyObject* str() const
02140 {
02141 ostringstream ch;
02142 ch << id;
02143 return PythonObject(ch.str());
02144 }
02145
02146 static PyObject* create(PyTypeObject*, PyObject*, PyObject*);
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164
02165
02166 virtual DECLARE_EXPORT bool instantiate();
02167
02168
02169
02170
02171
02172
02173
02174
02175
02176 DECLARE_EXPORT void insertInOperationplanList();
02177
02178
02179 virtual DECLARE_EXPORT void addSubOperationPlan(OperationPlan*);
02180
02181
02182 virtual DECLARE_EXPORT void eraseSubOperationPlan(OperationPlan*);
02183
02184
02185
02186 DECLARE_EXPORT void createFlowLoads();
02187
02188 bool getHidden() const {return getOperation()->getHidden();}
02189
02190
02191
02192
02193
02194
02195
02196
02197 static DECLARE_EXPORT OperationPlan* findId(unsigned long l);
02198
02199
02200
02201
02202 virtual void updateProblems();
02203
02204
02205 Plannable* getEntity() const {return oper;}
02206
02207
02208
02209
02210 const MetaClass& getType() const {return *metadata;}
02211
02212 static DECLARE_EXPORT const MetaClass* metadata;
02213
02214 static DECLARE_EXPORT const MetaCategory* metacategory;
02215
02216 virtual size_t getSize() const
02217 {return sizeof(OperationPlan);}
02218
02219
02220 static DECLARE_EXPORT void writer(const MetaCategory*, XMLOutput*);
02221
02222
02223
02224
02225
02226
02227
02228
02229
02230 DECLARE_EXPORT bool operator < (const OperationPlan& a) const;
02231
02232 private:
02233
02234
02235
02236
02237
02238 virtual DECLARE_EXPORT void update();
02239
02240
02241
02242
02243
02244
02245 DECLARE_EXPORT void resizeFlowLoadPlans();
02246
02247
02248 OperationPlan *owner;
02249
02250
02251 double quantity;
02252
02253
02254
02255
02256
02257
02258
02259
02260
02261 OperationPlan() : owner(NULL), quantity(0.0), flags(0), dmd(NULL),
02262 id(0), oper(NULL), firstflowplan(NULL), firstloadplan(NULL),
02263 prev(NULL), next(NULL), firstsubopplan(NULL), lastsubopplan(NULL),
02264 nextsubopplan(NULL), prevsubopplan(NULL)
02265 {initType(metadata);}
02266
02267 private:
02268 static const short IS_LOCKED = 1;
02269 static const short IS_SETUP = 2;
02270 static const short HAS_SETUP = 4;
02271
02272
02273
02274 short flags;
02275
02276
02277
02278
02279
02280
02281
02282 static DECLARE_EXPORT unsigned long counter;
02283
02284
02285
02286
02287
02288 Demand *dmd;
02289
02290
02291
02292
02293 unsigned long id;
02294
02295
02296 DateRange dates;
02297
02298
02299 Operation *oper;
02300
02301
02302 FlowPlan* firstflowplan;
02303
02304
02305 LoadPlan* firstloadplan;
02306
02307
02308
02309
02310
02311 OperationPlan* prev;
02312
02313
02314
02315
02316
02317 OperationPlan* next;
02318
02319
02320 OperationPlan* firstsubopplan;
02321
02322
02323 OperationPlan* lastsubopplan;
02324
02325
02326 OperationPlan* nextsubopplan;
02327
02328
02329 OperationPlan* prevsubopplan;
02330 };
02331
02332
02333
02334
02335 class OperationPlanState
02336 {
02337 public:
02338 Date start;
02339 Date end;
02340 double quantity;
02341
02342
02343 OperationPlanState() : quantity(0.0) {}
02344
02345
02346 OperationPlanState(const OperationPlan* x)
02347 {
02348 if (!x)
02349 {
02350 quantity = 0.0;
02351 return;
02352 }
02353 else
02354 {
02355 start = x->getDates().getStart();
02356 end = x->getDates().getEnd();
02357 quantity = x->getQuantity();
02358 }
02359 }
02360
02361
02362 OperationPlanState(const Date x, const Date y, double q)
02363 : start(x), end(y), quantity(q) {}
02364
02365
02366 OperationPlanState(const DateRange& x, double q)
02367 : start(x.getStart()), end(x.getEnd()), quantity(q) {}
02368 };
02369
02370
02371
02372
02373 class OperationFixedTime : public Operation
02374 {
02375 public:
02376
02377 explicit OperationFixedTime(const string& s) : Operation(s) {initType(metadata);}
02378
02379
02380 const TimePeriod getDuration() const {return duration;}
02381
02382
02383
02384 void setDuration(TimePeriod t)
02385 {
02386 if (t<0L)
02387 throw DataException("FixedTime operation can't have a negative duration");
02388 duration = t;
02389 }
02390
02391 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02392 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02393 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02394 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02395 static int initialize();
02396
02397 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02398
02399 virtual const MetaClass& getType() const {return *metadata;}
02400 static DECLARE_EXPORT const MetaClass* metadata;
02401 virtual size_t getSize() const
02402 {return sizeof(OperationFixedTime) + Operation::extrasize();}
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417 DECLARE_EXPORT OperationPlanState setOperationPlanParameters
02418 (OperationPlan*, double, Date, Date, bool=true, bool=true) const;
02419
02420 protected:
02421 DECLARE_EXPORT virtual bool extraInstantiate(OperationPlan* o);
02422
02423 private:
02424
02425 TimePeriod duration;
02426 };
02427
02428
02429
02430 class OperationSetup : public Operation
02431 {
02432 friend class CommandErase;
02433 public:
02434
02435 explicit OperationSetup(const string& s) : Operation(s) {initType(metadata);}
02436
02437
02438 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const {}
02439 static int initialize();
02440
02441 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02442
02443 virtual const MetaClass& getType() const {return *metadata;}
02444 static DECLARE_EXPORT const MetaClass* metadata;
02445 virtual size_t getSize() const
02446 {return sizeof(OperationSetup) + Operation::extrasize();}
02447
02448
02449
02450
02451
02452 DECLARE_EXPORT OperationPlanState setOperationPlanParameters
02453 (OperationPlan*, double, Date, Date, bool=true, bool=true) const;
02454
02455
02456 static DECLARE_EXPORT const Operation* setupoperation;
02457 };
02458
02459
02460
02461
02462
02463 class OperationTimePer : public Operation
02464 {
02465 public:
02466
02467 explicit OperationTimePer(const string& s) : Operation(s) {initType(metadata);}
02468
02469
02470 TimePeriod getDuration() const {return duration;}
02471
02472
02473 void setDuration(TimePeriod t)
02474 {
02475 if(t<0L)
02476 throw DataException("TimePer operation can't have a negative duration");
02477 duration = t;
02478 }
02479
02480
02481 TimePeriod getDurationPer() const {return duration_per;}
02482
02483
02484 void setDurationPer(TimePeriod t)
02485 {
02486 if(t<0L)
02487 throw DataException("TimePer operation can't have a negative duration-per");
02488 duration_per = t;
02489 }
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505 DECLARE_EXPORT OperationPlanState setOperationPlanParameters
02506 (OperationPlan*, double, Date, Date, bool=true, bool=true) const;
02507
02508 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02509 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02510 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02511 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02512 static int initialize();
02513
02514 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02515
02516 virtual const MetaClass& getType() const {return *metadata;}
02517 static DECLARE_EXPORT const MetaClass* metadata;
02518 virtual size_t getSize() const
02519 {return sizeof(OperationTimePer) + Operation::extrasize();}
02520
02521 private:
02522
02523 TimePeriod duration;
02524
02525
02526 TimePeriod duration_per;
02527 };
02528
02529
02530
02531
02532
02533 class OperationRouting : public Operation
02534 {
02535 public:
02536
02537 explicit OperationRouting(const string& c) : Operation(c) {initType(metadata);}
02538
02539
02540 DECLARE_EXPORT ~OperationRouting();
02541
02542
02543 void addStepFront(Operation *o)
02544 {
02545 if (!o) throw DataException("Adding NULL operation to routing");
02546 steps.push_front(o);
02547 o->addSuperOperation(this);
02548 }
02549
02550
02551 void addStepBack(Operation *o)
02552 {
02553 if (!o) throw DataException("Adding NULL operation to routing");
02554 steps.push_back(o);
02555 o->addSuperOperation(this);
02556 }
02557
02558
02559 static DECLARE_EXPORT PyObject* addStep(PyObject*, PyObject*);
02560
02561
02562 void removeSubOperation(Operation *o)
02563 {steps.remove(o); o->superoplist.remove(this);}
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580 DECLARE_EXPORT OperationPlanState setOperationPlanParameters
02581 (OperationPlan*, double, Date, Date, bool=true, bool=true) const;
02582
02583 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
02584 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02585 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02586 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02587 static int initialize();
02588
02589 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02590
02591
02592 virtual const Operationlist& getSubOperations() const {return steps;}
02593
02594 virtual const MetaClass& getType() const {return *metadata;}
02595 static DECLARE_EXPORT const MetaClass* metadata;
02596 virtual size_t getSize() const
02597 {
02598 return sizeof(OperationRouting) + Operation::extrasize()
02599 + steps.size() * 2 * sizeof(Operation*);
02600 }
02601
02602 protected:
02603
02604 virtual DECLARE_EXPORT bool extraInstantiate(OperationPlan* o);
02605
02606 private:
02607
02608 Operationlist steps;
02609 };
02610
02611
02612 inline void OperationPlan::restore(const OperationPlanState& x)
02613 {
02614 getOperation()->setOperationPlanParameters(this, x.quantity, x.start, x.end, true);
02615 assert(quantity == x.quantity);
02616 assert(dates.getStart() == x.start || x.start!=x.end);
02617 assert(dates.getEnd() == x.end || x.start!=x.end);
02618 }
02619
02620
02621
02622 enum SearchMode
02623 {
02624
02625
02626
02627 PRIORITY = 0,
02628
02629 MINCOST = 1,
02630
02631 MINPENALTY = 2,
02632
02633
02634 MINCOSTPENALTY = 3
02635 };
02636
02637
02638
02639 inline ostream & operator << (ostream & os, const SearchMode & d)
02640 {
02641 switch (d)
02642 {
02643 case PRIORITY: os << "PRIORITY"; return os;
02644 case MINCOST: os << "MINCOST"; return os;
02645 case MINPENALTY: os << "MINPENALTY"; return os;
02646 case MINCOSTPENALTY: os << "MINCOSTPENALTY"; return os;
02647 default: assert(false); return os;
02648 }
02649 }
02650
02651
02652
02653 DECLARE_EXPORT SearchMode decodeSearchMode(const string& c);
02654
02655
02656
02657
02658
02659 class OperationAlternate : public Operation
02660 {
02661 public:
02662 typedef pair<int,DateRange> alternateProperty;
02663
02664
02665 explicit OperationAlternate(const string& c)
02666 : Operation(c), search(PRIORITY) {initType(metadata);}
02667
02668
02669 DECLARE_EXPORT ~OperationAlternate();
02670
02671
02672
02673
02674 DECLARE_EXPORT void addAlternate
02675 (Operation*, int = 1, DateRange = DateRange());
02676
02677
02678 DECLARE_EXPORT void removeSubOperation(Operation *);
02679
02680
02681
02682
02683
02684 DECLARE_EXPORT const alternateProperty& getProperties(Operation* o) const;
02685
02686
02687
02688
02689
02690 DECLARE_EXPORT void setPriority(Operation*, int);
02691
02692
02693
02694
02695
02696 DECLARE_EXPORT void setEffective(Operation*, DateRange);
02697
02698
02699 SearchMode getSearch() const {return search;}
02700
02701
02702 void setSearch(const string a) {search = decodeSearchMode(a);}
02703
02704
02705
02706
02707
02708
02709
02710 DECLARE_EXPORT OperationPlanState setOperationPlanParameters
02711 (OperationPlan*, double, Date, Date, bool=true, bool=true) const;
02712
02713 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
02714 DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02715 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02716 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02717 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02718 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02719 virtual const Operationlist& getSubOperations() const {return alternates;}
02720 static int initialize();
02721
02722
02723
02724
02725
02726 static DECLARE_EXPORT PyObject* addAlternate(PyObject*, PyObject*, PyObject*);
02727
02728 virtual const MetaClass& getType() const {return *metadata;}
02729 static DECLARE_EXPORT const MetaClass* metadata;
02730 virtual size_t getSize() const
02731 {
02732 return sizeof(OperationAlternate) + Operation::extrasize()
02733 + alternates.size() * (5*sizeof(Operation*)+sizeof(alternateProperty));
02734 }
02735
02736 protected:
02737
02738 virtual DECLARE_EXPORT bool extraInstantiate(OperationPlan* o);
02739
02740 private:
02741 typedef list<alternateProperty> alternatePropertyList;
02742
02743
02744
02745 alternatePropertyList alternateProperties;
02746
02747
02748
02749
02750
02751
02752
02753 Operationlist alternates;
02754
02755
02756 SearchMode search;
02757 };
02758
02759
02760
02761
02762
02763
02764
02765 class Item : public HasHierarchy<Item>, public HasDescription
02766 {
02767 public:
02768
02769 explicit Item(const string& str) : HasHierarchy<Item>(str),
02770 deliveryOperation(NULL), price(0.0) {}
02771
02772
02773
02774
02775
02776 Operation* getOperation() const
02777 {
02778
02779 if (deliveryOperation) return deliveryOperation;
02780
02781
02782 for (Item* i = getOwner(); i; i=i->getOwner())
02783 if (i->deliveryOperation) return i->deliveryOperation;
02784
02785
02786 return NULL;
02787 }
02788
02789
02790
02791
02792
02793 void setOperation(Operation* o) {deliveryOperation = o;}
02794
02795
02796
02797
02798 double getPrice() const {return price;}
02799
02800
02801 void setPrice(const double c)
02802 {
02803 if (c >= 0) price = c;
02804 else throw DataException("Item price must be positive");
02805 }
02806
02807 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02808 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
02809 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
02810 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02811 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02812 static int initialize();
02813
02814
02815 virtual DECLARE_EXPORT ~Item();
02816
02817 virtual const MetaClass& getType() const {return *metadata;}
02818 static DECLARE_EXPORT const MetaCategory* metadata;
02819
02820 private:
02821
02822
02823
02824 Operation* deliveryOperation;
02825
02826
02827 double price;
02828 };
02829
02830
02831
02832
02833 class ItemDefault : public Item
02834 {
02835 public:
02836 explicit ItemDefault(const string& str) : Item(str) {initType(metadata);}
02837 virtual const MetaClass& getType() const {return *metadata;}
02838 static DECLARE_EXPORT const MetaClass* metadata;
02839 virtual size_t getSize() const
02840 {
02841 return sizeof(ItemDefault) + getName().size()
02842 + HasDescription::extrasize();
02843 }
02844 static int initialize();
02845 };
02846
02847
02848
02849
02850
02851 class Buffer : public HasHierarchy<Buffer>, public HasLevel,
02852 public Plannable, public HasDescription
02853 {
02854 friend class Flow;
02855 friend class FlowPlan;
02856
02857 public:
02858 typedef TimeLine<FlowPlan> flowplanlist;
02859 typedef Association<Operation,Buffer,Flow>::ListB flowlist;
02860
02861
02862 explicit Buffer(const string& str) : HasHierarchy<Buffer>(str),
02863 hidden(false), producing_operation(NULL), loc(NULL), it(NULL),
02864 min_cal(NULL), max_cal(NULL), carrying_cost(0.0) {}
02865
02866
02867
02868 Operation* getProducingOperation() const {return producing_operation;}
02869
02870
02871
02872 void setProducingOperation(Operation* o)
02873 {producing_operation = o; setChanged();}
02874
02875
02876 Item* getItem() const {return it;}
02877
02878
02879 void setItem(Item* i) {it = i; setChanged();}
02880
02881
02882 Location* getLocation() const {return loc;}
02883
02884
02885 void setLocation(Location* i) {loc = i;}
02886
02887
02888
02889 CalendarDouble* getMinimum() const {return min_cal;}
02890
02891
02892
02893 CalendarDouble* getMaximum() const {return max_cal;}
02894
02895
02896 DECLARE_EXPORT void setMinimum(CalendarDouble *);
02897
02898
02899 DECLARE_EXPORT void setMaximum(CalendarDouble *);
02900
02901
02902
02903
02904
02905 double getCarryingCost() const {return carrying_cost;}
02906
02907
02908
02909
02910
02911
02912 void setCarryingCost(const double c)
02913 {
02914 if (c >= 0) carrying_cost = c;
02915 else throw DataException("Buffer carrying_cost must be positive");
02916 }
02917
02918 DECLARE_EXPORT virtual void beginElement(XMLInput&, const Attribute&);
02919 DECLARE_EXPORT virtual void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
02920 DECLARE_EXPORT virtual void endElement(XMLInput&, const Attribute&, const DataElement&);
02921 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
02922 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
02923
02924 size_t extrasize() const
02925 {return getName().size() + HasDescription::extrasize();}
02926
02927
02928 static int initialize();
02929
02930
02931 virtual DECLARE_EXPORT ~Buffer();
02932
02933
02934
02935
02936 DECLARE_EXPORT double getOnHand(Date d = Date::infinitePast) const;
02937
02938
02939 DECLARE_EXPORT void setOnHand(double f);
02940
02941
02942
02943
02944
02945
02946 DECLARE_EXPORT double getOnHand(Date, Date, bool min = true) const;
02947
02948
02949 const flowlist& getFlows() const {return flows;}
02950
02951 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
02952
02953
02954 const flowplanlist& getFlowPlans() const {return flowplans;}
02955
02956
02957 flowplanlist& getFlowPlans() {return flowplans;}
02958
02959
02960
02961 Flow* findFlow(const Operation* o, Date d) const
02962 {return flows.find(o,d);}
02963
02964
02965
02966
02967
02968 DECLARE_EXPORT void deleteOperationPlans(bool deleteLockedOpplans = false);
02969
02970 virtual DECLARE_EXPORT void updateProblems();
02971
02972 void setHidden(bool b) {if (hidden!=b) setChanged(); hidden = b;}
02973 bool getHidden() const {return hidden;}
02974
02975 virtual const MetaClass& getType() const {return *metadata;}
02976 static DECLARE_EXPORT const MetaCategory* metadata;
02977
02978
02979
02980
02981 virtual DECLARE_EXPORT void followPegging
02982 (PeggingIterator&, FlowPlan*, short, double, double);
02983
02984 private:
02985
02986
02987 flowplanlist flowplans;
02988
02989
02990 flowlist flows;
02991
02992
02993 bool hidden;
02994
02995
02996 Operation *producing_operation;
02997
02998
02999
03000
03001
03002 Location* loc;
03003
03004
03005
03006
03007 Item* it;
03008
03009
03010
03011
03012
03013 CalendarDouble *min_cal;
03014
03015
03016
03017
03018
03019 CalendarDouble *max_cal;
03020
03021
03022
03023
03024
03025 double carrying_cost;
03026 };
03027
03028
03029
03030
03031 class BufferDefault : public Buffer
03032 {
03033 public:
03034 explicit BufferDefault(const string& str) : Buffer(str) {initType(metadata);}
03035 virtual const MetaClass& getType() const {return *metadata;}
03036 virtual size_t getSize() const
03037 {return sizeof(BufferDefault) + Buffer::extrasize();}
03038 static DECLARE_EXPORT const MetaClass* metadata;
03039 static int initialize();
03040 };
03041
03042
03043
03044
03045
03046
03047
03048
03049 class BufferInfinite : public Buffer
03050 {
03051 public:
03052 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03053 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03054 virtual const MetaClass& getType() const {return *metadata;}
03055 virtual size_t getSize() const
03056 {return sizeof(BufferInfinite) + Buffer::extrasize();}
03057 explicit BufferInfinite(const string& c) : Buffer(c)
03058 {setDetectProblems(false); initType(metadata);}
03059 static DECLARE_EXPORT const MetaClass* metadata;
03060 static int initialize();
03061 };
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076
03077
03078
03079
03080
03081
03082
03083
03084
03085
03086
03087
03088
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101
03102
03103
03104
03105
03106
03107
03108
03109
03110
03111
03112
03113
03114
03115 class BufferProcure : public Buffer
03116 {
03117 public:
03118 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03119 virtual DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
03120 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03121 virtual const MetaClass& getType() const {return *metadata;}
03122 virtual size_t getSize() const
03123 {return sizeof(BufferProcure) + Buffer::extrasize();}
03124 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
03125 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
03126 static int initialize();
03127
03128
03129 explicit BufferProcure(const string& c) : Buffer(c), min_inventory(0),
03130 max_inventory(0), size_minimum(0), size_maximum(DBL_MAX), size_multiple(0),
03131 oper(NULL) {initType(metadata);}
03132 static DECLARE_EXPORT const MetaClass* metadata;
03133
03134
03135 TimePeriod getLeadtime() const {return leadtime;}
03136
03137
03138 void setLeadtime(TimePeriod p)
03139 {
03140 if (p<0L)
03141 throw DataException("Procurement buffer can't have a negative lead time");
03142 leadtime = p;
03143 }
03144
03145
03146 TimePeriod getFence() const {return fence;}
03147
03148
03149 void setFence(TimePeriod p) {fence = p;}
03150
03151
03152
03153
03154 double getMinimumInventory() const {return min_inventory;}
03155
03156
03157 void setMinimumInventory(double f)
03158 {
03159 if (f<0)
03160 throw DataException("Procurement buffer can't have a negative minimum inventory");
03161 min_inventory = f;
03162
03163 if (max_inventory < min_inventory) max_inventory = min_inventory;
03164 }
03165
03166
03167 double getMaximumInventory() const {return max_inventory;}
03168
03169
03170 void setMaximumInventory(double f)
03171 {
03172 if (f<0)
03173 throw DataException("Procurement buffer can't have a negative maximum inventory");
03174 max_inventory = f;
03175
03176 if (max_inventory < min_inventory) min_inventory = max_inventory;
03177 }
03178
03179
03180
03181
03182
03183 TimePeriod getMinimumInterval() const {return min_interval;}
03184
03185
03186 void setMinimumInterval(TimePeriod p)
03187 {
03188 if (p<0L)
03189 throw DataException("Procurement buffer can't have a negative minimum interval");
03190 min_interval = p;
03191
03192 if (max_interval < min_interval) max_interval = min_interval;
03193 }
03194
03195
03196
03197
03198 TimePeriod getMaximumInterval() const {return max_interval;}
03199
03200
03201 void setMaximumInterval(TimePeriod p)
03202 {
03203 if (p<0L)
03204 throw DataException("Procurement buffer can't have a negative maximum interval");
03205 max_interval = p;
03206
03207 if (max_interval < min_interval) min_interval = max_interval;
03208 }
03209
03210
03211 double getSizeMinimum() const {return size_minimum;}
03212
03213
03214 void setSizeMinimum(double f)
03215 {
03216 if (f<0)
03217 throw DataException("Procurement buffer can't have a negative minimum size");
03218 size_minimum = f;
03219
03220 if (size_maximum < size_minimum) size_maximum = size_minimum;
03221 }
03222
03223
03224 double getSizeMaximum() const {return size_maximum;}
03225
03226
03227 void setSizeMaximum(double f)
03228 {
03229 if (f<0)
03230 throw DataException("Procurement buffer can't have a negative maximum size");
03231 size_maximum = f;
03232
03233 if (size_maximum < size_minimum) size_minimum = size_maximum;
03234 }
03235
03236
03237 double getSizeMultiple() const {return size_multiple;}
03238
03239
03240 void setSizeMultiple(double f)
03241 {
03242 if (f<0)
03243 throw DataException("Procurement buffer can't have a negative multiple size");
03244 size_multiple = f;
03245 }
03246
03247
03248
03249
03250 DECLARE_EXPORT Operation* getOperation() const;
03251
03252 private:
03253
03254
03255
03256 TimePeriod leadtime;
03257
03258
03259
03260
03261 TimePeriod fence;
03262
03263
03264
03265
03266
03267
03268 double min_inventory;
03269
03270
03271
03272
03273
03274 double max_inventory;
03275
03276
03277 TimePeriod min_interval;
03278
03279
03280 TimePeriod max_interval;
03281
03282
03283
03284
03285 double size_minimum;
03286
03287
03288
03289
03290 double size_maximum;
03291
03292
03293
03294
03295 double size_multiple;
03296
03297
03298 Operation* oper;
03299 };
03300
03301
03302
03303
03304
03305
03306 class Flow : public Object, public Association<Operation,Buffer,Flow>::Node,
03307 public Solvable
03308 {
03309 public:
03310
03311 virtual DECLARE_EXPORT ~Flow();
03312
03313
03314 explicit Flow(Operation* o, Buffer* b, double q)
03315 : quantity(q), priority(1), hasAlts(false), altFlow(NULL), search(PRIORITY)
03316 {
03317 setOperation(o);
03318 setBuffer(b);
03319 validate(ADD);
03320 initType(metadata);
03321 }
03322
03323
03324 Operation* getOperation() const {return getPtrA();}
03325
03326
03327
03328
03329
03330 void setOperation(Operation* o) {if (o) setPtrA(o,o->getFlows());}
03331
03332
03333 bool isConsumer() const {return quantity < 0;}
03334
03335
03336 bool isProducer() const {return quantity >= 0;}
03337
03338
03339 double getQuantity() const {return quantity;}
03340
03341
03342
03343
03344
03345
03346 void setQuantity(double f) {quantity = f;}
03347
03348
03349 Buffer* getBuffer() const {return getPtrB();}
03350
03351
03352
03353
03354
03355 void setBuffer(Buffer* b) {if (b) setPtrB(b,b->getFlows());}
03356
03357
03358 void setPriority(int i) {priority = i;}
03359
03360
03361 int getPriority() const {return priority;}
03362
03363
03364 bool hasAlternates() const {return hasAlts;}
03365
03366
03367
03368
03369 Flow* getAlternate() const {return altFlow;}
03370
03371
03372 DECLARE_EXPORT void setAlternate(Flow *);
03373
03374
03375 DECLARE_EXPORT void setAlternate(const string& n);
03376
03377
03378 SearchMode getSearch() const {return search;}
03379
03380
03381 void setSearch(const string a) {search = decodeSearchMode(a);}
03382
03383
03384
03385 virtual bool getHidden() const
03386 {
03387 return (getBuffer() && getBuffer()->getHidden())
03388 || (getOperation() && getOperation()->getHidden());
03389 }
03390
03391
03392 virtual Date getFlowplanDate(const FlowPlan*) const;
03393
03394
03395 virtual double getFlowplanQuantity(const FlowPlan*) const;
03396
03397 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03398 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
03399 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
03400 static int initialize();
03401 static void writer(const MetaCategory*, XMLOutput*);
03402
03403 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03404
03405 virtual const MetaClass& getType() const {return *metadata;}
03406 static DECLARE_EXPORT const MetaCategory* metadata;
03407 virtual size_t getSize() const {return sizeof(Flow) + getName().size();}
03408
03409 protected:
03410
03411 explicit Flow() : quantity(0.0), priority(1), hasAlts(false),
03412 altFlow(NULL), search(PRIORITY) {initType(metadata);}
03413
03414 private:
03415
03416 DECLARE_EXPORT void validate(Action action);
03417
03418
03419 double quantity;
03420
03421
03422 int priority;
03423
03424
03425 bool hasAlts;
03426
03427
03428 Flow* altFlow;
03429
03430
03431 SearchMode search;
03432
03433 static PyObject* create(PyTypeObject* pytype, PyObject* args, PyObject* kwds);
03434 DECLARE_EXPORT PyObject* getattro(const Attribute&);
03435 DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
03436 };
03437
03438
03439
03440
03441
03442
03443 class FlowStart : public Flow
03444 {
03445 public:
03446
03447 explicit FlowStart(Operation* o, Buffer* b, double q) : Flow(o,b,q) {}
03448
03449
03450 explicit FlowStart() {}
03451
03452 virtual const MetaClass& getType() const {return *metadata;}
03453 static DECLARE_EXPORT const MetaClass* metadata;
03454 virtual size_t getSize() const {return sizeof(FlowStart);}
03455 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03456 };
03457
03458
03459
03460
03461
03462
03463 class FlowEnd : public Flow
03464 {
03465 public:
03466
03467 explicit FlowEnd(Operation* o, Buffer* b, double q) : Flow(o,b,q) {}
03468
03469
03470 explicit FlowEnd() {}
03471
03472
03473 virtual Date getFlowplanDate(const FlowPlan* fl) const;
03474
03475 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03476
03477 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03478
03479 virtual const MetaClass& getType() const {return *metadata;}
03480 static DECLARE_EXPORT const MetaClass* metadata;
03481 virtual size_t getSize() const {return sizeof(FlowEnd);}
03482 };
03483
03484
03485
03486
03487
03488
03489
03490 class FlowPlan : public TimeLine<FlowPlan>::EventChangeOnhand, public PythonExtensionBase
03491 {
03492 friend class OperationPlan::FlowPlanIterator;
03493 private:
03494
03495 const Flow *fl;
03496
03497
03498 PyObject* getattro(const Attribute&);
03499
03500
03501 OperationPlan *oper;
03502
03503
03504 FlowPlan *nextFlowPlan;
03505
03506 public:
03507
03508 static DECLARE_EXPORT const MetaCategory* metadata;
03509 static int initialize();
03510
03511
03512 explicit DECLARE_EXPORT FlowPlan(OperationPlan*, const Flow*);
03513
03514
03515 const Flow* getFlow() const {return fl;}
03516
03517
03518 const Buffer* getBuffer() const {return fl->getBuffer();}
03519
03520
03521
03522
03523 DECLARE_EXPORT void setFlow(const Flow*);
03524
03525
03526 OperationPlan* getOperationPlan() const {return oper;}
03527
03528
03529 virtual ~FlowPlan()
03530 {
03531 Buffer* b = getFlow()->getBuffer();
03532 b->setChanged();
03533 b->flowplans.erase(this);
03534 }
03535
03536
03537
03538
03539
03540
03541 void DECLARE_EXPORT writeElement
03542 (XMLOutput*, const Keyword&, mode=DEFAULT) const;
03543
03544
03545
03546
03547
03548
03549 void setQuantity(double qty, bool b=false, bool u = true)
03550 {
03551 if (getFlow()->getEffective().within(getDate()))
03552 oper->setQuantity(qty / getFlow()->getQuantity(), b, u);
03553 }
03554
03555
03556
03557
03558 DECLARE_EXPORT void update();
03559
03560
03561 TimeLine<FlowPlan>* getTimeLine() const
03562 {return &(getFlow()->getBuffer()->flowplans);}
03563
03564
03565
03566
03567 bool getHidden() const {return fl->getHidden();}
03568 };
03569
03570
03571 inline double Flow::getFlowplanQuantity(const FlowPlan* fl) const
03572 {
03573 return getEffective().within(fl->getDate()) ?
03574 fl->getOperationPlan()->getQuantity() * getQuantity() :
03575 0.0;
03576 }
03577
03578
03579 inline Date Flow::getFlowplanDate(const FlowPlan* fl) const
03580 {
03581 return fl->getOperationPlan()->getDates().getStart();
03582 }
03583
03584
03585 inline Date FlowEnd::getFlowplanDate(const FlowPlan* fl) const
03586 {
03587 return fl->getOperationPlan()->getDates().getEnd();
03588 }
03589
03590
03591
03592
03593
03594 class SetupMatrix : public HasName<SetupMatrix>
03595 {
03596 public:
03597 class RuleIterator;
03598
03599 class Rule : public Object
03600 {
03601 friend class RuleIterator;
03602 friend class SetupMatrix;
03603 public:
03604
03605 DECLARE_EXPORT Rule(SetupMatrix *s, int p = 0);
03606
03607
03608 DECLARE_EXPORT ~Rule();
03609
03610 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03611 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
03612 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
03613 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
03614 static int initialize();
03615
03616 virtual const MetaClass& getType() const {return *metadata;}
03617 static DECLARE_EXPORT const MetaCategory* metadata;
03618
03619 size_t getSize() const
03620 {return sizeof(Rule) + from.size() + to.size();}
03621
03622
03623
03624
03625
03626 DECLARE_EXPORT void setPriority(const int);
03627
03628
03629 double getPriority() const {return priority;}
03630
03631
03632 void setFromSetup(const string f) {from = f;}
03633
03634
03635 const string& getFromSetup() const {return from;}
03636
03637
03638 void setToSetup(const string f) {to = f;}
03639
03640
03641 const string& getToSetup() const {return to;}
03642
03643
03644 void setDuration(const TimePeriod p) {duration = p;}
03645
03646
03647 TimePeriod getDuration() const {return duration;}
03648
03649
03650 void setCost(const double p) {cost = p;}
03651
03652
03653 double getCost() const {return cost;}
03654
03655 private:
03656
03657 string from;
03658
03659
03660 string to;
03661
03662
03663 TimePeriod duration;
03664
03665
03666 double cost;
03667
03668
03669
03670
03671
03672 int priority;
03673
03674
03675 SetupMatrix *matrix;
03676
03677
03678 Rule *nextRule;
03679
03680
03681 Rule *prevRule;
03682 };
03683
03684
03685 class RuleIterator
03686 {
03687 private:
03688 Rule* curRule;
03689 public:
03690
03691 RuleIterator(Rule* c = NULL) : curRule(c) {}
03692 bool operator != (const RuleIterator &b) const
03693 {return b.curRule != curRule;}
03694 bool operator == (const RuleIterator &b) const
03695 {return b.curRule == curRule;}
03696 RuleIterator& operator++()
03697 {if (curRule) curRule = curRule->nextRule; return *this;}
03698 RuleIterator operator++(int)
03699 {RuleIterator tmp = *this; ++*this; return tmp;}
03700 RuleIterator& operator--()
03701 {if(curRule) curRule = curRule->prevRule; return *this;}
03702 RuleIterator operator--(int)
03703 {RuleIterator tmp = *this; --*this; return tmp;}
03704 Rule* operator ->() const {return curRule;}
03705 Rule& operator *() const {return *curRule;}
03706 };
03707
03708 public:
03709
03710 SetupMatrix(const string& n) : HasName<SetupMatrix>(n), firstRule(NULL) {}
03711
03712
03713 DECLARE_EXPORT ~SetupMatrix();
03714
03715
03716
03717
03718
03719 DECLARE_EXPORT Rule* createRule(const AttributeList&);
03720
03721 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03722 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
03723 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
03724 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
03725 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
03726 static int initialize();
03727
03728 virtual const MetaClass& getType() const {return *metadata;}
03729 static DECLARE_EXPORT const MetaCategory* metadata;
03730
03731 virtual size_t getSize() const
03732 {
03733 size_t i = sizeof(SetupMatrix) + getName().size();
03734 for (RuleIterator j = beginRules(); j!= endRules(); ++j)
03735 i += j->getSize();
03736 return i;
03737 }
03738
03739 size_t extrasize() const {return getName().size();}
03740
03741
03742 RuleIterator beginRules() const {return RuleIterator(firstRule);}
03743
03744
03745 RuleIterator endRules() const {return RuleIterator(NULL);}
03746
03747
03748 static DECLARE_EXPORT PyObject* addPythonRule(PyObject*, PyObject*, PyObject*);
03749
03750
03751
03752
03753
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767 DECLARE_EXPORT Rule* calculateSetup(const string, const string) const;
03768
03769 private:
03770
03771 Rule *firstRule;
03772 };
03773
03774
03775
03776
03777
03778 class SetupMatrixDefault : public SetupMatrix
03779 {
03780 public:
03781 explicit SetupMatrixDefault(const string& str) : SetupMatrix(str) {initType(metadata);}
03782 virtual const MetaClass& getType() const {return *metadata;}
03783 static DECLARE_EXPORT const MetaClass* metadata;
03784 virtual size_t getSize() const
03785 {return sizeof(SetupMatrixDefault) + SetupMatrix::extrasize();}
03786 static int initialize();
03787 };
03788
03789
03790
03791
03792
03793 class Resource : public HasHierarchy<Resource>,
03794 public HasLevel, public Plannable, public HasDescription
03795 {
03796 friend class Load;
03797 friend class LoadPlan;
03798
03799 public:
03800
03801
03802 static const long defaultMaxEarly = 100*86400L;
03803
03804
03805 explicit Resource(const string& str) : HasHierarchy<Resource>(str),
03806 max_cal(NULL), loc(NULL), cost(0.0), hidden(false), maxearly(defaultMaxEarly),
03807 setupmatrix(NULL) {};
03808
03809
03810 virtual DECLARE_EXPORT ~Resource();
03811
03812
03813 DECLARE_EXPORT void setMaximum(CalendarDouble* c);
03814
03815
03816 CalendarDouble* getMaximum() const {return max_cal;}
03817
03818
03819
03820
03821 double getCost() const {return cost;}
03822
03823
03824 void setCost(const double c)
03825 {
03826 if (c >= 0) cost = c;
03827 else throw DataException("Resource cost must be positive");
03828 }
03829
03830 typedef Association<Operation,Resource,Load>::ListB loadlist;
03831 typedef TimeLine<LoadPlan> loadplanlist;
03832
03833
03834 const loadplanlist& getLoadPlans() const {return loadplans;}
03835
03836
03837 loadplanlist& getLoadPlans() {return loadplans;}
03838
03839
03840
03841
03842 const loadlist& getLoads() const {return loads;}
03843
03844
03845
03846 Load* findLoad(const Operation* o, Date d) const
03847 {return loads.find(o,d);}
03848
03849 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03850 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
03851 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
03852 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
03853 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
03854
03855
03856 static int initialize();
03857
03858 size_t extrasize() const
03859 {return getName().size() + HasDescription::extrasize() + setup.size();}
03860
03861
03862 Location* getLocation() const {return loc;}
03863
03864
03865 void setLocation(Location* i) {loc = i;}
03866
03867 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03868
03869
03870
03871
03872 DECLARE_EXPORT void deleteOperationPlans(bool = false);
03873
03874
03875 virtual DECLARE_EXPORT void updateProblems();
03876
03877
03878 virtual DECLARE_EXPORT void updateSetups(const LoadPlan* = NULL);
03879
03880 void setHidden(bool b) {if (hidden!=b) setChanged(); hidden = b;}
03881 bool getHidden() const {return hidden;}
03882
03883 virtual const MetaClass& getType() const {return *metadata;}
03884 static DECLARE_EXPORT const MetaCategory* metadata;
03885
03886
03887
03888 TimePeriod getMaxEarly() const {return maxearly;}
03889
03890
03891
03892 void setMaxEarly(TimePeriod c)
03893 {
03894 if (c >= 0L) maxearly = c;
03895 else throw DataException("MaxEarly must be positive");
03896 }
03897
03898
03899 SetupMatrix* getSetupMatrix() const {return setupmatrix;}
03900
03901
03902 void setSetupMatrix(SetupMatrix *s) {setupmatrix = s;}
03903
03904
03905 const string& getSetup() const {return setup;}
03906
03907
03908 void setSetup(const string s) {setup = s;}
03909
03910 private:
03911
03912 CalendarDouble* max_cal;
03913
03914
03915 loadplanlist loadplans;
03916
03917
03918
03919 loadlist loads;
03920
03921
03922 Location* loc;
03923
03924
03925 double cost;
03926
03927
03928 bool hidden;
03929
03930
03931 TimePeriod maxearly;
03932
03933
03934 SetupMatrix *setupmatrix;
03935
03936
03937 string setup;
03938 };
03939
03940
03941
03942
03943
03944 class ResourceDefault : public Resource
03945 {
03946 public:
03947 explicit ResourceDefault(const string& str) : Resource(str) {initType(metadata);}
03948 virtual const MetaClass& getType() const {return *metadata;}
03949 static DECLARE_EXPORT const MetaClass* metadata;
03950 virtual size_t getSize() const
03951 {return sizeof(ResourceDefault) + Resource::extrasize();}
03952 static int initialize();
03953 };
03954
03955
03956
03957
03958 class ResourceInfinite : public Resource
03959 {
03960 public:
03961 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
03962 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
03963 virtual const MetaClass& getType() const {return *metadata;}
03964 explicit ResourceInfinite(const string& c) : Resource(c)
03965 {setDetectProblems(false); initType(metadata);}
03966 static DECLARE_EXPORT const MetaClass* metadata;
03967 virtual size_t getSize() const
03968 {return sizeof(ResourceInfinite) + Resource::extrasize();}
03969 static int initialize();
03970 };
03971
03972
03973
03974 class Load
03975 : public Object, public Association<Operation,Resource,Load>::Node,
03976 public Solvable
03977 {
03978 friend class Resource;
03979 friend class Operation;
03980
03981 public:
03982
03983 explicit Load(Operation* o, Resource* r, double u)
03984 : priority(1), hasAlts(false), altLoad(NULL), search(PRIORITY)
03985 {
03986 setOperation(o);
03987 setResource(r);
03988 setQuantity(u);
03989 validate(ADD);
03990 initType(metadata);
03991 }
03992
03993
03994 DECLARE_EXPORT ~Load();
03995
03996
03997 Operation* getOperation() const {return getPtrA();}
03998
03999
04000
04001 void setOperation(Operation* o) {if (o) setPtrA(o,o->getLoads());}
04002
04003
04004 Resource* getResource() const {return getPtrB();}
04005
04006
04007
04008 void setResource(Resource* r) {if (r) setPtrB(r,r->getLoads());}
04009
04010
04011
04012 double getQuantity() const {return qty;}
04013
04014
04015
04016
04017 void setQuantity(double f)
04018 {
04019 if (f < 0) throw DataException("Load quantity can't be negative");
04020 qty = f;
04021 }
04022
04023
04024 void setPriority(int i) {priority = i;}
04025
04026
04027 int getPriority() const {return priority;}
04028
04029
04030 bool hasAlternates() const {return hasAlts;}
04031
04032
04033
04034
04035 Load* getAlternate() const {return altLoad;}
04036
04037
04038 DECLARE_EXPORT void setAlternate(Load *);
04039
04040
04041 DECLARE_EXPORT void setAlternate(const string& n);
04042
04043
04044 DECLARE_EXPORT void setSetup(const string);
04045
04046
04047 const string& getSetup() const {return setup;}
04048
04049
04050 virtual Date getLoadplanDate(const LoadPlan*) const;
04051
04052
04053 virtual double getLoadplanQuantity(const LoadPlan*) const;
04054
04055 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
04056 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
04057 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
04058 DECLARE_EXPORT PyObject* getattro(const Attribute&);
04059 DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
04060 static int initialize();
04061 static void writer(const MetaCategory*, XMLOutput*);
04062
04063 bool getHidden() const
04064 {
04065 return (getResource() && getResource()->getHidden())
04066 || (getOperation() && getOperation()->getHidden());
04067 }
04068 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
04069
04070 virtual const MetaClass& getType() const {return *metadata;}
04071 static DECLARE_EXPORT const MetaCategory* metadata;
04072 virtual size_t getSize() const
04073 {return sizeof(Load) + getName().size() + getSetup().size();}
04074
04075
04076 Load() : qty(1.0), priority(1), hasAlts(false), altLoad(NULL), search(PRIORITY)
04077 {initType(metadata);}
04078
04079
04080 SearchMode getSearch() const {return search;}
04081
04082
04083 void setSearch(const string a) {search = decodeSearchMode(a);}
04084
04085 private:
04086
04087
04088
04089
04090 DECLARE_EXPORT void validate(Action action);
04091
04092
04093
04094 double qty;
04095
04096
04097 int priority;
04098
04099
04100 bool hasAlts;
04101
04102
04103 Load* altLoad;
04104
04105
04106 string setup;
04107
04108
04109 SearchMode search;
04110
04111
04112 static PyObject* create(PyTypeObject*, PyObject*, PyObject*);
04113 };
04114
04115
04116
04117
04118
04119
04120
04121
04122
04123
04124
04125
04126 class Plan : public Plannable, public Object
04127 {
04128 private:
04129
04130 Date cur_Date;
04131
04132
04133 string name;
04134
04135
04136 string descr;
04137
04138
04139 static DECLARE_EXPORT Plan* thePlan;
04140
04141
04142
04143
04144 Plan() : cur_Date(Date::now()) {initType(metadata);}
04145
04146 public:
04147
04148
04149
04150
04151 static Plan& instance() {return *thePlan;}
04152
04153
04154
04155
04156
04157
04158
04159 DECLARE_EXPORT ~Plan();
04160
04161
04162 const string& getName() const {return name;}
04163
04164
04165 void setName(const string& s) {name = s;}
04166
04167
04168 const Date & getCurrent() const {return cur_Date;}
04169
04170
04171
04172
04173
04174 DECLARE_EXPORT void setCurrent(Date);
04175
04176
04177 const string& getDescription() const {return descr;}
04178
04179
04180 void setDescription(const string& str) {descr = str;}
04181
04182
04183
04184
04185
04186
04187 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
04188 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
04189 DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
04190 DECLARE_EXPORT PyObject* getattro(const Attribute&);
04191 DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
04192
04193
04194 static int initialize();
04195
04196 virtual void updateProblems() {};
04197
04198
04199 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
04200
04201 const MetaClass& getType() const {return *metadata;}
04202 static DECLARE_EXPORT const MetaCategory* metadata;
04203 virtual size_t getSize() const
04204 {return sizeof(Plan) + name.size() + descr.size();}
04205 };
04206
04207
04208
04209
04210
04211
04212
04213
04214 class CommandReadXMLFile : public Command
04215 {
04216 public:
04217
04218
04219 CommandReadXMLFile(const char* s = NULL, bool v = true, bool o = false)
04220 : validate(v), validate_only(o) {if (s) filename = s;}
04221
04222
04223 CommandReadXMLFile(const string& s, bool v = true, bool o = false)
04224 : filename(s), validate(v), validate_only(o) {}
04225
04226
04227 void setFileName(const string& v) {filename = v;}
04228
04229
04230 string getFileName() {return filename;}
04231
04232
04233 void setValidate(bool b) {validate = b;}
04234
04235
04236 bool getValidate() {return validate;}
04237
04238
04239 void setValidateOnly(bool b) {validate_only = b;}
04240
04241
04242
04243 bool getValidateOnly() {return validate_only;}
04244
04245
04246
04247
04248 DECLARE_EXPORT void execute();
04249
04250
04251 static DECLARE_EXPORT PyObject* executePython(PyObject*, PyObject*);
04252
04253 private:
04254
04255
04256 string filename;
04257
04258
04259
04260
04261
04262
04263 bool validate;
04264
04265
04266
04267 bool validate_only;
04268 };
04269
04270
04271
04272
04273
04274
04275
04276 class CommandReadXMLString : public Command
04277 {
04278 public:
04279
04280 CommandReadXMLString(const string& s, const bool v=true, const bool o=false)
04281 : data(s), validate(v), validate_only(o) {};
04282
04283
04284 CommandReadXMLString(const bool v=true, const bool o=false)
04285 : validate(v), validate_only(o) {};
04286
04287
04288 void setData(const string& v) {data = v;}
04289
04290
04291 string getData() {return data;}
04292
04293
04294 void setValidate(bool b) {validate = b;}
04295
04296
04297 bool getValidate() {return validate;}
04298
04299
04300 void setValidateOnly(bool b) {validate_only = b;}
04301
04302
04303
04304 bool getValidateOnly() {return validate_only;}
04305
04306
04307 DECLARE_EXPORT void execute();
04308
04309
04310 static DECLARE_EXPORT PyObject* executePython(PyObject *, PyObject *);
04311
04312 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
04313
04314 private:
04315
04316
04317 string data;
04318
04319
04320
04321
04322
04323
04324 bool validate;
04325
04326
04327
04328 bool validate_only;
04329 };
04330
04331
04332
04333
04334
04335
04336
04337
04338
04339
04340
04341
04342 class CommandSave : public Command
04343 {
04344 public:
04345
04346 CommandSave(const string& v = "plan.out")
04347 : filename(v), content(XMLOutput::STANDARD) {};
04348
04349
04350 virtual ~CommandSave() {};
04351
04352
04353 string getFileName() const {return filename;}
04354
04355
04356 void setFileName(const string& v) {filename = v;}
04357
04358
04359 DECLARE_EXPORT void execute();
04360
04361
04362 static DECLARE_EXPORT PyObject* executePython(PyObject*, PyObject*);
04363
04364
04365 XMLOutput::content_type getContent() const {return content;}
04366
04367
04368
04369
04370 void setContent(XMLOutput::content_type t) {content = t;}
04371
04372
04373
04374
04375
04376
04377 void setHeaderStart(const string& s) {headerstart = s;}
04378
04379
04380
04381 string getHeaderStart() const {return headerstart;}
04382
04383
04384
04385
04386
04387 void setHeaderAtts(const string& s) {headeratts = s;}
04388
04389
04390
04391 string getHeaderAtts() const {return headeratts;}
04392
04393 private:
04394 string filename;
04395 string headerstart;
04396 string headeratts;
04397 XMLOutput::content_type content;
04398 };
04399
04400
04401
04402
04403
04404
04405
04406
04407
04408
04409
04410
04411
04412 class CommandSavePlan : public Command
04413 {
04414 public:
04415 CommandSavePlan(const string& v = "plan.out") : filename(v) {};
04416 string getFileName() const {return filename;}
04417 void setFileName(const string& v) {filename = v;}
04418 DECLARE_EXPORT void execute();
04419
04420
04421 static DECLARE_EXPORT PyObject* executePython(PyObject*, PyObject*);
04422
04423 DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
04424 private:
04425 string filename;
04426 };
04427
04428
04429
04430
04431
04432
04433
04434
04435
04436
04437 class CommandPlanSize : public Command
04438 {
04439 public:
04440 CommandPlanSize() {};
04441 DECLARE_EXPORT void execute();
04442 static PyObject* executePython(PyObject* self, PyObject* args)
04443 {CommandPlanSize x;x.execute(); return Py_BuildValue("");}
04444 void undo() {}
04445 bool undoable() const {return true;}
04446 };
04447
04448
04449
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459
04460
04461
04462
04463
04464 class CommandErase : public Command
04465 {
04466 public:
04467 CommandErase(bool staticAlso = false) : deleteStaticModel(staticAlso) {};
04468
04469 DECLARE_EXPORT void execute();
04470
04471
04472 static DECLARE_EXPORT PyObject* executePython(PyObject*, PyObject*);
04473
04474 bool getDeleteStaticModel() const {return deleteStaticModel;}
04475 void setDeleteStaticModel(bool b) {deleteStaticModel = b;}
04476 private:
04477
04478
04479 bool deleteStaticModel;
04480 };
04481
04482
04483
04484
04485
04486
04487
04488 class Demand
04489 : public HasHierarchy<Demand>, public Plannable, public HasDescription
04490 {
04491 public:
04492 typedef slist<OperationPlan*> OperationPlan_list;
04493
04494
04495 explicit Demand(const string& str) : HasHierarchy<Demand>(str),
04496 it(NULL), oper(NULL), cust(NULL), qty(0.0), prio(0),
04497 maxLateness(TimePeriod::MAX), minShipment(0), hidden(false) {}
04498
04499
04500
04501 virtual ~Demand() {deleteOperationPlans(true);}
04502
04503
04504 double getQuantity() const {return qty;}
04505
04506
04507
04508 virtual DECLARE_EXPORT void setQuantity(double);
04509
04510
04511
04512
04513 int getPriority() const {return prio;}
04514
04515
04516
04517
04518 virtual void setPriority(int i) {prio=i; setChanged();}
04519
04520
04521 Item* getItem() const {return it;}
04522
04523
04524 virtual void setItem(Item *i) {it=i; setChanged();}
04525
04526
04527
04528
04529
04530
04531 Operation* getOperation() const {return oper;}
04532
04533
04534
04535
04536
04537
04538
04539 DECLARE_EXPORT Operation* getDeliveryOperation() const;
04540
04541
04542 int getCluster() const
04543 {
04544 Operation* o = getDeliveryOperation();
04545 return o ? o->getCluster() : 0;
04546 }
04547
04548
04549 virtual void setOperation(Operation* o) {oper=o; setChanged();}
04550
04551
04552 DECLARE_EXPORT const OperationPlan_list& getDelivery() const;
04553
04554
04555 DECLARE_EXPORT OperationPlan* getLatestDelivery() const;
04556
04557
04558 DECLARE_EXPORT OperationPlan* getEarliestDelivery() const;
04559
04560
04561 DECLARE_EXPORT void addDelivery(OperationPlan *o);
04562
04563
04564 DECLARE_EXPORT void removeDelivery(OperationPlan *o);
04565
04566
04567
04568
04569
04570
04571
04572 DECLARE_EXPORT void deleteOperationPlans
04573 (bool deleteLockedOpplans = false, CommandList* = NULL);
04574
04575
04576 const Date& getDue() const {return dueDate;}
04577
04578
04579 virtual void setDue(Date d) {dueDate = d; setChanged();}
04580
04581
04582 Customer* getCustomer() const {return cust;}
04583
04584
04585 virtual void setCustomer(Customer* c) {cust = c; setChanged();}
04586
04587
04588 DECLARE_EXPORT double getPlannedQuantity() const;
04589
04590 virtual DECLARE_EXPORT void writeElement(XMLOutput*, const Keyword&, mode=DEFAULT) const;
04591 virtual DECLARE_EXPORT void endElement(XMLInput&, const Attribute&, const DataElement&);
04592 virtual DECLARE_EXPORT void beginElement(XMLInput&, const Attribute&);
04593 virtual DECLARE_EXPORT PyObject* getattro(const Attribute&);
04594 virtual DECLARE_EXPORT int setattro(const Attribute&, const PythonObject&);
04595 static int initialize();
04596
04597 size_t extrasize() const
04598 {
04599 return getName().size() + HasDescription::extrasize()
04600 + sizeof(void*) * 2 * deli.size();
04601 }
04602
04603 virtual void solve(Solver &s, void* v = NULL) const {s.solve(this,v);}
04604
04605
04606
04607
04608 TimePeriod getMaxLateness() const {return maxLateness;}
04609
04610
04611
04612
04613
04614 virtual void setMaxLateness(TimePeriod m)
04615 {
04616 if (m < 0L)
04617 throw DataException("The maximum demand lateness must be positive");
04618 maxLateness = m;
04619 }
04620
04621
04622
04623
04624
04625 double getMinShipment() const {return minShipment;}
04626
04627
04628
04629
04630
04631 virtual void setMinShipment(double m)
04632 {
04633 if (m < 0.0)
04634 throw DataException("The minumum demand shipment quantity must be positive");
04635 minShipment = m;
04636 }
04637
04638
04639 virtual DECLARE_EXPORT void updateProblems();
04640
04641
04642
04643 void setHidden(bool b) {hidden = b;}
04644
04645
04646 bool getHidden() const {return hidden;}
04647
04648 virtual const MetaClass& getType() const {return *metadata;}
04649 static DECLARE_EXPORT const MetaCategory* metadata;
04650
04651 private:
04652
04653 Item *it;
04654
04655
04656
04657 Operation *oper;
04658
04659
04660 Customer *cust;
04661
04662
04663 double qty;
04664
04665
04666 int prio;
04667
04668
04669 Date dueDate;
04670
04671
04672
04673
04674 TimePeriod maxLateness;
04675
04676
04677 double minShipment;
04678
04679
04680 bool hidden;
04681
04682
04683 OperationPlan_list deli;
04684 };
04685
04686
04687
04688
04689 class DemandDefault : public Demand
04690 {
04691 public:
04692 explicit DemandDefault(const string& str) : Demand(str) {initType(metadata);}
04693 virtual const MetaClass& getType() const {return *metadata;}
04694 static DECLARE_EXPORT const MetaClass* metadata;
04695 virtual size_t getSize() const
04696 {return sizeof(DemandDefault) + Demand::extrasize();}
04697 static int initialize();
04698 };
04699
04700
04701
04702
04703
04704
04705
04706
04707 class LoadPlan : public TimeLine<LoadPlan>::EventChangeOnhand, public PythonExtensionBase
04708 {
04709 friend class OperationPlan::LoadPlanIterator;
04710 public:
04711
04712
04713
04714
04715
04716
04717 explicit DECLARE_EXPORT LoadPlan(OperationPlan*, const Load*);
04718
04719
04720 OperationPlan* getOperationPlan() const {return oper;}
04721
04722
04723 const Load* getLoad() const {return ld;}
04724
04725
04726 const Resource* getResource() const {return ld->getResource();}
04727
04728
04729
04730
04731 DECLARE_EXPORT void setLoad(const Load*);
04732
04733
04734 bool isStart() const {return start_or_end == START;}
04735
04736
04737 DECLARE_EXPORT virtual ~LoadPlan();
04738
04739
04740
04741
04742 DECLARE_EXPORT void update();
04743
04744
04745 TimeLine<LoadPlan>* getTimeLine() const
04746 {return &(ld->getResource()->loadplans);}
04747
04748
04749
04750
04751
04752 DECLARE_EXPORT const string& getSetup(bool = true) const;
04753
04754
04755
04756
04757 bool getHidden() const {return ld->getHidden();}
04758
04759
04760
04761
04762
04763
04764
04765
04766 DECLARE_EXPORT LoadPlan* getOtherLoadPlan() const;
04767
04768 static int initialize();
04769 static DECLARE_EXPORT const MetaCategory* metadata;
04770 PyObject* getattro(const Attribute&);
04771
04772 private:
04773
04774
04775
04776
04777 DECLARE_EXPORT LoadPlan(OperationPlan*, const Load*, LoadPlan*);
04778
04779
04780
04781 enum type {START, END};
04782
04783
04784 type start_or_end;
04785
04786
04787 const Load *ld;
04788
04789
04790 OperationPlan *oper;
04791
04792
04793 LoadPlan *nextLoadPlan;
04794 };
04795
04796
04797 inline Date Load::getLoadplanDate(const LoadPlan* lp) const
04798 {
04799 const DateRange & dr = lp->getOperationPlan()->getDates();
04800 if (lp->isStart())
04801 return dr.getStart() > getEffective().getStart() ?
04802 dr.getStart() :
04803 getEffective().getStart();
04804 else
04805 return dr.getEnd() < getEffective().getEnd() ?
04806 dr.getEnd() :
04807 getEffective().getEnd();
04808 }
04809
04810
04811 inline double Load::getLoadplanQuantity(const LoadPlan* lp) const
04812 {
04813 if (!lp->getOperationPlan()->getDates().overlap(getEffective())
04814 && (lp->getOperationPlan()->getDates().getDuration()
04815 || !getEffective().within(lp->getOperationPlan()->getDates().getStart())))
04816
04817
04818
04819 return 0.0;
04820 return lp->isStart() ? getQuantity() : -getQuantity();
04821 }
04822
04823
04824
04825
04826
04827
04828
04829 class ProblemBeforeCurrent : public Problem
04830 {
04831 public:
04832 string getDescription() const
04833 {
04834 ostringstream ch;
04835 ch << "Job '" << static_cast<OperationPlan*>(getOwner())->getIdentifier()
04836 << "' planned in the past";
04837 return ch.str();
04838 }
04839 bool isFeasible() const {return false;}
04840 double getWeight() const
04841 {return dynamic_cast<OperationPlan*>(getOwner())->getQuantity();}
04842 explicit ProblemBeforeCurrent(OperationPlan* o) : Problem(o)
04843 {addProblem();}
04844 ~ProblemBeforeCurrent() {removeProblem();}
04845 string getEntity() const {return "operation";}
04846 Object* getOwner() const {return dynamic_cast<OperationPlan*>(owner);}
04847 const DateRange getDateRange() const
04848 {
04849 OperationPlan *o = dynamic_cast<OperationPlan*>(getOwner());
04850 if (o->getDates().getEnd() > Plan::instance().getCurrent())
04851 return DateRange(o->getDates().getStart(),
04852 Plan::instance().getCurrent());
04853 else
04854 return DateRange(o->getDates().getStart(),
04855 o->getDates().getEnd());
04856 }
04857 size_t getSize() const {return sizeof(ProblemBeforeCurrent);}
04858
04859
04860 const MetaClass& getType() const {return *metadata;}
04861
04862
04863 static DECLARE_EXPORT const MetaClass* metadata;
04864 };
04865
04866
04867
04868
04869
04870
04871
04872 class ProblemBeforeFence : public Problem
04873 {
04874 public:
04875 string getDescription() const
04876 {
04877 ostringstream ch;
04878 ch << "Job '" << static_cast<OperationPlan*>(getOwner())->getIdentifier()
04879 << "' planned before fence";
04880 return ch.str();
04881 }
04882 bool isFeasible() const {return true;}
04883 double getWeight() const
04884 {return static_cast<OperationPlan*>(getOwner())->getQuantity();}
04885 explicit ProblemBeforeFence(OperationPlan* o) : Problem(o)
04886 {addProblem();}
04887 ~ProblemBeforeFence() {removeProblem();}
04888 string getEntity() const {return "operation";}
04889 Object* getOwner() const {return dynamic_cast<OperationPlan*>(owner);}
04890 const DateRange getDateRange() const
04891 {
04892 OperationPlan *o = dynamic_cast<OperationPlan*>(owner);
04893 if (o->getDates().getEnd() > Plan::instance().getCurrent()
04894 + o->getOperation()->getFence())
04895 return DateRange(o->getDates().getStart(),
04896 Plan::instance().getCurrent() + o->getOperation()->getFence());
04897 else
04898 return DateRange(o->getDates().getStart(),
04899 o->getDates().getEnd());
04900 }
04901 size_t getSize() const {return sizeof(ProblemBeforeFence);}
04902
04903
04904 const MetaClass& getType() const {return *metadata;}
04905
04906
04907 static DECLARE_EXPORT const MetaClass* metadata;
04908 };
04909
04910
04911
04912
04913
04914 class ProblemPrecedence : public Problem
04915 {
04916 public:
04917 string getDescription() const
04918 {
04919 OperationPlan *o = static_cast<OperationPlan*>(getOwner());
04920 if (!o->nextsubopplan)
04921 return string("Bogus precendence problem on '")
04922 + o->getOperation()->getName() + "'";
04923 else
04924 return string("Operation '") + o->getOperation()->getName()
04925 + "' starts before operation '"
04926 + o->nextsubopplan->getOperation()->getName() +"' ends";
04927 }
04928 bool isFeasible() const {return false;}
04929
04930 double getWeight() const
04931 {
04932 return static_cast<double>(getDateRange().getDuration()) / 86400;
04933 }
04934 explicit ProblemPrecedence(OperationPlan* o) : Problem(o) {addProblem();}
04935 ~ProblemPrecedence() {removeProblem();}
04936 string getEntity() const {return "operation";}
04937 Object* getOwner() const {return dynamic_cast<OperationPlan*>(owner);}
04938 const DateRange getDateRange() const
04939 {
04940 OperationPlan *o = static_cast<OperationPlan*>(getOwner());
04941 return DateRange(o->nextsubopplan->getDates().getStart(),
04942 o->getDates().getEnd());
04943 }
04944
04945
04946 const MetaClass& getType() const {return *metadata;}
04947
04948
04949 static DECLARE_EXPORT const MetaClass* metadata;
04950 size_t getSize() const {return sizeof(ProblemPrecedence);}
04951 };
04952
04953
04954
04955
04956
04957
04958
04959
04960 class ProblemDemandNotPlanned : public Problem
04961 {
04962 public:
04963 string getDescription() const
04964 {return string("Demand '") + getDemand()->getName() + "' is not planned";}
04965 bool isFeasible() const {return false;}
04966 double getWeight() const {return getDemand()->getQuantity();}
04967 explicit ProblemDemandNotPlanned(Demand* d) : Problem(d) {addProblem();}
04968 ~ProblemDemandNotPlanned() {removeProblem();}
04969 string getEntity() const {return "demand";}
04970 const DateRange getDateRange() const
04971 {return DateRange(getDemand()->getDue(),getDemand()->getDue());}
04972 Object* getOwner() const {return dynamic_cast<Demand*>(owner);}
04973 Demand* getDemand() const {return dynamic_cast<Demand*>(owner);}
04974 size_t getSize() const {return sizeof(ProblemDemandNotPlanned);}
04975
04976
04977 const MetaClass& getType() const {return *metadata;}
04978
04979
04980 static DECLARE_EXPORT const MetaClass* metadata;
04981 };
04982
04983
04984
04985
04986
04987 class ProblemLate : public Problem
04988 {
04989 public:
04990 DECLARE_EXPORT string getDescription() const;
04991 bool isFeasible() const {return true;}
04992
04993
04994
04995
04996 double getWeight() const
04997 {
04998 assert(getDemand() && !getDemand()->getDelivery().empty());
04999 return static_cast<double>(DateRange(
05000 getDemand()->getDue(),
05001 getDemand()->getLatestDelivery()->getDates().getEnd()
05002 ).getDuration()) / 86400;
05003 }
05004
05005
05006 explicit ProblemLate(Demand* d) : Problem(d) {addProblem();}
05007
05008
05009 ~ProblemLate() {removeProblem();}
05010
05011 const DateRange getDateRange() const
05012 {
05013 assert(getDemand() && !getDemand()->getDelivery().empty());
05014 return DateRange(getDemand()->getDue(),
05015 getDemand()->getLatestDelivery()->getDates().getEnd());
05016 }
05017 Demand* getDemand() const {return dynamic_cast<Demand*>(getOwner());}
05018 size_t getSize() const {return sizeof(ProblemLate);}
05019 string getEntity() const {return "demand";}
05020 Object* getOwner() const {return dynamic_cast<Demand*>(owner);}
05021
05022
05023 const MetaClass& getType() const {return *metadata;}
05024
05025
05026 static DECLARE_EXPORT const MetaClass* metadata;
05027 };
05028
05029
05030
05031
05032
05033 class ProblemEarly : public Problem
05034 {
05035 public:
05036 DECLARE_EXPORT string getDescription() const;
05037 bool isFeasible() const {return true;}
05038 double getWeight() const
05039 {
05040 assert(getDemand() && !getDemand()->getDelivery().empty());
05041 return static_cast<double>(DateRange(
05042 getDemand()->getDue(),
05043 getDemand()->getEarliestDelivery()->getDates().getEnd()
05044 ).getDuration()) / 86400;
05045 }
05046 explicit ProblemEarly(Demand* d) : Problem(d) {addProblem();}
05047 ~ProblemEarly() {removeProblem();}
05048 string getEntity() const {return "demand";}
05049 Object* getOwner() const {return dynamic_cast<Demand*>(owner);}
05050 const DateRange getDateRange() const
05051 {
05052 assert(getDemand() && !getDemand()->getDelivery().empty());
05053 return DateRange(getDemand()->getDue(),
05054 getDemand()->getEarliestDelivery()->getDates().getEnd());
05055 }
05056 Demand* getDemand() const {return dynamic_cast<Demand*>(getOwner());}
05057 size_t getSize() const {return sizeof(ProblemEarly);}
05058
05059
05060 const MetaClass& getType() const {return *metadata;}
05061
05062
05063 static DECLARE_EXPORT const MetaClass* metadata;
05064 };
05065
05066
05067
05068
05069
05070 class ProblemShort : public Problem
05071 {
05072 public:
05073 string getDescription() const
05074 {
05075 ostringstream ch;
05076 ch << "Demand '" << getDemand()->getName() << "' planned "
05077 << (getDemand()->getQuantity() - getDemand()->getPlannedQuantity())
05078 << " units short";
05079 return ch.str();
05080 }
05081 bool isFeasible() const {return true;}
05082 double getWeight() const
05083 {return getDemand()->getQuantity() - getDemand()->getPlannedQuantity();}
05084 explicit ProblemShort(Demand* d) : Problem(d) {addProblem();}
05085 ~ProblemShort() {removeProblem();}
05086 string getEntity() const {return "demand";}
05087 const DateRange getDateRange() const
05088 {return DateRange(getDemand()->getDue(), getDemand()->getDue());}
05089 Object* getOwner() const {return dynamic_cast<Demand*>(owner);}
05090 Demand* getDemand() const {return dynamic_cast<Demand*>(owner);}
05091 size_t getSize() const {return sizeof(ProblemShort);}
05092
05093
05094 const MetaClass& getType() const {return *metadata;}
05095
05096
05097 static DECLARE_EXPORT const MetaClass* metadata;
05098 };
05099
05100
05101
05102
05103
05104 class ProblemExcess : public Problem
05105 {
05106 public:
05107 string getDescription() const
05108 {
05109 ostringstream ch;
05110 ch << "Demand '" << getDemand()->getName() << "' planned "
05111 << (getDemand()->getPlannedQuantity() - getDemand()->getQuantity())
05112 << " units excess";
05113 return ch.str();
05114 }
05115 bool isFeasible() const {return true;}
05116 double getWeight() const
05117 {return getDemand()->getPlannedQuantity() - getDemand()->getQuantity();}
05118 explicit ProblemExcess(Demand* d) : Problem(d) {addProblem();}
05119 string getEntity() const {return "demand";}
05120 Object* getOwner() const {return dynamic_cast<Demand*>(owner);}
05121 ~ProblemExcess() {removeProblem();}
05122 const DateRange getDateRange() const
05123 {return DateRange(getDemand()->getDue(), getDemand()->getDue());}
05124 Demand* getDemand() const {return dynamic_cast<Demand*>(getOwner());}
05125 size_t getSize() const {return sizeof(ProblemExcess);}
05126
05127
05128 const MetaClass& getType() const {return *metadata;}
05129
05130
05131 static DECLARE_EXPORT const MetaClass* metadata;
05132 };
05133
05134
05135
05136
05137
05138 class ProblemCapacityOverload : public Problem
05139 {
05140 public:
05141 DECLARE_EXPORT string getDescription() const;
05142 bool isFeasible() const {return false;}
05143 double getWeight() const {return qty;}
05144 ProblemCapacityOverload(Resource* r, DateRange d, double q)
05145 : Problem(r), qty(q), dr(d) {addProblem();}
05146 ~ProblemCapacityOverload() {removeProblem();}
05147 string getEntity() const {return "capacity";}
05148 Object* getOwner() const {return dynamic_cast<Resource*>(owner);}
05149 const DateRange getDateRange() const {return dr;}
05150 Resource* getResource() const {return dynamic_cast<Resource*>(getOwner());}
05151 size_t getSize() const {return sizeof(ProblemCapacityOverload);}
05152
05153
05154 const MetaClass& getType() const {return *metadata;}
05155
05156
05157 static DECLARE_EXPORT const MetaClass* metadata;
05158
05159 private:
05160
05161 double qty;
05162
05163
05164 DateRange dr;
05165 };
05166
05167
05168
05169
05170
05171 class ProblemCapacityUnderload : public Problem
05172 {
05173 public:
05174 DECLARE_EXPORT string getDescription() const;
05175 bool isFeasible() const {return true;}
05176 double getWeight() const {return qty;}
05177 ProblemCapacityUnderload(Resource* r, DateRange d, double q)
05178 : Problem(r), qty(q), dr(d) {addProblem();}
05179 ~ProblemCapacityUnderload() {removeProblem();}
05180 string getEntity() const {return "capacity";}
05181 Object* getOwner() const {return dynamic_cast<Resource*>(owner);}
05182 const DateRange getDateRange() const {return dr;}
05183 Resource* getResource() const {return dynamic_cast<Resource*>(getOwner());}
05184 size_t getSize() const {return sizeof(ProblemCapacityUnderload);}
05185
05186
05187 const MetaClass& getType() const {return *metadata;}
05188
05189
05190 static DECLARE_EXPORT const MetaClass* metadata;
05191
05192 private:
05193
05194 double qty;
05195
05196
05197 DateRange dr;
05198 };
05199
05200
05201
05202
05203
05204 class ProblemMaterialShortage : public Problem
05205 {
05206 public:
05207 DECLARE_EXPORT string getDescription() const;
05208 bool isFeasible() const {return false;}
05209 double getWeight() const {return qty;}
05210 ProblemMaterialShortage(Buffer* b, Date st, Date nd, double q)
05211 : Problem(b), qty(q), dr(st,nd) {addProblem();}
05212 string getEntity() const {return "material";}
05213 Object* getOwner() const {return dynamic_cast<Buffer*>(owner);}
05214 ~ProblemMaterialShortage() {removeProblem();}
05215 const DateRange getDateRange() const {return dr;}
05216 Buffer* getBuffer() const {return dynamic_cast<Buffer*>(getOwner());}
05217 size_t getSize() const {return sizeof(ProblemMaterialShortage);}
05218
05219
05220 const MetaClass& getType() const {return *metadata;}
05221
05222
05223 static DECLARE_EXPORT const MetaClass* metadata;
05224
05225 private:
05226
05227 double qty;
05228
05229
05230 DateRange dr;
05231 };
05232
05233
05234
05235
05236
05237 class ProblemMaterialExcess : public Problem
05238 {
05239 public:
05240 DECLARE_EXPORT string getDescription() const;
05241 bool isFeasible() const {return true;}
05242 double getWeight() const {return qty;}
05243 ProblemMaterialExcess(Buffer* b, Date st, Date nd, double q)
05244 : Problem(b), qty(q), dr(st,nd) {addProblem();}
05245 string getEntity() const {return "material";}
05246 ~ProblemMaterialExcess() {removeProblem();}
05247 const DateRange getDateRange() const {return dr;}
05248 Object* getOwner() const {return dynamic_cast<Buffer*>(owner);}
05249 Buffer* getBuffer() const {return dynamic_cast<Buffer*>(owner);}
05250 size_t getSize() const {return sizeof(ProblemMaterialExcess);}
05251
05252
05253 const MetaClass& getType() const {return *metadata;}
05254
05255
05256 static DECLARE_EXPORT const MetaClass* metadata;
05257
05258 private:
05259
05260 double qty;
05261
05262
05263 DateRange dr;
05264 };
05265
05266
05267
05268
05269
05270
05271
05272
05273 class CommandCreateOperationPlan : public Command
05274 {
05275 public:
05276
05277 CommandCreateOperationPlan
05278 (const Operation* o, double q, Date d1, Date d2, Demand* l,
05279 OperationPlan* ow=NULL, bool makeflowsloads=true)
05280 {
05281 opplan = o ?
05282 o->createOperationPlan(q, d1, d2, l, ow, 0, makeflowsloads)
05283 : NULL;
05284 }
05285 void execute()
05286 {
05287 if (opplan)
05288 {
05289 opplan->instantiate();
05290 opplan = NULL;
05291 }
05292 }
05293 void undo() {delete opplan; opplan = NULL;}
05294 bool undoable() const {return true;}
05295 ~CommandCreateOperationPlan() {if (opplan) delete opplan;}
05296 OperationPlan *getOperationPlan() const {return opplan;}
05297
05298 private:
05299
05300 OperationPlan *opplan;
05301 };
05302
05303
05304
05305
05306
05307
05308 class CommandDeleteOperationPlan : public Command
05309 {
05310 public:
05311
05312
05313
05314 DECLARE_EXPORT CommandDeleteOperationPlan(OperationPlan* o);
05315 void execute() {oper = NULL;}
05316 DECLARE_EXPORT void undo();
05317 bool undoable() const {return true;}
05318 ~CommandDeleteOperationPlan() {if (oper) undo();}
05319
05320 private:
05321
05322 Operation *oper;
05323
05324
05325 DateRange dates;
05326
05327
05328 double qty;
05329
05330
05331 long unsigned id;
05332
05333
05334 Demand *dmd;
05335
05336
05337 OperationPlan *ow;
05338 };
05339
05340
05341
05342
05343
05344
05345
05346
05347 class CommandMoveOperationPlan : public Command
05348 {
05349 public:
05350
05351
05352
05353
05354
05355
05356
05357
05358 DECLARE_EXPORT CommandMoveOperationPlan(OperationPlan* opplanptr,
05359 Date newStart, Date newEnd, double newQty = -1.0);
05360
05361
05362 DECLARE_EXPORT CommandMoveOperationPlan(OperationPlan*);
05363
05364
05365 void execute() {opplan=NULL;}
05366
05367
05368 void undo() {restore(true); opplan = NULL;}
05369
05370
05371 DECLARE_EXPORT void restore(bool = false);
05372
05373 bool undoable() const {return true;}
05374
05375
05376 ~CommandMoveOperationPlan() {if (opplan) undo();}
05377
05378
05379 OperationPlan* getOperationPlan() const {return opplan;}
05380
05381
05382 void setStart(Date d) {if (opplan) opplan->setStart(d);}
05383
05384
05385 void setParameters(Date s, Date e, double q, bool b)
05386 {
05387 assert(opplan->getOperation());
05388 if (opplan)
05389 opplan->getOperation()->setOperationPlanParameters(opplan, q, s, e, b);
05390 }
05391
05392
05393 void setEnd(Date d) {if (opplan) opplan->setEnd(d);}
05394
05395
05396 void setQuantity(double q) {if (opplan) opplan->setQuantity(q);}
05397
05398
05399 double getQuantity() const {return originalqty; }
05400
05401
05402 DateRange getDates() const {return originaldates;}
05403
05404 private:
05405
05406 OperationPlan *opplan;
05407
05408
05409 DateRange originaldates;
05410
05411
05412 double originalqty;
05413
05414
05415 Command* firstCommand;
05416 };
05417
05418
05419
05420
05421
05422
05423
05424
05425
05426
05427 class HasProblems::EntityIterator
05428 {
05429 private:
05430
05431
05432
05433
05434 union
05435 {
05436 Buffer::iterator *bufIter;
05437 Resource::iterator *resIter;
05438 OperationPlan::iterator *operIter;
05439 Demand::iterator *demIter;
05440 };
05441
05442
05443
05444
05445
05446
05447
05448
05449 unsigned short type;
05450
05451 public:
05452
05453
05454 explicit DECLARE_EXPORT EntityIterator();
05455
05456
05457
05458 explicit EntityIterator(unsigned short i) : type(i) {}
05459
05460
05461 DECLARE_EXPORT EntityIterator(const EntityIterator& o);
05462
05463
05464 DECLARE_EXPORT EntityIterator& operator=(const EntityIterator& o);
05465
05466
05467 DECLARE_EXPORT ~EntityIterator();
05468
05469
05470 DECLARE_EXPORT EntityIterator& operator++();
05471
05472
05473
05474
05475 DECLARE_EXPORT bool operator != (const EntityIterator& t) const;
05476
05477
05478
05479
05480 bool operator == (const EntityIterator& t) const {return !(*this != t);}
05481
05482
05483 DECLARE_EXPORT HasProblems& operator*() const;
05484
05485
05486 DECLARE_EXPORT HasProblems* operator->() const;
05487 };
05488
05489
05490
05491
05492
05493
05494
05495
05496
05497
05498 class Problem::const_iterator
05499 {
05500 friend class Problem;
05501 private:
05502
05503
05504 Problem* iter;
05505 HasProblems* owner;
05506 HasProblems::EntityIterator eiter;
05507
05508 public:
05509
05510
05511
05512
05513
05514 explicit const_iterator(HasProblems* o) : iter(o ? o->firstProblem : NULL),
05515 owner(o), eiter(4) {}
05516
05517
05518
05519 explicit const_iterator() : owner(NULL)
05520 {
05521
05522 while (eiter!=HasProblems::endEntity() && !(eiter->firstProblem))
05523 ++eiter;
05524
05525 iter = (eiter!=HasProblems::endEntity()) ? eiter->firstProblem : NULL;
05526 }
05527
05528
05529 DECLARE_EXPORT const_iterator& operator++();
05530
05531
05532 bool operator != (const const_iterator& t) const {return iter!=t.iter;}
05533
05534
05535 bool operator == (const const_iterator& t) const {return iter==t.iter;}
05536
05537 Problem& operator*() const {return *iter;}
05538 Problem* operator->() const {return iter;}
05539 };
05540
05541
05542
05543
05544
05545
05546
05547
05548
05549
05550
05551
05552
05553 class PeggingIterator : public Object
05554 {
05555 public:
05556
05557 DECLARE_EXPORT PeggingIterator(const Demand* e);
05558
05559
05560 PeggingIterator(const FlowPlan* e, bool b = true)
05561 : downstream(b), firstIteration(true)
05562 {
05563 if (!e) return;
05564 if (downstream)
05565 states.push(state(0,abs(e->getQuantity()),1.0,e,NULL));
05566 else
05567 states.push(state(0,abs(e->getQuantity()),1.0,NULL,e));
05568 initType(metadata);
05569 }
05570
05571
05572 OperationPlan* getConsumingOperationplan() const
05573 {
05574 const FlowPlan* x = states.top().cons_flowplan;
05575 return x ? x->getOperationPlan() : NULL;
05576 }
05577
05578
05579 Buffer *getBuffer() const
05580 {
05581 const FlowPlan* x = states.top().prod_flowplan;
05582 if (!x) x = states.top().cons_flowplan;
05583 return x ? x->getFlow()->getBuffer() : NULL;
05584 }
05585
05586
05587 OperationPlan* getProducingOperationplan() const
05588 {
05589 const FlowPlan* x = states.top().prod_flowplan;
05590 return x ? x->getOperationPlan() : NULL;
05591 }
05592
05593
05594 Date getConsumingDate() const
05595 {
05596 const FlowPlan* x = states.top().cons_flowplan;
05597 return x ? x->getDate() : Date::infinitePast;
05598 }
05599
05600
05601 Date getProducingDate() const
05602 {
05603 const FlowPlan* x = states.top().prod_flowplan;
05604 return x ? x->getDate() : Date::infinitePast;
05605 }
05606
05607
05608
05609
05610
05611 short getLevel() const {return states.top().level;}
05612
05613
05614
05615
05616 double getQuantityDemand() const {return states.top().qty;}
05617
05618
05619
05620
05621 double getQuantityBuffer() const
05622 {
05623 const state& t = states.top();
05624 return t.prod_flowplan
05625 ? t.factor * t.prod_flowplan->getOperationPlan()->getQuantity()
05626 : 0;
05627 }
05628
05629
05630
05631 double getFactor() const {return states.top().factor;}
05632
05633
05634
05635
05636 bool getPegged() const {return states.top().pegged;}
05637
05638
05639 DECLARE_EXPORT PeggingIterator& operator++();
05640
05641
05642
05643
05644
05645 PeggingIterator operator++(int)
05646 {PeggingIterator tmp = *this; ++*this; return tmp;}
05647
05648
05649 DECLARE_EXPORT PeggingIterator& operator--();
05650
05651
05652
05653
05654
05655 PeggingIterator operator--(int)
05656 {PeggingIterator tmp = *this; --*this; return tmp;}
05657
05658
05659 bool operator==(const PeggingIterator& x) const {return states == x.states;}
05660
05661
05662 bool operator!=(const PeggingIterator& x) const {return states != x.states;}
05663
05664
05665
05666
05667
05668 operator bool () const {return !states.empty();}
05669
05670
05671 DECLARE_EXPORT void updateStack(short, double, double, const FlowPlan*, const FlowPlan*, bool = true);
05672
05673
05674 bool isDownstream() {return downstream;}
05675
05676
05677 static int initialize();
05678
05679 virtual void endElement(XMLInput& i, const Attribute& a, const DataElement& d)
05680 {
05681 throw LogicException("Pegging can't be read");
05682 }
05683 virtual const MetaClass& getType() const {return *metadata;}
05684 static DECLARE_EXPORT const MetaCategory* metadata;
05685 size_t getSize() const {return sizeof(PeggingIterator);}
05686
05687 private:
05688
05689
05690 struct state
05691 {
05692
05693 double qty;
05694
05695
05696
05697
05698 double factor;
05699
05700
05701
05702
05703 short level;
05704
05705
05706 const FlowPlan* cons_flowplan;
05707
05708
05709 const FlowPlan* prod_flowplan;
05710
05711
05712 bool pegged;
05713
05714
05715 state(unsigned int l, double d, double f,
05716 const FlowPlan* fc, const FlowPlan* fp, bool p = true)
05717 : qty(d), factor(f), level(l),
05718 cons_flowplan(fc), prod_flowplan(fp), pegged(p) {};
05719
05720
05721 bool operator != (const state& s) const
05722 {
05723 return cons_flowplan != s.cons_flowplan
05724 || prod_flowplan != s.prod_flowplan
05725 || level != s.level;
05726 }
05727
05728
05729 bool operator == (const state& s) const
05730 {
05731 return cons_flowplan == s.cons_flowplan
05732 && prod_flowplan == s.prod_flowplan
05733 && level == s.level;
05734 }
05735 };
05736
05737
05738 typedef stack < state > statestack;
05739
05740
05741 statestack states;
05742
05743
05744 DECLARE_EXPORT PyObject *iternext();
05745
05746 DECLARE_EXPORT PyObject* getattro(const Attribute&);
05747
05748
05749 DECLARE_EXPORT void followPegging(const OperationPlan*, short, double, double);
05750
05751
05752
05753
05754
05755 bool first;
05756
05757
05758 bool downstream;
05759
05760
05761
05762
05763 bool firstIteration;
05764 };
05765
05766
05767
05768
05769
05770
05771 class OperationPlan::FlowPlanIterator
05772 {
05773 friend class OperationPlan;
05774 private:
05775 FlowPlan* curflowplan;
05776 FlowPlan* prevflowplan;
05777 FlowPlanIterator(FlowPlan* b) : curflowplan(b), prevflowplan(NULL) {}
05778 public:
05779 FlowPlanIterator(const FlowPlanIterator& b)
05780 {
05781 curflowplan = b.curflowplan;
05782 prevflowplan = b.prevflowplan;
05783 }
05784 bool operator != (const FlowPlanIterator &b) const
05785 {return b.curflowplan != curflowplan;}
05786 bool operator == (const FlowPlanIterator &b) const
05787 {return b.curflowplan == curflowplan;}
05788 FlowPlanIterator& operator++()
05789 {
05790 prevflowplan = curflowplan;
05791 if (curflowplan) curflowplan = curflowplan->nextFlowPlan;
05792 return *this;
05793 }
05794 FlowPlanIterator operator++(int)
05795 {FlowPlanIterator tmp = *this; ++*this; return tmp;}
05796 FlowPlan* operator ->() const {return curflowplan;}
05797 FlowPlan& operator *() const {return *curflowplan;}
05798 void deleteFlowPlan()
05799 {
05800 if (!curflowplan) return;
05801 if (prevflowplan) prevflowplan->nextFlowPlan = curflowplan->nextFlowPlan;
05802 else curflowplan->oper->firstflowplan = curflowplan->nextFlowPlan;
05803 FlowPlan* tmp = curflowplan;
05804
05805 curflowplan = curflowplan->nextFlowPlan;
05806 delete tmp;
05807 }
05808 };
05809
05810 inline OperationPlan::FlowPlanIterator OperationPlan::beginFlowPlans() const
05811 {return OperationPlan::FlowPlanIterator(firstflowplan);}
05812
05813 inline OperationPlan::FlowPlanIterator OperationPlan::endFlowPlans() const
05814 {return OperationPlan::FlowPlanIterator(NULL);}
05815
05816 inline int OperationPlan::sizeFlowPlans() const
05817 {
05818 int c = 0;
05819 for (FlowPlanIterator i = beginFlowPlans(); i != endFlowPlans(); ++i) ++c;
05820 return c;
05821 }
05822
05823
05824
05825
05826
05827
05828 class OperationPlan::LoadPlanIterator
05829 {
05830 friend class OperationPlan;
05831 private:
05832 LoadPlan* curloadplan;
05833 LoadPlan* prevloadplan;
05834 LoadPlanIterator(LoadPlan* b) : curloadplan(b), prevloadplan(NULL) {}
05835 public:
05836 LoadPlanIterator(const LoadPlanIterator& b)
05837 {
05838 curloadplan = b.curloadplan;
05839 prevloadplan = b.prevloadplan;
05840 }
05841 bool operator != (const LoadPlanIterator &b) const
05842 {return b.curloadplan != curloadplan;}
05843 bool operator == (const LoadPlanIterator &b) const
05844 {return b.curloadplan == curloadplan;}
05845 LoadPlanIterator& operator++()
05846 {
05847 prevloadplan = curloadplan;
05848 if (curloadplan) curloadplan = curloadplan->nextLoadPlan;
05849 return *this;
05850 }
05851 LoadPlanIterator operator++(int)
05852 {LoadPlanIterator tmp = *this; ++*this; return tmp;}
05853 LoadPlan* operator ->() const {return curloadplan;}
05854 LoadPlan& operator *() const {return *curloadplan;}
05855 void deleteLoadPlan()
05856 {
05857 if (!curloadplan) return;
05858 if (prevloadplan) prevloadplan->nextLoadPlan = curloadplan->nextLoadPlan;
05859 else curloadplan->oper->firstloadplan = curloadplan->nextLoadPlan;
05860 LoadPlan* tmp = curloadplan;
05861
05862 curloadplan = curloadplan->nextLoadPlan;
05863 delete tmp;
05864 }
05865 };
05866
05867 inline OperationPlan::LoadPlanIterator OperationPlan::beginLoadPlans() const
05868 {return OperationPlan::LoadPlanIterator(firstloadplan);}
05869
05870 inline OperationPlan::LoadPlanIterator OperationPlan::endLoadPlans() const
05871 {return OperationPlan::LoadPlanIterator(NULL);}
05872
05873 inline int OperationPlan::sizeLoadPlans() const
05874 {
05875 int c = 0;
05876 for (LoadPlanIterator i = beginLoadPlans(); i != endLoadPlans(); ++i) ++c;
05877 return c;
05878 }
05879
05880
05881 class ProblemIterator
05882 : public FreppleIterator<ProblemIterator,Problem::const_iterator,Problem>
05883 {
05884 };
05885
05886
05887 class BufferIterator
05888 : public FreppleIterator<BufferIterator,Buffer::iterator,Buffer>
05889 {
05890 };
05891
05892
05893 class LocationIterator
05894 : public FreppleIterator<LocationIterator,Location::iterator,Location>
05895 {
05896 };
05897
05898
05899 class CustomerIterator
05900 : public FreppleIterator<CustomerIterator,Customer::iterator,Customer>
05901 {
05902 };
05903
05904
05905 class ItemIterator
05906 : public FreppleIterator<ItemIterator,Item::iterator,Item>
05907 {
05908 };
05909
05910 class DemandIterator
05911 : public FreppleIterator<DemandIterator,Demand::iterator,Demand>
05912 {
05913 };
05914
05915
05916 class ResourceIterator
05917 : public FreppleIterator<ResourceIterator,Resource::iterator,Resource>
05918 {
05919 };
05920
05921
05922 class SolverIterator
05923 : public FreppleIterator<SolverIterator,Solver::iterator,Solver>
05924 {
05925 };
05926
05927
05928 class OperationIterator
05929 : public FreppleIterator<OperationIterator,Operation::iterator,Operation>
05930 {
05931 };
05932
05933
05934 class CalendarIterator
05935 : public FreppleIterator<CalendarIterator,Calendar::iterator,Calendar>
05936 {
05937 };
05938
05939
05940 class SetupMatrixIterator
05941 : public FreppleIterator<SetupMatrixIterator,SetupMatrix::iterator,SetupMatrix>
05942 {
05943 };
05944
05945
05946
05947
05948
05949
05950
05951 class SetupMatrixRuleIterator : public PythonExtension<SetupMatrixRuleIterator>
05952 {
05953 public:
05954 static int initialize();
05955
05956 SetupMatrixRuleIterator(SetupMatrix* c) : matrix(c)
05957 {
05958 if (!c)
05959 throw LogicException("Creating rule iterator for NULL matrix");
05960 currule = c->beginRules();
05961 }
05962
05963 private:
05964 SetupMatrix* matrix;
05965 SetupMatrix::RuleIterator currule;
05966 PyObject *iternext();
05967 };
05968
05969
05970
05971
05972
05973
05974
05975 class CalendarBucketIterator : public PythonExtension<CalendarBucketIterator>
05976 {
05977 public:
05978 static int initialize();
05979
05980 CalendarBucketIterator(Calendar* c) : cal(c)
05981 {
05982 if (!c)
05983 throw LogicException("Creating bucket iterator for NULL calendar");
05984 i = c->beginBuckets();
05985 }
05986
05987 private:
05988 Calendar* cal;
05989 Calendar::BucketIterator i;
05990 PyObject *iternext();
05991 };
05992
05993
05994 class CalendarEventIterator
05995 : public PythonExtension<CalendarEventIterator>
05996 {
05997 public:
05998 static int initialize();
05999
06000 CalendarEventIterator(Calendar* c, Date d=Date::infinitePast, bool f=true)
06001 : cal(c), eventiter(c,d,f), forward(f) {}
06002
06003 private:
06004 Calendar* cal;
06005 Calendar::EventIterator eventiter;
06006 bool forward;
06007 PyObject *iternext();
06008 };
06009
06010
06011
06012
06013
06014
06015
06016 class OperationPlanIterator
06017 : public FreppleIterator<OperationPlanIterator,OperationPlan::iterator,OperationPlan>
06018 {
06019 public:
06020
06021 OperationPlanIterator() {}
06022
06023
06024 OperationPlanIterator(Operation* o)
06025 : FreppleIterator<OperationPlanIterator,OperationPlan::iterator,OperationPlan>(o)
06026 {}
06027
06028
06029 OperationPlanIterator(OperationPlan* opplan)
06030 : FreppleIterator<OperationPlanIterator,OperationPlan::iterator,OperationPlan>(opplan)
06031 {}
06032 };
06033
06034
06035
06036
06037
06038
06039
06040 class FlowPlanIterator : public PythonExtension<FlowPlanIterator>
06041 {
06042 public:
06043 static int initialize();
06044
06045 FlowPlanIterator(Buffer* b) : buf(b), buffer_or_opplan(true)
06046 {
06047 if (!b)
06048 throw LogicException("Creating flowplan iterator for NULL buffer");
06049 bufiter = new Buffer::flowplanlist::const_iterator(b->getFlowPlans().begin());
06050 }
06051
06052 FlowPlanIterator(OperationPlan* o) : opplan(o), buffer_or_opplan(false)
06053 {
06054 if (!o)
06055 throw LogicException("Creating flowplan iterator for NULL operationplan");
06056 opplaniter = new OperationPlan::FlowPlanIterator(o->beginFlowPlans());
06057 }
06058
06059 ~FlowPlanIterator()
06060 {
06061 if (buffer_or_opplan) delete bufiter;
06062 else delete opplaniter;
06063 }
06064
06065 private:
06066 union
06067 {
06068 Buffer* buf;
06069 OperationPlan* opplan;
06070 };
06071
06072 union
06073 {
06074 Buffer::flowplanlist::const_iterator *bufiter;
06075 OperationPlan::FlowPlanIterator *opplaniter;
06076 };
06077
06078
06079
06080 bool buffer_or_opplan;
06081
06082 PyObject *iternext();
06083 };
06084
06085
06086
06087
06088
06089
06090
06091 class LoadPlanIterator : public PythonExtension<LoadPlanIterator>
06092 {
06093 public:
06094 static int initialize();
06095
06096 LoadPlanIterator(Resource* r) : res(r), resource_or_opplan(true)
06097 {
06098 if (!r)
06099 throw LogicException("Creating loadplan iterator for NULL resource");
06100 resiter = new Resource::loadplanlist::const_iterator(r->getLoadPlans().begin());
06101 }
06102
06103 LoadPlanIterator(OperationPlan* o) : opplan(o), resource_or_opplan(false)
06104 {
06105 if (!opplan)
06106 throw LogicException("Creating loadplan iterator for NULL operationplan");
06107 opplaniter = new OperationPlan::LoadPlanIterator(o->beginLoadPlans());
06108 }
06109
06110 ~LoadPlanIterator()
06111 {
06112 if (resource_or_opplan) delete resiter;
06113 else delete opplaniter;
06114 }
06115
06116 private:
06117 union
06118 {
06119 Resource* res;
06120 OperationPlan* opplan;
06121 };
06122
06123 union
06124 {
06125 Resource::loadplanlist::const_iterator *resiter;
06126 OperationPlan::LoadPlanIterator *opplaniter;
06127 };
06128
06129
06130
06131 bool resource_or_opplan;
06132
06133 PyObject *iternext();
06134 };
06135
06136
06137
06138
06139
06140
06141
06142 class DemandPlanIterator : public PythonExtension<DemandPlanIterator>
06143 {
06144 public:
06145 static int initialize();
06146
06147 DemandPlanIterator(Demand* r) : dem(r)
06148 {
06149 if (!r)
06150 throw LogicException("Creating demandplan iterator for NULL demand");
06151 i = r->getDelivery().begin();
06152 }
06153
06154 private:
06155 Demand* dem;
06156 Demand::OperationPlan_list::const_iterator i;
06157 PyObject *iternext();
06158 };
06159
06160
06161
06162
06163
06164
06165
06166 class LoadIterator : public PythonExtension<LoadIterator>
06167 {
06168 public:
06169 static int initialize();
06170
06171 LoadIterator(Resource* r)
06172 : res(r), ir(r ? r->getLoads().begin() : NULL), oper(NULL), io(NULL)
06173 {
06174 if (!r)
06175 throw LogicException("Creating loadplan iterator for NULL resource");
06176 }
06177
06178 LoadIterator(Operation* o)
06179 : res(NULL), ir(NULL), oper(o), io(o ? o->getLoads().begin() : NULL)
06180 {
06181 if (!o)
06182 throw LogicException("Creating loadplan iterator for NULL operation");
06183 }
06184
06185 private:
06186 Resource* res;
06187 Resource::loadlist::const_iterator ir;
06188 Operation* oper;
06189 Operation::loadlist::const_iterator io;
06190 PyObject *iternext();
06191 };
06192
06193
06194
06195
06196
06197
06198
06199 class FlowIterator : public PythonExtension<FlowIterator>
06200 {
06201 public:
06202 static int initialize();
06203
06204 FlowIterator(Buffer* b)
06205 : buf(b), ib(b ? b->getFlows().begin() : NULL), oper(NULL), io(NULL)
06206 {
06207 if (!b)
06208 throw LogicException("Creating flowplan iterator for NULL buffer");
06209 }
06210
06211 FlowIterator(Operation* o)
06212 : buf(NULL), ib(NULL), oper(o), io(o ? o->getFlows().begin() : NULL)
06213 {
06214 if (!o)
06215 throw LogicException("Creating flowplan iterator for NULL operation");
06216 }
06217
06218 private:
06219 Buffer* buf;
06220 Buffer::flowlist::const_iterator ib;
06221 Operation* oper;
06222 Operation::flowlist::const_iterator io;
06223 PyObject *iternext();
06224 };
06225
06226
06227 }
06228
06229 #endif