Simulation.h 5.45 KB
Newer Older
1
/**
Ulrich Kemloh's avatar
Ulrich Kemloh committed
2 3
 * \file        Simulation.h
 * \date        Dec 15, 2010
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum J?lich GmbH. All rights reserved.
6
 *
Ulrich Kemloh's avatar
Ulrich Kemloh committed
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
Ulrich Kemloh's avatar
Ulrich Kemloh committed
23
 * \section Description
24 25 26 27
 * The Simulation class represents a simulation of pedestrians
 * based on a certain model in a specific scenario. A simulation is defined by
 * various parameters and functions.
 *
Ulrich Kemloh's avatar
Ulrich Kemloh committed
28 29 30 31
 *
 **/


Ulrich Kemloh's avatar
Ulrich Kemloh committed
32 33 34 35 36 37

#ifndef SIMULATION_H_
#define SIMULATION_H_

#include "general/ArgumentParser.h"
#include "geometry/Building.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
38
#include "geometry/SubRoom.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
39 40
#include "IO/OutputHandler.h"
#include "IO/IODispatcher.h"
41
#include "math/OperationalModel.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
42
#include "math/ODESolver.h"
43 44
#include "routing/global_shortest/GlobalRouter.h"
#include "routing/quickest/QuickestPathRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
45
#include "routing/DirectionStrategy.h"
46
#include "routing/RoutingEngine.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
47
#include "pedestrian/PedDistributor.h"
48
#include "routing/smoke_router/SmokeRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
49
#include "events/EventManager.h"
50
#include "pedestrian/AgentsSourcesManager.h"
GrgrLmml's avatar
GrgrLmml committed
51
#include "general/Configuration.h"
52 53 54
#include <filesystem>


55

Ulrich Kemloh's avatar
Ulrich Kemloh committed
56
//Forward declarations
57 58
//class AgentsSourcesManager;
class EventManager;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
59

GrgrLmml's avatar
GrgrLmml committed
60
class Simulation {
61
private:
GrgrLmml's avatar
GrgrLmml committed
62
    ///Number of pedestrians in the simulation
63
    long _nPeds;
64
    ///Maximum simulation time
65
    //double _tmax;
66 67 68 69
    /// time step
    double _deltaT;
    /// frame rate for the trajectories
    double _fps;
70 71
    ///seed using for the random number generator
    unsigned int _seed;
72
    /// building object
73
    std::shared_ptr<Building> _building;
74
    /// Force model to use
75
    std::shared_ptr<OperationalModel> _operationalModel;
76
    /// Manage all route choices algorithms
Oliver Schmidts's avatar
Oliver Schmidts committed
77
    std::shared_ptr<RoutingEngine> _routingEngine;
78
    /// differential equation solver
79 80 81
    ODESolver* _solver;
    /// writing the trajectories to file
    IODispatcher* _iod;
82
    /// EventManager
83
    EventManager* _em;
GrgrLmml's avatar
GrgrLmml committed
84
    /// config
Arne Graf's avatar
Arne Graf committed
85
    Configuration* _config;
86 87
    /// Agents sources manager
    AgentsSourcesManager _agentSrcManager;
88 89
    /// hybrid simulation manager
    //HybridSimulationManager
Mohcine Chraibi's avatar
Mohcine Chraibi committed
90
    int _periodic;
91 92
     int _maxSimTime;

Mohcine Chraibi's avatar
Mohcine Chraibi committed
93
    bool _gotSources; // is true if we got some sources. Otherwise, false.
94 95
     bool _trainConstraints; // true if inifile has some train constraints

96
    // bool _printPB; // print progressbar
97
public:
98 99 100
    /**
     * Constructor
     */
Arne Graf's avatar
Arne Graf committed
101
    Simulation(Configuration* args);
102 103 104 105

    /**
     * Destructor
     */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
106
    virtual ~Simulation();
107 108 109 110

    /**
     * Initialize the number of agents in the simulation
     */
Oliver Schmidts's avatar
Oliver Schmidts committed
111
    long GetPedsNumber() const;
112 113

    /**
GrgrLmml's avatar
GrgrLmml committed
114
     * Read parameters from config.
115
     */
GrgrLmml's avatar
GrgrLmml committed
116
    bool InitArgs();
117 118

    /**
119
     * Update the route of the pedestrians and reassign rooms, in the case a room change happens
120
     */
121 122
    void UpdateRoutesAndLocations();

123 124 125 126 127 128 129 130 131 132 133 134 135 136
    /**
     * Update the routes (intermediate destinations) of the pedestrians.
     * Based on the route choice algorithm used, the next doors or the next decision points is set.
     * TODO:
     */
    void UpdateRoutes();

    /**
     * Update the location of the agents and remove the agents from the simulation who have left the building.
     * Locations includes room/subrooms.
     * TODO:
     */
    void UpdateLocations();

137
    /**
138 139 140
     * Perform some initialisation for the simulation.
     * such as writing the headers for the trajectories.
     * @param the maximal number of pedestrian
141
     */
GrgrLmml's avatar
GrgrLmml committed
142
    void RunHeader(long nPed = -1);
143 144

    /**
145
     * Run the main part of the simulation
146
     */
147
    double RunBody(double maxSimTime);
148

149
    /**
150 151 152 153 154 155 156 157
     * Perform some finalization like writing the
     * footers for the trajectories.
     */
    void RunFooter();

    /**
     * Run a standard simulation
     * @return the total simulated/evacuation time
158
     */
159
    double RunStandardSimulation(double maxSimTime);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
160

161 162 163
    /**
     * print some statistics about the simulation
     */
Mohcine Chraibi's avatar
Mohcine Chraibi committed
164
    void PrintStatistics(double time);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
165

166 167 168
    /**
     * @return the agents source manager
     */
169
    AgentsSourcesManager& GetAgentSrcManager();
170 171 172 173 174 175

    /**
     * Check if any agents are waiting to enter the simulation
     */
    void ProcessAgentsQueue();

Ulrich Kemloh's avatar
Ulrich Kemloh committed
176 177 178 179
    /**
     * @return a pointer to the building object
     */
    Building* GetBuilding();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
180 181 182 183 184

    /**
     * Update the flow for the door that the pedestrian just crossed
     * @param ped
     */
GrgrLmml's avatar
GrgrLmml committed
185
    void UpdateFlowAtDoors(const Pedestrian& ped) const;
186 187 188 189 190 191

     /**
     * Update the refresh ticks for all doors. they count up and measure the age of the tickvalue (ffRouter, quickest)
     *
     */
     void UpdateDoorticks() const;
192
     int GetMaxSimTime() const;
193 194 195 196 197
     void  incrementCountTraj();

     bool correctGeometry(std::shared_ptr<Building> building,  std::shared_ptr<TrainTimeTable>);
     bool WriteTrajectories(std::string trajName);
     bool TrainTraffic();
198

199 200
     int _countTraj=0; // count number of TXT trajectories to produce
     double _maxFileSize; // in MB
Ulrich Kemloh's avatar
Ulrich Kemloh committed
201 202 203
};

#endif /*SIMULATION_H_*/