本文整理汇总了C++中vle::devs::ExternalEventList::end方法的典型用法代码示例。如果您正苦于以下问题:C++ ExternalEventList::end方法的具体用法?C++ ExternalEventList::end怎么用?C++ ExternalEventList::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vle::devs::ExternalEventList
的用法示例。
在下文中一共展示了ExternalEventList::end方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: externalTransition
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;
}
}
示例2: externalTransition
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;
}
}
示例3: externalTransition
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;
}
}
示例4: handleExtEvt
/**
* @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());
}
}
}
示例5: externalTransition
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);
}
示例6: externalTransition
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\"");
}
}
}
//.........这里部分代码省略.........
示例7: externalTransition
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;
//.........这里部分代码省略.........