88 virtual double getMin(
bool inclusive =
true)
const
96 return m ? m->newMin : 0.0;
101 virtual double getMax(
bool inclusive =
true)
const
109 return m ? m->newMax : 0.0;
112 virtual unsigned short getType()
const = 0;
143 virtual unsigned short getType()
const {
return 1;}
159 virtual double getMin(
bool inclusive =
true)
const
161 if (inclusive)
return newMin;
164 virtual unsigned short getType()
const {
return 3;}
180 virtual double getMax(
bool inclusive =
true)
const
182 if (inclusive)
return newMax;
185 virtual unsigned short getType()
const {
return 4;}
225 TimeLine() : first(NULL), last(NULL), lastMax(NULL), lastMin(NULL) {}
229 for (
Event* p=first; p; p=p->
next) ++cnt;
232 iterator
begin() {
return iterator(first);}
234 iterator
rbegin() {
return iterator(last);}
235 iterator
end() {
return iterator(NULL);}
236 const_iterator
begin()
const {
return const_iterator(first);}
237 const_iterator
begin(
const Event* e)
const {
return const_iterator(e);}
238 const_iterator
rbegin()
const {
return const_iterator(last);}
239 const_iterator
end()
const {
return const_iterator(NULL);}
240 bool empty()
const {
return first==NULL;}
246 insert(static_cast<Event*>(e));
249 void update(EventChangeOnhand*,
double,
const Date&);
257 logger <<
"Inspecting " <<
this <<
": \"" << name <<
"\":" << endl;
258 for (const_iterator oo=
begin(); oo!=
end(); ++oo)
259 logger <<
" " << oo->getDate() <<
" "
260 << oo->getQuantity() <<
" " << oo->getOnhand()
261 <<
" " << oo->getCumulativeProduced() << &*oo << endl;
267 EventMinQuantity *m = this->lastMin;
269 while(m && d < m->getDate()) m = m->
prevMin;
271 while(m && d <= m->getDate()) m = m->
prevMin;
272 return m ? m->
getMin() : 0.0;
276 virtual double getMin(
const Event *e,
bool inclusive =
true)
const
279 EventMinQuantity *m = this->lastMin;
281 while(m && e->getDate() < m->getDate()) m = m->
prevMin;
283 while(m && e->getDate() <= m->getDate()) m = m->
prevMin;
284 return m ? m->
getMin() : 0.0;
290 EventMaxQuantity *m = this->lastMax;
292 while(m && d < m->getDate()) m = m->
prevMax;
294 while(m && d <= m->getDate()) m = m->
prevMax;
295 return m ? m->
getMax() : 0.0;
299 virtual double getMax(
const Event *e,
bool inclusive =
true)
const
302 EventMaxQuantity *m = this->lastMax;
304 while(m && e->getDate() < m->getDate()) m = m->
prevMax;
306 while(m && e->getDate() <= m->getDate()) m = m->
prevMax;
307 return m ? m->
getMax() : 0.0;
313 EventMinQuantity *m = this->lastMin;
315 while(m && d < m->getDate()) m = m->
prevMin;
317 while(m && d <= m->getDate()) m = m->
prevMin;
324 EventMaxQuantity *m = this->lastMax;
326 while(m && d < m->getDate()) m = m->
prevMax;
328 while(m && d <= m->getDate()) m = m->
prevMax;
343 EventMaxQuantity *lastMax;
346 EventMinQuantity *lastMin;
358 for (; i!=end() && *e<*i; --i)
364 for (; i!=end() && *e<*i; --i)
395 if (qty>0) e->
cum_prod = i->cum_prod + qty;
403 if (!lastMin || m->
getDate() >= lastMin->getDate())
422 if (!lastMax || m->
getDate() >= lastMax->getDate())
448 for (
iterator i = begin(e); i!=end(); ++i)
454 for (
iterator i = begin(e); i!=end(); ++i)
511 double delta = e->quantity - newqty;
512 double oldqty = e->quantity;
517 e->quantity = newqty;
522 while ( e->
next && !(*e<*e->next) )
531 e->
next = theNextNext;
533 theNextNext->
prev = e;
536 if (first == e) first = theNext;
539 theNext->
oh -= oldqty;
540 if (oldqty > 0) theNext->
cum_prod -= oldqty;
551 e->
prev = thePrevPrev;
553 thePrevPrev->
next = e;
556 if (last == e) last = thePrev;
566 double cumdelta = (oldqty>0? oldqty : 0) - (newqty>0 ? newqty : 0);
567 if (fabs(cumdelta) > 0)
568 for (
iterator i=begin(e); i!=end(); ++i)
571 i->cum_prod -= cumdelta;
574 for (
iterator i=begin(e); i!=end(); ++i)
587 double expectedOH = 0.0;
588 double expectedCumProd = 0.0;
589 const Event *prev = NULL;
594 if (i->getQuantity() > 0) expectedCumProd += i->getQuantity();
597 inspect(
"Error: timeline onhand value corrupted on "
598 +
string(i->getDate()));
604 inspect(
"Error: timeline cumulative produced value corrupted on "
605 +
string(i->getDate()));
609 if (prev && !(*prev<*i)
612 inspect(
"Error: timeline sort corrupted on " +
string(i->getDate()));