Esempio n. 1
0
    virtual void output(
        const devs::Time& /* time */,
        devs::ExternalEventList& output ) const
    {
        if (m_phase == CONTROL) {
            typedef std::vector<std::string>::const_iterator NodeIterator;
    
            vv::Map* nodeObservations = vv::Map::create();
            for (NodeIterator it = m_interventions.begin()->second.begin(); 
                 it !=  m_interventions.begin()->second.end(); it++) {
                nodeObservations->addString(*it, "R");
                vd::ExternalEvent * ev = new vd::ExternalEvent (*it);
                ev << vd::attribute ("type", buildString("clean"));
                output.addEvent (ev);
            }
            if (getModel().existOutputPort("info_center")) {
                vd::ExternalEvent * evInfo = new vd::ExternalEvent ("info_center");
                evInfo << vd::attribute("nodesStates", nodeObservations);
                output.addEvent(evInfo);
            } else {
                delete nodeObservations;
            }
        }

    }
Esempio n. 2
0
void Moore::externalTransition(const devs::ExternalEventList& events,
			       devs::Time /* time */)
{
    // mNewStates.clear();
    if (events.size() > 1) {
        devs::ExternalEventList sortedEvents = select(events);
        devs::ExternalEventList* clonedEvents =
            new devs::ExternalEventList;
        devs::ExternalEventList::const_iterator it = sortedEvents.begin();

        while (it != sortedEvents.end()) {
            clonedEvents->emplace_back(it->getPortName());
            devs::ExternalEvent& e = clonedEvents->back();
            copyExternalEventAttrs(*it, e);
            ++it;
        }
        mToProcessEvents.push_back(clonedEvents);
    } else {
        devs::ExternalEventList::const_iterator it = events.begin();
        devs::ExternalEventList* clonedEvents =
            new devs::ExternalEventList;
        clonedEvents->emplace_back(it->getPortName());
        devs::ExternalEvent& e = clonedEvents->back();
        copyExternalEventAttrs(*it, e);
        mToProcessEvents.push_back(clonedEvents);
    }
    mPhase = PROCESSING;
}
Esempio n. 3
0
 virtual void externalTransition(
     const devs::ExternalEventList&  event ,
     const devs::Time& time)
 {
     for (vd::ExternalEventList::const_iterator it = event.begin();
          it != event.end(); ++it) {
         if ((*it)->onPort("surveillance")) {
             Intervention newIntervention;
             value::Map infNodes = (*it)->getMapAttributeValue("infectedNodes");
             for (vv::MapValue::const_iterator node = infNodes.begin();
                  node != infNodes.end(); node++) {
                 m_nodeStates[node->first] = node->second->toString().value();
                 newIntervention.second.push_back(node->first);
             }
             newIntervention.first = time.getValue() + m_delay;
             m_interventions.push_back(newIntervention);
             if (m_phase == IDLE)
                 m_phase = CONTROL;
             /*
             else {
                 vle::utils::InternalError error(
                     "\nControler must recieve only one surveillance repport in this version\n");
                 throw error;
                 }
             */
         }
     }
     m_current_time = time.getValue();
 }
Esempio n. 4
0
 virtual void output(const devs::Time& /* time */,
                     devs::ExternalEventList& output) const
 {
     if (mActive) {
         output.push_back(buildEvent("yes"));
     } else {
         output.push_back(buildEvent("no"));
     }
 }
Esempio n. 5
0
 virtual void output(devs::Time /*time*/,
                     devs::ExternalEventList &output) const override
 {
     Ensures(i == 1);
     i++;
     output.emplace_back("out");
 }
Esempio n. 6
0
 virtual void output(const devs::Time& /* time */,
                     devs::ExternalEventList& output) const
 {
     for (int i = 0; i < m_counter; ++i) {
         output.push_back(buildEvent("out"));
     }
 }
