vv::Value* XRay::observation( const vd::ObservationEvent& event) const { if (event.onPort("xrayview")){ vv::Map* tmpResult = new vv::Map(); std::map<std::string, std::string>::const_iterator it; for ( it = mapResult.begin(); it != mapResult.end(); ++it ) { tmpResult->addString(it->first, it->second); } return tmpResult; } if (event.onPort("prevalence")){ //std::cout<<"Prev is "<<mPrevalence<<"\n"; return buildDouble(mPrevalence); } if (event.onPort("incidence")){ //std::cout<<"incidence is "<<mIncidence<<"\n"; return buildDouble(mIncidence); } else return 0; }
int main() { Lnode *head=NULL; Lnode *listHead=NULL; int totalNum= 10; int index =0; int value=0; buildTree(&head); traverse(head); printf("\n"); listHead = buildDouble(head); traverseList(listHead); printf("\n"); return 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); } }