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