virtual void output(vle::devs::Time /*time*/, vle::devs::ExternalEventList &output) const override { output.emplace_back("out"); output.back().addMap().addDouble("value", static_cast<double>(m_neighborhood)); }
void out(const vle::devs::Time& /*time*/, vle::devs::ExternalEventList& output) const { output.emplace_back("a"); value::Map& map = output.back().addMap(); map.addString("name","a"); map.addDouble("value",a+3); }
void externalTransition( const vle::devs::ExternalEventList& events, const vle::devs::Time& time) { vle::devs::ExternalEventList::const_iterator it = events.begin(); while (it != events.end()) { if ((*it)->onPort("available")) { bool available = (*it)->getBooleanAttributeValue("available"); unsigned int number = (*it)->getIntegerAttributeValue("number"); std::string type = (*it)->getStringAttributeValue("type"); if (available) { mAvailableResourceNumber += number; } else { mUnavailableResources[type] = mResourceConstraints->quantity(type) - number; } ++mResponseNumber; TraceModel( vle::fmt(" [%1%:%2%] at %3% -> available: %4% / %5%") % getModel().getParentName() % getModelName() % time % mAvailableResourceNumber % mResourceConstraints->quantity()); if (mAvailableResourceNumber == mResourceConstraints->quantity()) { mPhase = SEND_ASSIGN; } else { if (mResponseNumber == mResourceConstraints->size()) { clearDemand(); mPhase = SEND_UNAVAILABLE; } else { mPhase = WAIT_AVAILABLE; } } } else if ((*it)->onPort("demand")) { mResourceConstraints = ResourceConstraints::build(Resources::get(*it)); TraceModel(vle::fmt(" [%1%:%2%] at %3% -> demand: %4%") % getModel().getParentName() % getModelName() % time % mResourceConstraints->quantity()); mPhase = SEND_DEMAND; } else if ((*it)->onPort("release")) { mReleasedResources = Resources::build(Resources::get(*it)); TraceModel(vle::fmt(" [%1%:%2%] at %3% -> release: %4%") % getModel().getParentName() % getModelName() % time % *mReleasedResources); mPhase = SEND_RELEASE; } ++it; } }
void externalTransition( const vle::devs::ExternalEventList& events, const vle::devs::Time& time) { vle::devs::ExternalEventList::const_iterator it = events.begin(); while (it != events.end()) { if ((*it)->onPort("start")) { if (mPhase == INIT) { mActivities.starting(time); if (mActivities.startingActivities().empty()) { mPhase = WAIT; } else { mPhase = SEND; } } } else if ((*it)->onPort("done")) { Activity* a = Activity::build(Activity::get(*it)); TraceModel(vle::fmt(" [%1%:%2%] at %3% -> %4% DONE") % getModel().getParentName() % getModelName() % time % a->name()); mDoneActivities.push_back(a); } ++it; } if (mSigma > 0) { mSigma -= (time - mLastTime); mLastTime = time; } }
virtual void output(const vd::Time& time, vd::ExternalEventList& output) const { TraceAlways(vu::DateTime::simpleCurrentDate() + " - MMSExecute - Output at time : " + time.toString()); //Send event on external port (port "OUT") vd::ExternalEvent* evt = NULL; evt = new vd::ExternalEvent("bfalse"); if(evt != NULL) { vv::Value* val = Logical_toValue(this->bfalse); if(val != NULL) { evt << vd::attribute("bfalse", val); output.addEvent(evt); TraceModel(vu::DateTime::simpleCurrentDate() + " - Output port bfalse is changed to " + val->writeToString() + " at time " + time.toString()); } } evt = new vd::ExternalEvent("btrue"); if(evt != NULL) { vv::Value* val = Logical_toValue(this->btrue); if(val != NULL) { evt << vd::attribute("btrue", val); output.addEvent(evt); TraceModel(vu::DateTime::simpleCurrentDate() + " - Output port btrue is changed to " + val->writeToString() + " at time " + time.toString()); } } }
void output(vd::Time time, vd::ExternalEventList& output) const override { if (m_has_output_port) { const double out_val = m_val + m_trend * time; output.emplace_back(m_output_port_label); output.back().addMap().addDouble("d_val", out_val); } }
virtual void output(vd::Time /*time*/, vd::ExternalEventList &output) const override { if (m_has_output_port) { output.emplace_back(m_output_port_label); auto& m = output.back().addMap(); m.addDouble("up", m_upthreshold); m.addDouble("down", m_downthreshold); } }
void out2(const vle::devs::Time& /* time */, vle::devs::ExternalEventList& output) const { vle::devs::ExternalEvent* e = new vle::devs::ExternalEvent("g"); e->attributes().addString("name","g"); e->attributes().addDouble("value",0); output.push_back(e); e = new vle::devs::ExternalEvent("b"); e->attributes().addString("name","b"); e->attributes().addDouble("value",0); output.push_back(e); }
void out1(const vle::devs::Time& /*time*/, vle::devs::ExternalEventList& output) const { output.emplace_back("g"); value::Map& map = output.back().addMap(); map.addString("name","g"); map.addDouble("value",10); output.emplace_back("b"); value::Map& map2 = output.back().addMap();//TODO pas compris error qaund ion utilise la meme ref map (sur unique_ptr<Value>) map2.addString("name","b"); map2.addDouble("value",10); }
void out1(const vle::devs::Time& /*time*/, vle::devs::ExternalEventList& output) const { vle::devs::ExternalEvent* e = new vle::devs::ExternalEvent("g"); e->attributes().addString("name","g"); e->attributes().addDouble("value",10); output.push_back(e); e = new vle::devs::ExternalEvent("b"); e->attributes().addString("name","b"); e->attributes().addDouble("value",10); output.push_back(e); // std::cout << " FSA send out1 " << time << std::endl; }
void XRay::externalTransition( const vd::ExternalEventList& event, const vd::Time& time) { if (mPhase == RECEIVE) { if (!mapResult.empty()) mapResult.clear(); for (vd::ExternalEventList::const_iterator it = event.begin(); it != event.end(); ++it) { double randValue = rand().getDouble(); if ((*it) -> getPortName() == "status") { std::string value = (*it)-> getStringAttributeValue ("value"); std::string modelName = (*it)-> getStringAttributeValue ("modelName"); if (value == "S" || value == "R") { // probability of a wrong interpretation if (randValue > mProbabilityRightSR) { value = "I"; } } else if (value == "I") { if (randValue > mProbabilityRightI) { value = "S"; } } mapResult[modelName] = value; } } mCurrentTime = vd::Time(time); int nbInfected = 0; //int nbNonInfected = 0; std::map<std::string, std::string>::iterator node; for (node=mapResult.begin(); node!=mapResult.end();node++){ if (node->second == "I") nbInfected++; //else // nbNonInfected++; } //std::cout<<"xray recieve: "<<nbNonInfected<<" non infecteds and: "<< nbInfected // <<" infecteds at time: "<<time.getValue()<<"\n"; double tempPrev = ((double) nbInfected) / mSampleSize; //std::cout<<"tempPrev: "<<tempPrev<<"\n"; mIncidence = (tempPrev - mPrevalence)/mObservationTimeStep; mPrevalence = tempPrev; } }
/** * @brief Output function that fills the value of state variables * @param time, time of the output * @param extEvtList, the list of external event */ void outputVar(const vd::Time& /*time*/, vd::ExternalEventList& extEvtList) const { Variables::const_iterator itb = vars().begin(); Variables::const_iterator ite = vars().end(); for (; itb != ite; itb++) { const Variable& v = *itb->second; if (getModel().existOutputPort(itb->first)) { extEvtList.emplace_back(itb->first); value::Double& val = extEvtList.back().addDouble(); val = v.getVal(); } } }
void treat(const std::string& /*name*/, const ved::Activity& /*activity*/, vd::ExternalEventList& output) { output.emplace_back("x"); value::Map& m = output.back().addMap(); m.addString("name","x"); m.addDouble("value", plantlouse_population * (1-treatment_effect_on_plantlouse)); output.emplace_back("y"); value::Map& m2 = output.back().addMap(); m2.addString("name","y"); m2.addDouble("value", ladybird_population * (1-treatment_effect_on_ladybird)); }
virtual void output(const vle::devs::Time &time, vle::devs::ExternalEventList &output) const { (void)time; DTraceModel(vle::fmt("CompareDateAI: output at %1%") % time); if (date.empty() || index >= date.size()) return; auto low = std::lower_bound(date.begin() + index, date.end(), (*(date.begin() + index)).dmin, [] (const data& d, vle::devs::Time value) { return d.dmin <= value; }); DTraceModel(vle::fmt("CompareDateAI: need to send %1% start message" " (%2%)") % (std::distance(date.begin() + index, low)) % index); std::for_each(date.begin() + index, low, [&output] (const data& d) { vle::devs::ExternalEvent *ret = new vle::devs::ExternalEvent("start"); ret->putAttribute("specie_name", new vle::value::String( d.name)); ret->putAttribute("landunit_id", new vle::value::Integer( d.id)); output.push_back(ret); }); }
void aout(const std::string& /*name*/, const vmd::Activity& activity, vd::ExternalEventList& out) { if (activity.isInStartedState()) { out.emplace_back("out"); } }
void aout(const std::string& /*name*/, const vmd::Activity& activity, vd::ExternalEventList& out) { if (activity.isInStartedState()) { vd::ExternalEvent* evt = new vd::ExternalEvent("out"); out.push_back(evt); } }
void output(const vle::devs::Time& time, vle::devs::ExternalEventList& output) const { if (mPhase == SEND_ASSIGN) { for (ResourceConstraints::const_iterator it = mResourceConstraints->begin(); it != mResourceConstraints->end(); ++it) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("assign"); ee << vle::devs::attribute("type", it->type()); ee << vle::devs::attribute("quantity", (int)it->quantity()); output.push_back(ee); } } else if (mPhase == SEND_DEMAND) { for (ResourceConstraints::const_iterator it = mResourceConstraints->begin(); it != mResourceConstraints->end(); ++it) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("demand"); TraceModel( vle::fmt(" [%1%:%2%] at %3% -> demand: %4% = %5%") % getModel().getParentName() % getModelName() % time % it->type() % it->quantity()); ee << vle::devs::attribute("type", it->type()); ee << vle::devs::attribute("quantity", (int)it->quantity()); output.push_back(ee); } } else if (mPhase == SEND_RELEASE) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("release"); ee << vle::devs::attribute("resources", mReleasedResources->toValue()); output.push_back(ee); } else if (mPhase == SEND_UNAVAILABLE) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("unavailable"); ee << vle::devs::attribute("resources", mUnavailableResources.toValue()); output.push_back(ee); } }
virtual void output(const vle::devs::Time& /* time */, vle::devs::ExternalEventList& output) const { std::vector < std::string >::const_iterator it; for (it = mPortList.begin(); it != mPortList.end(); ++it) { output.push_back(buildEventWithAString("add", "name", *it)); } }
void out(const vd::Time& /* time */, vd::ExternalEventList& output) const { vd::ExternalEvent* ee = new vd::ExternalEvent("out"); ee << vd::attribute("name", std::string("a")); ee << vd::attribute("value", 2.); ee << vd::attribute("type", ve::DifferenceEquation::ADD); output.push_back(ee); }
void out(const vd::Time& time, vd::ExternalEventList& output) const { if(signal == "stop") { std::cout << std::setprecision(8) << time << " OS::out model:" << getModelName() << std::endl; vd::ExternalEvent* evt = new vd::ExternalEvent("act"); evt->putAttribute("name", new vv::String("Stade")); evt->putAttribute("value", new vv::Double(RECOLTE)); output.push_back(evt); } }
void output(const vle::devs::Time& time, vle::devs::ExternalEventList& output) const { if (mPhase == SEND_LOAD) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("load"); std::cout << time << " - [" << getModelName() << "] DECISION LOAD: " << mSelectedArrivedTransport->toString() << std::endl; ee << vle::devs::attribute( "type",mSelectedArrivedTransport->contentType()); ee << vle::devs::attribute("transport", mSelectedArrivedTransport->toValue()); output.addEvent(ee); } else if (mPhase == SEND_DEPART) { Transports::const_iterator it = mReadyTransports.begin(); std::cout << time << " - [" << getModelName() << "] DECISION DEPART: { "; while (it != mReadyTransports.end()) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent("depart"); std::cout << (*it)->id() << " "; ee << vle::devs::attribute("type", (*it)->contentType()); ee << vle::devs::attribute("id", (int)(*it)->id()); output.addEvent(ee); ++it; } std::cout << "}" << std::endl; } }
void externalTransition( const vle::devs::ExternalEventList& events, const vle::devs::Time& time) { vle::devs::ExternalEventList::const_iterator it = events.begin(); std::cout.precision(12); std::cout << time << " - [" << getModelName() << "] externalTransition: " << mPhase << std::endl; while (it != events.end()) { if ((*it)->onPort("transport")) { Transport* transport = new Transport( vle::value::toMapValue( (*it)->getAttributeValue("transport"))); std::cout << time << " - [" << getModelName() << "] DECISION TRANSPORT: " << transport->toString() << " => " << mPhase << std::endl; transport->arrived(time); mTransports.push_back(transport); } else if ((*it)->onPort("loaded")) { TransportID transportID = (*it)->getIntegerAttributeValue("id"); std::cout << time << " - [" << getModelName() << "] DECISION LOADED: transport -> " << transportID << std::endl; removeWaitingTransport(transportID); mPhase = SEND_DEPART; } ++it; } updateSigma(time); }
/** * @brief Handles external event and registers if necesserary * updates of external events (ExtUp), perturabations and discontinuities. * @param t, the current time * @param ext, the list of external event */ void handleExtEvt(const vd::Time& /*t*/, const vd::ExternalEventList& ext) { vd::ExternalEventList::const_iterator itb = ext.begin(); vd::ExternalEventList::const_iterator ite = ext.end(); for (; itb != ite; itb++) { //get port name const std::string& portName = itb->getPortName(); //find internal variable Variables::iterator itf = vars().find(portName); if (itf == vars().end()) { throw utils::InternalError(vle::utils::format( "[%s] Unrecognised variable '%s'", getModelName().c_str(), portName.c_str())); } if (itb->attributes()->isMap() and itb->attributes()->toMap().exist("value")) { itf->second->setVal( itb->attributes()->toMap().getDouble("value")); } else { itf->second->setVal(itb->attributes()->toDouble().value()); } } }
void output(const vle::devs::Time& /* time */, vle::devs::ExternalEventList& output) const { if (mPhase == SEND) { const Activities::result_t& activities = mActivities.startingActivities(); for(Activities::result_t::const_iterator it = activities.begin(); it != activities.end(); ++it) { vle::devs::ExternalEvent* ee = new vle::devs::ExternalEvent((*it)->location().name()); ee << vle::devs::attribute("location", (*it)->location().name()); ee << vle::devs::attribute("activity", (*it)->toValue()); output.push_back(ee); } } }
virtual void externalTransition(const vd::ExternalEventList& eventList, const vd::Time& time) { TraceAlways(vu::DateTime::simpleCurrentDate() + " - MMSExecute - externalTransition at time : " + time.toString()); //Update input port vd::ExternalEventList::const_iterator it = eventList.begin(); for (;it != eventList.end(); it++) { const vd::ExternalEvent& event = *(*it); if (event.onPort("time")) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Trying to update \"time\" port"); if(event.existAttributeValue("time")) { const vv::Value& val = event.getAttributeValue("time"); this->time = Long_fromValue(&val); if(val.isNull() == false) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Update \"time\" input port to \"" + val.writeToString() + "\" at time " + time.toString()); } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - NULL value for \"time\" input port at time " + time.toString()); } } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - Unknown attribute value \"time\" for the port \"time\""); } } if (event.onPort("timestep")) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Trying to update \"timestep\" port"); if(event.existAttributeValue("timestep")) { const vv::Value& val = event.getAttributeValue("timestep"); this->timestep = Long_fromValue(&val); if(val.isNull() == false) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Update \"timestep\" input port to \"" + val.writeToString() + "\" at time " + time.toString()); } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - NULL value for \"timestep\" input port at time " + time.toString()); } } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - Unknown attribute value \"timestep\" for the port \"timestep\""); } } if (event.onPort("cycle")) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Trying to update \"cycle\" port"); if(event.existAttributeValue("cycle")) { const vv::Value& val = event.getAttributeValue("cycle"); this->cycle = Long_fromValue(&val); if(val.isNull() == false) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Update \"cycle\" input port to \"" + val.writeToString() + "\" at time " + time.toString()); } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - NULL value for \"cycle\" input port at time " + time.toString()); } } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - Unknown attribute value \"cycle\" for the port \"cycle\""); } } if (event.onPort("NID")) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Trying to update \"NID\" port"); if(event.existAttributeValue("NID")) { const vv::Value& val = event.getAttributeValue("NID"); this->NID = Long_fromValue(&val); if(val.isNull() == false) { TraceModel(vu::DateTime::simpleCurrentDate() + " - Update \"NID\" input port to \"" + val.writeToString() + "\" at time " + time.toString()); } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - NULL value for \"NID\" input port at time " + time.toString()); } } else { TraceModel(vu::DateTime::simpleCurrentDate() + " - Unknown attribute value \"NID\" for the port \"NID\""); } } } }
void XRay::output(const vd::Time& /*time*/, vd::ExternalEventList& output) const { if (mPhase == SEND) { vd::RequestEvent * request = new vd::RequestEvent ("status?"); request << vd::attribute ("modelName", std::string (getModelName())); output.addEvent (request); } if ((mPhase == RECEIVE)and (getModel().existOutputPort("observations"))) { vd::ExternalEvent * ev = new vd::ExternalEvent ("observations"); ev << vd::attribute ("value", buildDouble(mPrevalence)); output.addEvent (ev); } if ((mPhase == RECEIVE)and (getModel().existOutputPort("control"))) { vd::ExternalEvent * ev = new vd::ExternalEvent ("control"); vv::Map* nodeObservations = vv::Map::create(); typedef std::map<std::string, std::string>::const_iterator mapit; for (mapit it = mapResult.begin(); it != mapResult.end(); it++) { if (it->second == "I") nodeObservations->addString(it->first, it->second); } ev << vd::attribute ("infectedNodes", nodeObservations); output.addEvent (ev); } if ((mPhase == RECEIVE)and (getModel().existOutputPort("info_center"))) { vd::ExternalEvent * ev = new vd::ExternalEvent ("info_center"); vv::Map* nodeObservations = vv::Map::create(); typedef std::map<std::string, std::string>::const_iterator mapit; for (mapit it = mapResult.begin(); it != mapResult.end(); it++) { nodeObservations->addString(it->first, it->second); } ev << vd::attribute ("nodesStates", nodeObservations); output.addEvent (ev); } if ((mPhase == RECEIVE or mPhase == INIT) and getModel().existOutputPort("connectTo")) { vd::ExternalEvent* connectionRequest = new vd::ExternalEvent("connectTo"); vv::Set linkTo; std::vector <int> sample; int i=0; while (sample.size()<mNbModel) { sample.push_back(i); i++; } for (int j = 0; j < sample.size(); j++) { int k = rand().getInt(0,sample.size()-1); int temp = sample[j]; sample[j]=sample[k]; sample[k]=temp; } while (sample.size()>mSampleSize) sample.pop_back(); for (std::vector<int>::iterator i = sample.begin(); i!=sample.end(); ++i) { std::string vetName = mPrefix + "-" + boost::lexical_cast<std::string>(*i); linkTo.addString(vetName); } connectionRequest << vd::attribute("modelName", std::string (getModelName())); connectionRequest << vd::attribute("linkTo", linkTo); output.addEvent(connectionRequest); } }
virtual void externalTransition(const vd::ExternalEventList &events, vd::Time time) override { double val, shifting_factor; int cnt; if (events.size() > 1) Trace(context(), 6, "Warning: %s got multiple events at date: %f\n", getModelName().c_str(), time); auto it = events.begin(); while (it != events.end()) { val = it->getMap().getDouble("d_val"); if (INIT == m_state) { init_step_number_and_offset(val); update_thresholds(); m_state = RESPONSE; } else { cnt = 0; if ((val > m_upthreshold) || (val < m_downthreshold)) Trace(context(), 6, "%s: treating out of bonds val: %f " "(quantizer interval : [%f,%f] at date: %f", getModelName().c_str(), val, m_downthreshold, m_upthreshold, time); while ((val >= m_upthreshold) || (val <= m_downthreshold)) { cnt++; if (val >= m_upthreshold) { m_step_number++; } else { m_step_number--; } switch (m_adapt_state) { case IMPOSSIBLE: update_thresholds(); break; case POSSIBLE: if (val >= m_upthreshold) { store_change(m_step_size, time); } else { store_change(-m_step_size, time); } shifting_factor = shift_quanta(); if (0 > shifting_factor) throw vu::ModellingError( "Bad shifting value (value : %f, " "should be strictly positive)\n", shifting_factor); if (1 < shifting_factor) throw vu::ModellingError( "Bad shifting value ( value : %f, " "should be less than 1)\n", shifting_factor);; if ((0 != shifting_factor) && (1 != shifting_factor)) { if (val >= m_upthreshold) { update_thresholds(shifting_factor, DOWN); } else { update_thresholds(shifting_factor, UP); } Trace(context(), 6, "Quantifier %s new quantas while treating new val %f at date %f", getModelName().c_str(), val, time); Trace(context(), 6, "Quantizer interval: [%f, %f], amplitude: %f " "(default amplitude: %f)", m_downthreshold, m_upthreshold, (m_upthreshold - m_downthreshold), (2 * m_step_size)); Trace(context(), 6, "Quantifier %s shifting : %f", getModelName().c_str(), shifting_factor); m_adapt_state = DONE; } else { update_thresholds(); } break; case DONE: // equiv to reinit init_step_number_and_offset(val); // archive.resize(0); m_adapt_state = POSSIBLE; update_thresholds(); break; } } if (cnt > 1) Trace(context(), 6, "Warning : in %s multiple quanta change" " at date : %f %d\n", getModelName().c_str(), time, cnt); if (0 == cnt) Trace(context(), 6, "Warning : in %s useless ext transition" "call: no quanta change! input val %f (quantizer " "interval : [%f,%f] at date %f\n", getModelName().c_str(), val, m_downthreshold, m_upthreshold, time); } ++it; } m_state = RESPONSE; }
void out2(const vle::devs::Time& /*time*/ , vle::devs::ExternalEventList& output) const { output.emplace_back("c"); output.back().addDouble(0); }
void output(vle::devs::Time /*time*/, vle::devs::ExternalEventList& output) const override { output.emplace_back("a"); output.back().addDouble(a+3); }