Stride Reference Manual  1.0
Coordinator.cpp
Go to the documentation of this file.
1 #include "Coordinator.h"
2 #include "util/async.h"
4 #include "calendar/Calendar.h"
5 #include "sim/SimulatorStatus.h"
6 
7 #include <vector>
8 #include <iostream>
9 
10 using namespace stride;
11 using namespace util;
12 using namespace std;
13 
14 vector<SimulatorStatus> Coordinator::timeStep() {
15  vector<future<SimulatorStatus>> fut_results;
16 
17  // Run the simulator for the day
18  for (auto& it: m_sims) {
19  fut_results.push_back(it.second->timeStep());
20  }
21  auto results = future_pool(fut_results);
22 
23 
24  for (auto& it: m_sims) {
25  it.second->returnForeignTravellers();
26  }
27 
28  int weekday = m_calendar.getDayOfTheWeek();
29 
30  for (uint i = 0; i < m_traveller_schedule.at(weekday).size(); ++i) {
31  Flight& new_flight = m_traveller_schedule[weekday].at(i);
32  try {
33  m_sims.at(new_flight.m_source_sim)->sendNewTravellers(new_flight.m_amount,
34  new_flight.m_duration,
35  m_sims.at(new_flight.m_destination_sim)->getName(),
36  new_flight.m_district,
37  new_flight.m_facility);
38  } catch (...) {
39  // Map out of bounds / wrong schedule results in an exception which is caught and ignored here
40  cerr << "\nWarning: travelling from " << new_flight.m_source_sim << " to " << new_flight.m_destination_sim
41  << " failed because one of them doesn't exist.\n";
42  }
43  }
44 
45  m_calendar.advanceDay();
46  return results;
47 }
vector< T > future_pool(vector< future< T >> &futures)
Definition: async.h:52
unsigned int uint
Definition: Influence.h:17
string m_district
The current day of the week (0 (Sunday), ..., 6 (Saturday))
Header file for the Calendar class.
Time Dependent Person DataType.
Definition: NoBehaviour.h:17
STL namespace.
vector< SimulatorStatus > timeStep()
Definition: Coordinator.cpp:14