void DemandController::execute( void ) { // update class variables _currentTime += 1; int operation = (int)setValue; // SEND DATA TO GLD; GET DATA FROM GLD std::cout << "DemandController: sending GridlabDInput interaction: " << object << "/" << parameter << ": " << value << units << ": " << operation << std::endl; GridlabDInputSP gldiSP = create_GridlabDInput(); gldiSP->set_ObjectName( object ); gldiSP->set_Parameter( parameter ); gldiSP->set_Value( value ); gldiSP->set_Units( units ); gldiSP->set_Operation( operation ); gldiSP->sendInteraction( getRTI(), _currentTime + getLookAhead() ); // GET MESSAGES HERE FROM HLA // init temporary variables InteractionRoot::SP interactionRootSP; while ( (interactionRootSP = getNextInteraction() ) != 0 ) { boost::shared_ptr<GridlabDOutput> gldoSP( boost::static_pointer_cast<GridlabDOutput>( interactionRootSP ) ); std::string recv_objectName = gldoSP->get_ObjectName(); std::string recv_parameterName = gldoSP->get_Parameter(); double recv_value = gldoSP->get_Value(); std::string recv_units = gldoSP->get_Units(); int recv_operation = gldoSP->get_Operation(); if (!strcmp(recv_objectName.c_str(), "Market_1") and setValue) { std::cout << "Received current market price: " << recv_value << std::endl; if (recv_value > 100 and value == 70) { std::cout << "Market price has increased too much, lowering demand." << std::endl; value = 60; } else if (recv_value <= 100 and value == 60) { std::cout << "Market price has decreased enough, increasing demand." << std::endl; value = 70; } } else if (!strcmp(recv_objectName.c_str(), object.c_str()) and !setValue) { std::cout << "DemandMonitor: Received updated demand: " << recv_objectName << "/" << recv_parameterName << ": " << recv_value << recv_units << std::endl; } } // Advance Time DemandControllerATRCallback gldfedATRcb( *this ); putAdvanceTimeRequest( _currentTime, gldfedATRcb ); }
//------------------------------------------------------------------------------ // updateAttributeValues() -- Send attributes to the RTI //------------------------------------------------------------------------------ bool NetIO::updateAttributeValues(const RTI::ObjectHandle handle, RTI::AttributeHandleValuePairSet* attrs, const char* theTag) { bool ok = true; if ( attrs->size() > 0) { try { if (getRegulating()) { //DPG getRTIambassador()->queryLookahead(getLookAhead()); getRTIambassador()->updateAttributeValues(handle, *attrs, (getFederationTime()+getLookAhead()), theTag); } else { getRTIambassador()->updateAttributeValues(handle, *attrs, 0); } } catch (RTI::Exception& e) { std::cerr << &e << std::endl; ok = false; } } return ok; }