Exemplo n.º 1
0
	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());
			}
		} 
	}
Exemplo n.º 2
0
    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;

        }
    }
Exemplo n.º 3
0
  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);
      }
  }