void PeggingIterator::followPegging (const OperationPlan* op, double qty, double offset, short lvl) { // Zero quantity operationplans don't have further pegging if (!op->getQuantity()) return; // For each flowplan ask the buffer to find the pegged operationplans. if (downstream) for (OperationPlan::FlowPlanIterator i = op->beginFlowPlans(); i != op->endFlowPlans(); ++i) { if (i->getQuantity() > ROUNDING_ERROR) // Producing flowplan i->getFlow()->getBuffer()->followPegging(*this, &*i, qty, offset, lvl+1); } else for (OperationPlan::FlowPlanIterator i = op->beginFlowPlans(); i != op->endFlowPlans(); ++i) { if (i->getQuantity() < -ROUNDING_ERROR) // Consuming flowplan i->getFlow()->getBuffer()->followPegging(*this, &*i, qty, offset, lvl+1); } // Push child operationplans on the stack. // The pegged quantity is equal to the ratio of the quantities of the // parent and child operationplan. for (OperationPlan::iterator j(op); j != OperationPlan::end(); ++j) updateStack( &*j, qty * j->getQuantity() / op->getQuantity(), offset * j->getQuantity() / op->getQuantity(), lvl+1 ); }
void OperatorDelete::pushBuffers(OperationPlan* o, bool consuming) { // Loop over all flowplans for (OperationPlan::FlowPlanIterator i = o->beginFlowPlans(); i != o->endFlowPlans(); ++i) { // Skip flowplans we're not interested in if ((consuming && i->getQuantity() >= 0) || (!consuming && i->getQuantity() <= 0)) continue; // Check if the buffer is already found on the stack bool found = false; for (vector<Buffer*>::const_reverse_iterator j = buffersToScan.rbegin(); j != buffersToScan.rend(); ++j) { if (*j == i->getBuffer()) { found = true; break; } } // Add the buffer to the stack if (!found) buffersToScan.push_back(const_cast<Buffer*>(i->getBuffer())); } // Recursive call for all suboperationplans for (OperationPlan::iterator subopplan(o); subopplan != OperationPlan::end(); ++subopplan) pushBuffers(&*subopplan, consuming); }