void Simulator::startSimulation(){
  setReportsFilePath("Reports.ini");
  updateConf("Configuration.ini");
  updateRoadMap("RoadMap.ini");
  updateEvents("Events.ini");
  updateReports("Commands.ini");

  // Starting the cycle
  bool isCycleRunning = true;
  while(isCycleRunning){
    
    // Perform Events
    std::pair <std::multimap<int,Event*>::iterator, std::multimap<int,Event*>::iterator> event_it;
    event_it = _events.equal_range(getCurrentTime());
    for (std::multimap<int,Event*>::iterator it=event_it.first; it!=event_it.second; ++it)
      (it->second)->performEvent();
      
    updateCarsHistory();
  
    // Execute Commands
    std::pair <std::multimap<int,Report*>::iterator, std::multimap<int,Report*>::iterator> report_it;
    report_it = _reports.equal_range(getCurrentTime());
    for (std::multimap<int,Report*>::iterator it=report_it.first; it!=report_it.second && isCycleRunning; ++it){
      if((it->second)->getReportType() == "termination")
	  isCycleRunning = false;
      else
	(it->second)->writeReport();
    }
  
    advanceCarsInRoads();
    advanceCarsInJunctions();

    increaseTime();
  }
}
Beispiel #2
0
void Detector::handleMessage(cMessage *msg) {
    if (msg->arrivedOn("clock")) {
        // Schedule evaluation just a bit later, so that we have all sketches
        scheduleAt(
                simTime() + simtime_t(getParentModule()->par("interval")) * .8,
                msg);
    } else if (msg->isSelfMessage()) {
        evaluateCores();
        delete msg;
        clearReports();
    } else if (msg->arrivedOn("graphServerIn")) {
        updateCores(check_and_cast<CoresUpdate*>(msg));
    } else if (msg->arrivedOn("reportsIn")) {
        updateReports(check_and_cast<Report*>(msg));
    } else {
        delete msg;
    }
}