-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflowplan.cpp
More file actions
627 lines (570 loc) · 22.9 KB
/
Copy pathflowplan.cpp
File metadata and controls
627 lines (570 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/***************************************************************************
* *
* Copyright (C) 2007-2015 by frePPLe bv *
* *
* Permission is hereby granted, free of charge, to any person obtaining *
* a copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE *
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION *
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION *
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
***************************************************************************/
#include "frepple/model.h"
namespace frepple {
const MetaClass* FlowPlan::metadata;
const MetaCategory* FlowPlan::metacategory;
int FlowPlan::initialize() {
// Initialize the metadata
metacategory =
MetaCategory::registerCategory<FlowPlan>("flowplan", "flowplans", reader);
metadata = MetaClass::registerClass<FlowPlan>("flowplan", "flowplan", true);
registerFields<FlowPlan>(const_cast<MetaClass*>(metadata));
// Initialize the Python type
auto& x = FreppleCategory<FlowPlan>::getPythonType();
x.setName("flowplan");
x.setDoc("frePPLe flowplan");
x.supportgetattro();
x.supportsetattro();
x.supportcreate(create);
metadata->setPythonClass(x);
return x.typeReady();
}
FlowPlan::FlowPlan(OperationPlan* opplan, const Flow* f)
: fl(const_cast<Flow*>(f)), oper(opplan) {
assert(opplan && f);
// Initialize the Python type
initType(metadata);
// Link the flowplan to the operationplan
if (opplan->firstflowplan) {
// Append to the end
FlowPlan* c = opplan->firstflowplan;
while (c->nextFlowPlan) c = c->nextFlowPlan;
c->nextFlowPlan = this;
} else
// First in the list
opplan->firstflowplan = this;
// Find the buffer
if (fl->getBuffer() && fl->getBuffer()->getItem() &&
fl->getBuffer()->getItem()->hasType<ItemMTO>()) {
buf = Buffer::findOrCreate(fl->getBuffer()->getItem(),
fl->getBuffer()->getLocation(),
opplan->getBatch());
} else
buf = fl->getBuffer();
assert(buf);
// Compute the flowplan quantity
auto fl_info = fl->getFlowplanDateQuantity(this);
buf->flowplans.insert(this, fl_info.second, fl_info.first);
// Mark the operation and buffer as having changed. This will trigger the
// recomputation of their problems
buf->setChanged();
fl->getOperation()->setChanged();
}
FlowPlan::FlowPlan(OperationPlan* opplan, const Flow* f, Date d, double q)
: fl(const_cast<Flow*>(f)), oper(opplan) {
assert(opplan && f);
// Initialize the Python type
initType(metadata);
// Link the flowplan to the operationplan
if (opplan->firstflowplan) {
// Append to the end
FlowPlan* c = opplan->firstflowplan;
while (c->nextFlowPlan) c = c->nextFlowPlan;
c->nextFlowPlan = this;
} else
// First in the list
opplan->firstflowplan = this;
// Find the buffer
if (fl->getBuffer() && fl->getBuffer()->getItem() &&
fl->getBuffer()->getItem()->hasType<ItemMTO>()) {
if (fl->getBuffer()->getItem()->hasType<ItemMTO>() && opplan->getBatch())
buf = Buffer::findOrCreate(fl->getBuffer()->getItem(),
fl->getBuffer()->getLocation(),
opplan->getBatch());
} else
buf = fl->getBuffer();
assert(buf);
// Compute the flowplan quantity
buf->flowplans.insert(this, q, d);
// Mark the operation and buffer as having changed. This will trigger the
// recomputation of their problems
buf->setChanged();
fl->getOperation()->setChanged();
}
string FlowPlan::getStatus() const {
if (flags & STATUS_CONFIRMED)
return "confirmed";
else
return "proposed";
}
void FlowPlan::setStatus(const string& s) {
if (getOperationPlan()->getProposed() && s == "confirmed")
throw DataException(
"OperationPlanMaterial locked while OperationPlan is not");
if (s == "confirmed")
flags |= STATUS_CONFIRMED;
else if (s == "proposed")
flags &= ~STATUS_CONFIRMED;
else
throw DataException("invalid operationplanmaterial status:" + s);
}
void FlowPlan::update() {
// Update the timeline data structure
auto fl_info = fl->getFlowplanDateQuantity(this);
buf->flowplans.update(this, fl_info.second, fl_info.first);
// Mark the operation and buffer as having changed. This will trigger the
// recomputation of their problems
buf->setChanged();
fl->getOperation()->setChanged();
}
void FlowPlan::updateBatch() {
// Remove from the old buffer, if there is one
if (buf) {
buf->flowplans.erase(this);
buf->setChanged();
}
// Insert in the new buffer
PooledString batch = getOperationPlan()->getBatch();
if (fl->getBuffer()->getItem()->hasType<ItemMTO>() && batch)
buf = Buffer::findOrCreate(fl->getBuffer()->getItem(),
fl->getBuffer()->getLocation(), batch);
else
buf = fl->getBuffer();
buf->flowplans.insert(this, getQuantity(), getDate());
buf->setChanged();
}
void FlowPlan::setBuffer(Buffer* newbuf) {
if (newbuf == buf) return;
if (!newbuf) throw DataException("Can't switch to nullptr buffer");
if (!buf) throw DataException("Can't switch from nullptr buffer");
if (newbuf->getItem() != buf->getItem() ||
newbuf->getLocation() != buf->getLocation())
throw DataException(
"Flowplans can only switch to buffers with the same item and location");
if (fl && fl->hasType<FlowTransferBatch>()) {
// Switch all flowplans of the same transfer batch
auto oldbuf = buf;
for (auto flpln = getOperationPlan()->beginFlowPlans();
flpln != getOperationPlan()->endFlowPlans(); ++flpln) {
if (flpln->buf != oldbuf) continue;
// Remove from the old buffer
flpln->buf->flowplans.erase(&*flpln);
// Insert in the new buffer
flpln->buf = newbuf;
flpln->buf->flowplans.insert(&*flpln, flpln->getQuantity(),
flpln->getDate());
}
oldbuf->setChanged();
} else {
// Remove from the old buffer
buf->flowplans.erase(this);
buf->setChanged();
// Insert in the new buffer
buf = newbuf;
buf->flowplans.insert(this, getQuantity(), getDate());
}
buf->setChanged();
}
void FlowPlan::setFlow(Flow* newfl) {
// No change
if (newfl == fl) return;
// Verify the data
if (!newfl) throw DataException("Can't switch to nullptr flow");
if (newfl->getType() != fl->getType())
throw DataException("Flowplans can only switch to flows of the same type");
PooledString batch;
if (buf) batch = buf->getBatch();
if (!newfl->hasType<FlowTransferBatch>() || !fl) {
// Remove from the old buffer, if there is one
if (fl) {
if (fl->getOperation() != newfl->getOperation())
throw DataException(
"Only switching to a flow on the same operation is allowed");
if (buf) {
buf->flowplans.erase(this);
buf->setChanged();
}
}
// Insert in the new buffer
fl = newfl;
auto fl_info = fl->getFlowplanDateQuantity(this);
if (fl->getBuffer()->getItem()->hasType<ItemMTO>() && !batch.empty())
buf = Buffer::findOrCreate(fl->getBuffer()->getItem(),
fl->getBuffer()->getLocation(), batch);
else
buf = fl->getBuffer();
buf->flowplans.insert(this, fl_info.second, fl_info.first);
buf->setChanged();
fl->getOperation()->setChanged();
} else {
// Switch all flowplans of the same transfer batch
auto oldFlow = fl;
if (oldFlow->getOperation() != newfl->getOperation())
throw DataException(
"Only switching to a flow on the same operation is allowed");
if (fl->getBuffer()->getItem()->hasType<ItemMTO>() && !batch.empty())
buf = Buffer::findOrCreate(fl->getBuffer()->getItem(),
fl->getBuffer()->getLocation(), batch);
else
buf = fl->getBuffer();
for (auto flpln = getOperationPlan()->beginFlowPlans();
flpln != getOperationPlan()->endFlowPlans(); ++flpln) {
if (flpln->getFlow() != oldFlow) continue;
// Remove from the old buffer
flpln->buf->flowplans.erase(&*flpln);
flpln->buf->setChanged();
// Insert in the new buffer
flpln->fl = newfl;
auto fl_info = flpln->fl->getFlowplanDateQuantity(&*flpln);
buf->flowplans.insert(&*flpln, fl_info.second, fl_info.first);
buf->setChanged();
flpln->fl->getOperation()->setChanged();
}
}
}
void FlowPlan::setItem(Item* newItem) {
// Verify the data
if (!newItem) throw DataException("Can't switch to nullptr flow");
if (fl && fl->getBuffer()) {
if (newItem == fl->getBuffer()->getItem())
// No change
return;
else
// Already set
throw DataException("Item can be set only once on a flowplan");
}
// We are not expecting to use this method in this way...
throw LogicException("Not implemented");
}
void FlowPlan::setQuantityRaw(double q) {
if (buf) buf->flowplans.update(this, q, getDate());
}
pair<double, double> FlowPlan::setQuantity(double quantity, bool rounddown,
bool update, bool execute,
short mode) {
// TODO argument "update" isn't used
if (getConfirmed()) {
// Confirmed flowplans take any quantity, regardless of the
// quantity of the owning operationplan.
if (execute) {
// Update the timeline data structure
buf->flowplans.update(this, quantity, getDate());
// Mark the operation and buffer as having changed. This will trigger the
// recomputation of their problems
buf->setChanged();
fl->getOperation()->setChanged();
}
return make_pair(quantity, oper->getQuantity());
}
if (!getFlow()->getEffective().within(getDate())) {
if (execute) {
if (mode == 2 || (mode == 0 && getFlow()->hasType<FlowEnd>())) {
oper->setOperationPlanParameters(
0.0, Date::infinitePast, computeFlowToOperationDate(oper->getEnd()),
true, execute, rounddown);
} else if (mode == 1 || (mode == 0 && getFlow()->hasType<FlowStart>())) {
oper->setOperationPlanParameters(
0.0,
(mode == 1 && getFlow()->hasType<FlowEnd>())
? oper->getStart()
: computeFlowToOperationDate(oper->getStart()),
Date::infinitePast, false, execute, rounddown);
}
}
return make_pair(0.0, 0.0);
}
double opplan_quantity;
bool less_than_fixed_qty =
fabs(getFlow()->getQuantityFixed()) &&
fabs(quantity) < fabs(getFlow()->getQuantityFixed()) + ROUNDING_ERROR;
if (getFlow()->getQuantity() == 0.0 || less_than_fixed_qty) {
// Fixed quantity flows only allow resizing to 0
if (less_than_fixed_qty && oper->getQuantity() != 0.0) {
if (mode == 2 || (mode == 0 && getFlow()->hasType<FlowEnd>()))
opplan_quantity = oper->setOperationPlanParameters(
0.0, Date::infinitePast,
computeFlowToOperationDate(oper->getEnd()),
true, execute, rounddown)
.quantity;
else if (mode == 1 || (mode == 0 && getFlow()->hasType<FlowStart>()))
opplan_quantity =
oper->setOperationPlanParameters(
0.0,
(mode == 1 && getFlow()->hasType<FlowEnd>())
? oper->getStart()
: computeFlowToOperationDate(oper->getStart()),
Date::infinitePast, false, execute, rounddown)
.quantity;
else
throw LogicException("Unreachable code reached");
} else if (!less_than_fixed_qty && oper->getQuantity() == 0.0) {
if (mode == 2 || (mode == 0 && getFlow()->hasType<FlowEnd>()))
opplan_quantity = oper->setOperationPlanParameters(
0.001, Date::infinitePast,
computeFlowToOperationDate(oper->getEnd()),
true, execute, rounddown)
.quantity;
else if (mode == 1 || (mode == 0 && getFlow()->hasType<FlowStart>()))
opplan_quantity =
oper->setOperationPlanParameters(
0.001,
(mode == 1 && getFlow()->hasType<FlowEnd>())
? oper->getStart()
: computeFlowToOperationDate(oper->getStart()),
Date::infinitePast, false, execute, rounddown)
.quantity;
else
throw LogicException("Unreachable code reached");
}
} else {
// Proportional or transfer batch flows
// For transfer batch flowplans the argument quantity is expected to be the
// total quantity of all batches.
if (mode == 2 || (mode == 0 && getFlow()->hasType<FlowEnd>()))
opplan_quantity = oper->setOperationPlanParameters(
(quantity - getFlow()->getQuantityFixed()) /
getFlow()->getQuantity(),
Date::infinitePast,
(mode == 2 || getFlow()->hasType<FlowStart>())
? oper->getEnd()
: computeFlowToOperationDate(getDate()),
true, execute, rounddown)
.quantity;
else if (mode == 1 || (mode == 0 && getFlow()->hasType<FlowStart>()))
opplan_quantity = oper->setOperationPlanParameters(
(quantity - getFlow()->getQuantityFixed()) /
getFlow()->getQuantity(),
(mode == 1 || getFlow()->hasType<FlowEnd>())
? oper->getStart()
: computeFlowToOperationDate(getDate()),
Date::infinitePast, false, execute, rounddown)
.quantity;
else
throw LogicException("Unreachable code reached");
}
if (execute && oper->getOwner()) {
// Update all sibling operationplans
for (auto i = oper->getOwner()->firstsubopplan; i; i = i->nextsubopplan)
if (i != oper) i->update();
}
if (opplan_quantity)
return make_pair(opplan_quantity * getFlow()->getQuantity() +
getFlow()->getQuantityFixed(),
opplan_quantity);
else
return make_pair(0.0, 0.0);
}
int FlowPlanIterator::initialize() {
// Initialize the type
auto& x = PythonExtension<FlowPlanIterator>::getPythonType();
x.setName("flowplanIterator");
x.setDoc("frePPLe iterator for flowplan");
x.supportiter();
return x.typeReady();
}
PyObject* FlowPlanIterator::iternext() {
FlowPlan* fl;
if (buffer_or_opplan) {
// Skip uninteresting entries
while (*bufiter != buf->getFlowPlans().end() &&
(*bufiter)->getQuantity() == 0.0)
++(*bufiter);
if (*bufiter == buf->getFlowPlans().end()) return nullptr;
fl = const_cast<FlowPlan*>(static_cast<const FlowPlan*>(&*((*bufiter)++)));
} else {
// Skip uninteresting entries
while (*opplaniter != opplan->endFlowPlans() &&
(*opplaniter)->getQuantity() == 0.0)
++(*opplaniter);
if (*opplaniter == opplan->endFlowPlans()) return nullptr;
fl = static_cast<FlowPlan*>(&*((*opplaniter)++));
}
Py_INCREF(fl);
return const_cast<FlowPlan*>(fl);
}
Object* FlowPlan::reader(const MetaClass* cat, const DataValueDict& in,
CommandManager* mgr) {
// Pick up the operationplan attribute. An error is reported if it's missing.
const DataValue* opplanElement = in.get(Tags::operationplan);
if (!opplanElement) throw DataException("Missing operationplan field");
Object* opplanobject = opplanElement->getObject();
if (!opplanobject || !opplanobject->hasType<OperationPlan>())
throw DataException("Invalid operationplan field");
auto* opplan = static_cast<OperationPlan*>(opplanobject);
// Pick up the item.
const DataValue* itemElement = in.get(Tags::item);
if (!itemElement) throw DataException("Item must be provided");
Object* itemobject = itemElement->getObject();
if (!itemobject || itemobject->getType().category != Item::metadata)
throw DataException("Invalid item field");
Item* itm = static_cast<Item*>(itemobject);
// Find the flow for this item on the operationplan.
// If multiple exist, we pick up the first one.
// TODO detect situations where the flowplan is on an alternate material
auto flplniter = opplan->getFlowPlans();
FlowPlan* flpln;
while ((flpln = flplniter.next())) {
if (flpln->getItem() == itm) return flpln;
}
OperationPlan* correctowner = nullptr;
Flow* correctflow = nullptr;
for (auto& f : opplan->getOperation()->getFlows()) {
if (f.getItem() == itm) {
correctowner = opplan;
correctflow = const_cast<Flow*>(&f);
break;
}
}
auto subopplans = opplan->getSubOperationPlans();
OperationPlan* firstChildOpplan = nullptr;
while (auto subopplan = subopplans.next()) {
if (!firstChildOpplan) firstChildOpplan = subopplan;
auto subflplniter = subopplan->getFlowPlans();
FlowPlan* subflpln;
while ((subflpln = subflplniter.next())) {
if (subflpln->getItem() == itm) return subflpln;
}
if (!correctowner)
for (auto& f : subopplan->getOperation()->getFlows()) {
if (f.getItem() == itm) {
correctowner = subopplan;
correctflow = const_cast<Flow*>(&f);
break;
}
}
}
// No existing flowplans is found, create a new one.
// TODO code assumes consuming flowplans
if (correctowner) opplan = correctowner;
if (!correctowner && firstChildOpplan) opplan = firstChildOpplan;
auto loc = opplan->getLocation();
if (!loc) {
loc = opplan->getOperation()->getLocation();
if (!loc) return nullptr;
}
auto buf = Buffer::findOrCreate(itm, loc, opplan->getBatch());
if (!correctflow) {
correctflow = new FlowStart(opplan->getOperation(), buf, -1);
correctflow->setHidden(true);
correctflow->setEffectiveEnd(Date::infinitePast);
}
return new FlowPlan(opplan, correctflow);
}
PyObject* FlowPlan::create(PyTypeObject* pytype, PyObject* args,
PyObject* kwds) {
try {
// Find or create the C++ object
PythonDataValueDict atts(kwds);
Object* x = reader(FlowPlan::metadata, atts, nullptr);
if (!x) {
Py_INCREF(Py_None);
return Py_None;
}
Py_INCREF(x);
// Iterate over extra keywords, and set attributes.
if (x) {
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(kwds, &pos, &key, &value)) {
PythonData field(value);
PyObject* key_utf8 = PyUnicode_AsUTF8String(key);
DataKeyword attr(PyBytes_AsString(key_utf8));
Py_DECREF(key_utf8);
if (!attr.isA(Tags::operationplan) && !attr.isA(Tags::item)) {
const MetaFieldBase* fmeta = x->getType().findField(attr.getHash());
if (!fmeta && x->getType().category)
fmeta = x->getType().category->findField(attr.getHash());
if (fmeta)
// Update the attribute
fmeta->setField(x, field);
else
x->setProperty(attr.getName(), value);
}
};
}
return x;
} catch (...) {
PythonType::evalException();
return nullptr;
}
}
Duration FlowPlan::getPeriodOfCover() const {
// Case 1: If the backlog is more than the onhand => period of cover is 0
// We consider the initial stock - all confirmed consumptions - all overdue
// demand
double left_for_consumption = getBuffer()->getOnHand();
auto fpiter = getBuffer()->getFlowPlans().begin(this);
fpiter++;
bool found = false;
while (fpiter != getBuffer()->getFlowPlans().end()) {
// subtract deliveries
if (fpiter->getQuantity() < 0.0 && fpiter->getDate() >= getDate() &&
fpiter->getOperationPlan()
->getOperation()
->hasType<OperationDelivery>() &&
fpiter->getOperationPlan()->getDemand()->getDue() < getDate()) {
left_for_consumption += fpiter->getQuantity();
found = true;
}
// add confirmed/completed/approved replenishments
if (fpiter->getQuantity() > 0.0 &&
fpiter->getDate() <= getDate() + Duration(1L) &&
(fpiter->getOperationPlan()->getStatus() == "approved" ||
fpiter->getOperationPlan()->getStatus() == "confirmed" ||
fpiter->getOperationPlan()->getStatus() == "completed"))
left_for_consumption += fpiter->getQuantity();
++fpiter;
}
if (found && left_for_consumption < ROUNDING_ERROR) return Duration(0L);
// Case 2: Regular case
left_for_consumption = getOnhand();
if (left_for_consumption > 0) {
auto fpiter2 = getBuffer()->getFlowPlans().begin(this);
++fpiter2;
while (fpiter2 != getBuffer()->getFlowPlans().end()) {
if (fpiter2->getQuantity() < 0.0) {
left_for_consumption += fpiter2->getQuantity();
if (left_for_consumption < ROUNDING_ERROR)
return fpiter2->getDate() - getDate();
}
++fpiter2;
}
} else {
// Case 3:
// On hand is 0 so we display the next consumer's date
auto fpiter2 = getBuffer()->getFlowPlans().begin(this);
++fpiter2;
while (fpiter2 != getBuffer()->getFlowPlans().end()) {
if (fpiter2->getQuantity() < 0.0) {
return max(0L, fpiter2->getDate() - getDate() -
fpiter2->getOperationPlan()->getDelay());
}
++fpiter2;
}
}
return Duration(999L * 86400L);
}
bool FlowPlan::getFeasible() const {
if (getBuffer()->hasType<BufferInfinite>()) return true;
auto flplaniter = getBuffer()->getFlowPlans();
for (auto cur = flplaniter.begin(this); cur != flplaniter.end(); ++cur) {
if (cur->getOnhand() < -ROUNDING_ERROR && cur->isLastOnDate())
// Material shortage
return false;
}
return true;
}
} // namespace frepple