Simulation.h 5.1 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
#include "routing/global_shortest/GlobalRouter.h"
44
#include "routing/global_shortest_trips/GlobalRouterTrips.h"
45
#include "routing/quickest/QuickestPathRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
46
#include "routing/DirectionStrategy.h"
47
#include "routing/RoutingEngine.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
48
#include "pedestrian/PedDistributor.h"
49
#include "routing/smoke_router/SmokeRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
50
#include "events/EventManager.h"
51
#include "pedestrian/AgentsSourcesManager.h"
GrgrLmml's avatar
GrgrLmml committed
52
#include "general/Configuration.h"
53

Ulrich Kemloh's avatar
Ulrich Kemloh committed
54
//Forward declarations
55 56
//class AgentsSourcesManager;
class EventManager;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
57

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

Mohcine Chraibi's avatar
Mohcine Chraibi committed
91
    bool _gotSources; // is true if we got some sources. Otherwise, false.
92
    // bool _printPB; // print progressbar
93
public:
94 95 96
    /**
     * Constructor
     */
Arne Graf's avatar
Arne Graf committed
97
    Simulation(Configuration* args);
98 99 100 101

    /**
     * Destructor
     */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
102
    virtual ~Simulation();
103 104 105 106

    /**
     * Initialize the number of agents in the simulation
     */
Oliver Schmidts's avatar
Oliver Schmidts committed
107
    long GetPedsNumber() const;
108 109

    /**
GrgrLmml's avatar
GrgrLmml committed
110
     * Read parameters from config.
111
     */
GrgrLmml's avatar
GrgrLmml committed
112
    bool InitArgs();
113 114

    /**
115
     * Update the route of the pedestrians and reassign rooms, in the case a room change happens
116
     */
117 118
    void UpdateRoutesAndLocations();

119 120 121 122 123 124 125 126 127 128 129 130 131 132
    /**
     * 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();

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

    /**
141
     * Run the main part of the simulation
142
     */
143
    double RunBody(double maxSimTime);
144

145
    /**
146 147 148 149 150 151 152 153
     * Perform some finalization like writing the
     * footers for the trajectories.
     */
    void RunFooter();

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

157 158 159 160
    /**
     * print some statistics about the simulation
     */
    void PrintStatistics();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
161

162 163 164
    /**
     * @return the agents source manager
     */
165
    AgentsSourcesManager& GetAgentSrcManager();
166 167 168 169 170 171

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

Ulrich Kemloh's avatar
Ulrich Kemloh committed
172 173 174 175
    /**
     * @return a pointer to the building object
     */
    Building* GetBuilding();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
176 177 178 179 180

    /**
     * Update the flow for the door that the pedestrian just crossed
     * @param ped
     */
GrgrLmml's avatar
GrgrLmml committed
181
    void UpdateFlowAtDoors(const Pedestrian& ped) const;
182 183 184 185 186 187

     /**
     * Update the refresh ticks for all doors. they count up and measure the age of the tickvalue (ffRouter, quickest)
     *
     */
     void UpdateDoorticks() const;
188 189
     int GetMaxSimTime() const;

190

Ulrich Kemloh's avatar
Ulrich Kemloh committed
191 192 193
};

#endif /*SIMULATION_H_*/