DECLARE_EXPORT void Buffer::setOnHand(double f) { // The dummy operation to model the inventory may need to be created Operation *o = Operation::find(INVENTORY_OPERATION); Flow *fl; if (!o) { // Create a fixed time operation with zero leadtime, hidden from the xml // output, hidden for the solver, and without problem detection. o = new OperationFixedTime(); o->setName(INVENTORY_OPERATION); o->setHidden(true); o->setDetectProblems(false); fl = new FlowEnd(o, this, 1); } else // Find the flow of this operation fl = const_cast<Flow*>(&*(o->getFlows().begin())); // Check valid pointers if (!fl || !o) throw LogicException("Failed creating inventory operation for '" + getName() + "'"); // Make sure the sign of the flow is correct: +1 or -1. fl->setQuantity(f>=0.0 ? 1.0 : -1.0); // Create a dummy operationplan on the inventory operation OperationPlan::iterator i(o); if (i == OperationPlan::end()) { // No operationplan exists yet OperationPlan *opplan = o->createOperationPlan( fabs(f), Date::infinitePast, Date::infinitePast); opplan->setLocked(true); opplan->activate(); } else { // Update the existing operationplan i->setLocked(false); i->setQuantity(fabs(f)); i->setLocked(true); } setChanged(); }