Esempio n. 7
0
void Agent::externalTransition(
    const devs::ExternalEventList& events,
    const devs::Time& time)
{
    mCurrentTime = time;

    for (devs::ExternalEventList::const_iterator it = events.begin();
            it != events.end(); ++it) {
        const std::string& port((*it)->getPortName());
        const value::Map& atts = (*it)->getAttributes();

        if (port == "ack") {
            const std::string& activity(atts.getString("name"));
            const std::string& order(atts.getString("value"));

            if (order == "done") {
                setActivityDone(activity, time);
            } else if (order == "fail") {
                setActivityFailed(activity, time);
            } else {
                throw utils::ModellingError(
                    fmt(_("Decision: unknown order `%1%'")) % order);
            }
        } else {
            value::Map::const_iterator jt = atts.value().find("value");
            if (jt == atts.end()) {
                jt = atts.value().find("init");
            }

            if (jt == atts.end() or not jt->second) {
                throw utils::ModellingError(
                    fmt(_("Decision: no value in this message: `%1%'")) %
                    (*it));
            }

            if (mPortMode) {
                applyFact(port, *jt->second);
            } else {
                const std::string& fact((*it)->getStringAttributeValue("name"));
                applyFact(fact, *jt->second);
            }
        }
    }

    mState = UpdateFact;
}
Esempio n. 8
0
void Moore::output(devs::Time time,
		   devs::ExternalEventList& output) const
{
    if (mPhase == PROCESSING) {
        OutputFuncsIterator it = mOutputFuncs.find(currentState());

        if (it != mOutputFuncs.end()) {
            (it->second)(time, output);
        } else {
            OutputsIterator ito = mOutputs.find(currentState());

            if (ito != mOutputs.end()) {
                output.emplace_back(ito->second);
            }
        }
    }
}
Esempio n. 9
0
void Mealy::output(devs::Time time,
		   devs::ExternalEventList& output) const
{
    if (mPhase == PROCESSING) {
        const devs::ExternalEventList& events = *mToProcessEvents.front();
        const devs::ExternalEvent& event = events.front();
        OutputFuncsIterator itof = mOutputFuncs.find(currentState());

        if (itof != mOutputFuncs.end()  and
            itof->second.find(event.getPortName()) != itof->second.end()) {
            (itof->second.find(event.getPortName())->second)(time, output);
        } else {
            OutputsIterator ito = mOutputs.find(currentState());

            if (ito != mOutputs.end() and
                ito->second.find(event.getPortName()) != ito->second.end()) {
                output.emplace_back(
                    ito->second.find(event.getPortName())->second);
            }
        }
    }
}
Esempio n. 10
0
 virtual void output(devs::Time /*time*/,
                     devs::ExternalEventList &output) const override
 {
     output.emplace_back("out");
     output.back().addString("leaf");
 }
Esempio n. 11
0
 virtual void output(devs::Time /* time */,
                     devs::ExternalEventList &output) const override
 {
     for (int i = 0; i < m_counter; ++i)
         output.emplace_back("out");
 }
Esempio n. 12
0
 virtual void externalTransition(const devs::ExternalEventList &events,
                                 devs::Time /* time */) override
 {
     m_counter = m_counter + events.size();
 }
Esempio n. 13
0
 virtual void externalTransition(const devs::ExternalEventList& evts,
                                 devs::Time time) override
 {
     mDate = time;
     mNumber += evts.size();
 }
Esempio n. 14
0
void GeneratorWrapper::output(const devs::Time& /* time */,
                              devs::ExternalEventList& output) const
{
    output.push_back(new devs::ExternalEvent("out"));
}
Esempio n. 15
0
 virtual void output(const devs::Time& /* time */,
                     devs::ExternalEventList& output) const
 { output.push_back(new devs::ExternalEvent("out")); }
Esempio n. 16
0
 void externalTransition(const devs::ExternalEventList& event,
                                 devs::Time time) override
 {
     last_wake_up_time = time;
     a = event.begin()->attributes()->toDouble().value();
 }