Virtual Belgium  2.0
A micro-simulation platform for the Belgian population
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Model.hpp
Go to the documentation of this file.
1 /****************************************************************
2  * MODEL.HPP
3  *
4  * This file contains all the VirtualBelgium's model and
5  * scheduler related classes and functions.
6  *
7  * Authors: J. Barthelemy and L. Hollaert
8  * Date : 17 july 2012
9  ****************************************************************/
10 
15 #ifndef MODEL_HPP_
16 #define MODEL_HPP_
17 
18 #include "Individual.hpp"
19 #include "Household.hpp"
20 #include "Data.hpp"
21 #include "tinyxml2.hpp"
22 
23 #include "repast_hpc/SharedContext.h"
24 #include "repast_hpc/Schedule.h"
25 #include "repast_hpc/Random.h"
26 #include "repast_hpc/Properties.h"
27 #include "repast_hpc/Utilities.h"
28 #include "repast_hpc/io.h"
29 #include "repast_hpc/logger.h"
30 #include "repast_hpc/initialize_random.h"
31 #include "repast_hpc/SVDataSetBuilder.h"
32 
33 #include <sstream>
34 #include <cstdlib>
35 #include <algorithm>
36 #include <stdexcept>
37 #include <math.h>
38 #include <vector>
39 #include <iomanip>
40 #include <boost/serialization/access.hpp>
41 #include <boost/lexical_cast.hpp>
42 #include <boost/mpi.hpp>
43 #include <boost/mpi/collectives.hpp>
44 #include <boost/mpi/communicator.hpp>
45 #include <boost/unordered_set.hpp>
46 
47 
49 
53 class Model {
54 
55  private :
56 
57  friend class ProviderReceiver;
58 
59  int _proc;
60  repast::Properties _props;
61  repast::SVDataSet* _data_out;
62 
69 
81 
93 
94  unsigned int _n_activity_start_time_x_ins[589][24];
95  unsigned int _n_activity_end_time_x_ins[589][24];
96  unsigned int _origin_destination_matrix[589][589];
97  unsigned int _origin_destination_matrix_mp[589][589];
98  unsigned int _origin_destination_matrix_ep[589][589];
99 
100  int _babyId;
101 
102  public :
103 
104  repast::SharedContext<Individual> agents;
105  repast::SharedContext<Household> agentsHh;
106 
108  /*
109  /param comm the mpi communicator
110  /param props the model properties
111  */
112  Model( boost::mpi::communicator* comm, repast::Properties & props );
113 
115  ~Model();
116 
118  void initSchedule();
119 
121  void step();
122 
124  void computeActivityChains();
125 
128 
130  void resetAggregateOutputs();
131 
133  void writeIndividuals();
134 
136  void writeActivityChains();
137 
140 
142  void saveODMatrix();
143 
145 
149  void providePackage(Individual * agent , std::vector<IndividualPackage> &out);
150 
152 
156  void providePackage(Household * agent, std::vector<HouseholdPackage> &out);
157 
159 
165 
167 
173 
175 
179  void provideContent(repast::AgentRequest req, std::vector<IndividualPackage>& out);
180 
182 
186  void provideContent(repast::AgentRequest req, std::vector<HouseholdPackage>& out);
187 
189 
192  void updateAgent(IndividualPackage package);
193 
195 
198  void updateAgent(HouseholdPackage package);
199 
200 };
201 
202 #endif /* MODEL_HPP_ */
AggregateSum * _age10MSum
aggregated number of men in age class 10
Definition: Model.hpp:80
AggregateSum * _babyGirlSum
aggregated number of death
Definition: Model.hpp:66
The package structure for Individual agents.
Definition: Individual.hpp:48
AggregateSum * _age3WSum
aggregated number of women in age class 3
Definition: Model.hpp:85
Individual agents related classes and methods declarations.
Model(boost::mpi::communicator *comm, repast::Properties &props)
Constructor.
Definition: Model.cpp:17
AggregateSum * _age7WSum
aggregated number of women in age class 7
Definition: Model.hpp:89
int _babyId
Id initialized for the babies.
Definition: Model.hpp:100
AggregateSum * _babyBoySum
aggregated number of death
Definition: Model.hpp:65
~Model()
Destructor.
Definition: Model.cpp:314
void providePackage(Individual *agent, std::vector< IndividualPackage > &out)
Used by Repast HPC to exchange Individual agents between process.
Definition: Model.cpp:339
unsigned int _origin_destination_matrix_mp[589][589]
Origin-Destination matrix between municipalities (morning peak: 7:00 - 9:00)
Definition: Model.hpp:97
unsigned int _origin_destination_matrix[589][589]
Origin-Destination matrix between municipalities.
Definition: Model.hpp:96
AggregateSum * _age6MSum
aggregated number of men in age class 6
Definition: Model.hpp:76
repast::Properties _props
properties of the model
Definition: Model.hpp:60
AggregateSum * _age8MSum
aggregated number of men in age class 8
Definition: Model.hpp:78
void updateAgent(IndividualPackage package)
Used by Repast HPC to update a local copy of an Individual agent with the data of the actual agent...
Definition: Model.cpp:396
void step()
Implements one step of the simulation.
Definition: Model.cpp:431
AggregateSum * _age1WSum
aggregated number of women in age class 1
Definition: Model.hpp:83
void computeActivityChains()
Generates the travel demand forecasting via activity chains model.
Definition: Model.cpp:470
AggregateSum * _age5MSum
aggregated number of men in age class 5
Definition: Model.hpp:75
void saveActivityLocalizationAndTime()
Save activities localization and when they are performed.
Definition: Model.cpp:940
AggregateSum * _age3MSum
aggregated number of men in age class 3
Definition: Model.hpp:73
void writeIndividuals()
Save the agents state of the current process' Individual shared context in a file.
Definition: Model.cpp:790
unsigned int _n_activity_end_time_x_ins[589][24]
Number of ending activities performed / time of the day by municipality (also trip start) ...
Definition: Model.hpp:95
Data related class and methods.
AggregateSum * _age6WSum
aggregated number of women in age class 6
Definition: Model.hpp:88
The package structure for Household agents.
Definition: Household.hpp:50
void resetAggregateOutputs()
Reset every aggregate data set to 0.
Definition: Model.cpp:761
AggregateSum * _deathWomenSum
aggregated number of death (women)
Definition: Model.hpp:64
AggregateSum * _age1MSum
aggregated number of men in age class 1
Definition: Model.hpp:71
friend class ProviderReceiver
Definition: Model.hpp:57
AggregateSum * _age4MSum
aggregated number of men in age class 4
Definition: Model.hpp:74
void initSchedule()
Initialisation of the simulation's schedule.
Definition: Model.cpp:317
void computePopulationEvolution()
Computes the socio-demographic evolution of the population.
Definition: Model.cpp:585
AggregateSum * _girlSum
aggregated number of women
Definition: Model.hpp:68
Main VirtualBelgium class.
Definition: Model.hpp:53
repast::SVDataSet * _data_out
aggregated output data set
Definition: Model.hpp:61
unsigned int _origin_destination_matrix_ep[589][589]
Origin-Destination matrix between municipalities (evening peak: 15:00 - 19:00)
Definition: Model.hpp:98
void provideContent(repast::AgentRequest req, std::vector< IndividualPackage > &out)
Used by Repast HPC exchange Individuals agents between processes.
Definition: Model.cpp:378
AggregateSum * _deathMenSum
aggregated number of death (men)
Definition: Model.hpp:63
void saveODMatrix()
Save origin-destination matrices for several time slots.
Definition: Model.cpp:1061
AggregateSum * _age9MSum
aggregated number of men in age class 9
Definition: Model.hpp:79
AggregateSum * _age4WSum
aggregated number of women in age class 4
Definition: Model.hpp:86
AggregateSum * _age0WSum
aggregated number of women in age class 0
Definition: Model.hpp:82
AggregateSum * _age2WSum
aggregated number of women in age class 2
Definition: Model.hpp:84
repast::SharedContext< Household > agentsHh
Shared context containing the household agents of the simulation.
Definition: Model.hpp:105
Individual * createAgent(IndividualPackage package)
Used by Repast HPC to create an Individual Agent from an IndividualPackage.
Definition: Model.cpp:362
AggregateSum * _age10WSum
aggregated number of women in age class 10
Definition: Model.hpp:92
AggregateSum * _age2MSum
aggregated number of men in age class 2
Definition: Model.hpp:72
Aggregate output data class.
Definition: Data.hpp:344
Household agents related classes and methods declarations.
unsigned int _n_activity_start_time_x_ins[589][24]
Number of starting activities time of the day by municipality.
Definition: Model.hpp:94
AggregateSum * _age0MSum
aggregated number of men in age class 0
Definition: Model.hpp:70
AggregateSum * _age8WSum
aggregated number of women in age class 8
Definition: Model.hpp:90
The individual agent class.
Definition: Individual.hpp:122
AggregateSum * _age7MSum
aggregated number of men in age class 7
Definition: Model.hpp:77
AggregateSum * _age5WSum
aggregated number of women in age class 5
Definition: Model.hpp:87
int _proc
rank of the model's process
Definition: Model.hpp:59
The household agent class.
Definition: Household.hpp:110
AggregateSum * _age9WSum
aggregated number of women in age class 9
Definition: Model.hpp:91
void writeActivityChains()
Write the Individual agents plans to an XML file that can be processed with MATSim.
Definition: Model.cpp:835
repast::SharedContext< Individual > agents
Shared context containing the individual agents of the simulation.
Definition: Model.hpp:104
AggregateSum * _menSum
aggregated number of men
Definition: Model.hpp:67