//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- /* virtual */ void Slot::notifyAgent(const Date_Time *when, CallbackType action) { // // This method is defined on some subclasses of the Slot. // agent->notifyContainer(when, action); } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // virtual bool ExchangeSlotAgent::notifyContainer(const Date_Time *when, CallbackType action) { #ifdef INSTRUMENT Instrument::AcctTimer dummy; #endif if (!rwAssert(_slot != NULL && _exchange != NULL)) { return true; // error } // if the accounting system is solving... if( // if the accounting system is solving... (AccountMgrObj->isSolving() == true) && ((action = filterOutFutureSolving(when, action)) != NULL_CALLBACK_TYPE) ) { // notify the slot that a value changed. currently only // MultiSlot defines this behavior. _slot->slotChanged(when, _slot, action); // notify the exchange that a value changed. #ifdef COUNT_DISPATCHES CountDispatches::solve(CountDispatches::ent_exchange); #endif _exchange->slotChanged(when, _slot, action); } return false; // success } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- bool Exchange::slotChanged(const Date_Time *when, const Slot *slot, CallbackType callback) { #ifdef DEBUG_EXCHANGE /* * DEBUGGING: *if slot name is "Destination Balance" and *object name is RGOtowiBernalilloHeronEX * stop here in debugger */ if(slot->getName() == "Destination Balance") { Exchange *e = slot->getExchange(); if(e && e->getName() == "RGOtowiBernalilloHeronEX") { cerr << "RGOtowiBernalilloHeronEX.Destination Balance" <hasAttribute(Slot::ExchangeSlotBit)) { if ( callback == SERIESSLOT_SERIES_VALUE_CHANGED_NOWONLY || callback == SUBSLOT_SERIES_VALUE_CHANGED_NOWONLY ) { // don't solve ahead; return true; } bool status; Date_Time timestepContext = *applContext.getTimestepContext(); if (slot == &_sourceBalance) { status = solve_next_source_balance(when, slot); } else if (slot == &_destBalance) { status = solve_next_dest_balance(when, slot); } APPL_TIMESTEP_CONTEXT(×tepContext); return status; } else if (slot->hasAttribute(Slot::PaybackSlotBit)) { return true; } else if (slot->hasAttribute(Slot::SupplySlotBit)) { // get the supply. Supply* supply = slot->getSupply(); if ((_borrowSupply && (supply == _borrowSupply)) || (supply == _inputBorrow)) { return solve_source_balance(when, slot) && solve_dest_balance(when, slot); } else if (getPayback(supply) != NULL) { return solve_source_balance(when, slot); } else if (supply == _destSupply) { return solve_dest_balance(when, slot); } } rwAssert(false); return false; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // private bool Exchange::solve_next_source_balance(const Date_Time *when, const Slot * /*slot*/) { static const char* mname ("Exchange::solve_next_source_balance"); //----------------------- static int nestCount (0); ++nestCount; //----------------------- if (nestCount == 6) { static int cnt (0); ++cnt; } if (nestCount > 640) { const QString whenStr (when->userTimeDateAbv()); std::cout << mname << " MAX NEST at DateTime: " << qPrintable (whenStr) << std::endl; --nestCount; return (true); // no change, OK //---------->> } //---------------------------------------- _solveNextSourceBalance_inProgress = true; //---------------------------------------- bool status(true); // return status double balance; // source balance double nextBorrow; // next borrow value double nextPayback; // sum of next payback-minus-loss values // get the source balance, the next borrow value, and the sum of // the next payback-minus-loss values. if (_sourceBalance.getValue(when, 0, balance) == false && getBorrowValue(nextBorrow, when, 1) && sumPaybackMinusLossValues(nextPayback, when, 1)) { if (!isValid(balance)) { balance = 0.0; } // calculate the next balance. double nextBalance(balance + nextBorrow - nextPayback); // set the next source balance. Date_Time nextDt(*when); nextDt += _sourceBalance.getStep(); if (nestCount > 636) { const QString whenStr (nextDt.userTimeDateAbv()); std::cout << mname << " [NEST " << nestCount << "]" << " " << qPrintable (whenStr) << "; VAL " << nextBalance << " '" << qPrintable (_sourceBalance.getCompleteName()) << "'" << std::endl; } SetStatus setStatus( _sourceBalance.setStdValue(nextBalance, &nextDt)); if (setStatus == SET_OK || setStatus == SET_NOCHANGE) { // solve the paybacks. solve_paybacks(&nextDt); } else { status = false; } } //----------------------------------------- _solveNextSourceBalance_inProgress = false; //----------------------------------------- //----------------------- --nestCount; //----------------------- return status; } //----------------------------------------------------------------------------- //-----------------------------------------------------------------------------