Simulation.h 4.98 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

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

GrgrLmml's avatar
GrgrLmml committed
57
class Simulation {
58
private:
GrgrLmml's avatar
GrgrLmml committed
59
    ///Number of pedestrians in the simulation
60
    long _nPeds;
61
    ///Maximum simulation time
62
    //double _tmax;
63 64 65 66
    /// time step
    double _deltaT;
    /// frame rate for the trajectories
    double _fps;
67 68
    ///seed using for the random number generator
    unsigned int _seed;
69
    /// building object
70
    std::shared_ptr<Building> _building;
71
    /// Force model to use
72
    std::shared_ptr<OperationalModel> _operationalModel;
73
    /// Manage all route choices algorithms
74
    std::shared_ptr<RoutingEngine> _routingEngine;
75
    /// differential equation solver
76 77 78
    ODESolver* _solver;
    /// writing the trajectories to file
    IODispatcher* _iod;
79
    /// EventManager
80
    EventManager* _em;
GrgrLmml's avatar
GrgrLmml committed
81
    /// config
Arne Graf's avatar
Arne Graf committed
82
    Configuration* _config;
83 84
    /// Agents sources manager
    AgentsSourcesManager _agentSrcManager;
85 86
    /// hybrid simulation manager
    //HybridSimulationManager
Mohcine Chraibi's avatar
Mohcine Chraibi committed
87
    int _periodic;
88
    bool _gotSources; // is true if we got some sources. Otherwise, false.
89
    // bool _printPB; // print progressbar
90
public:
91 92 93
    /**
     * Constructor
     */
Arne Graf's avatar
Arne Graf committed
94
    Simulation(Configuration* args);
95 96 97 98

    /**
     * Destructor
     */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
99
    virtual ~Simulation();
100 101 102 103

    /**
     * Initialize the number of agents in the simulation
     */
104
    long GetPedsNumber() const;
105 106

    /**
GrgrLmml's avatar
GrgrLmml committed
107
     * Read parameters from config.
108
     */
GrgrLmml's avatar
GrgrLmml committed
109
    bool InitArgs();
110 111

    /**
112
     * Update the route of the pedestrians and reassign rooms, in the case a room change happens
113
     */
114 115
    void UpdateRoutesAndLocations();

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

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

    /**
138
     * Run the main part of the simulation
139
     */
140
    double RunBody(double maxSimTime);
141

142
    /**
143 144 145 146 147 148 149 150
     * Perform some finalization like writing the
     * footers for the trajectories.
     */
    void RunFooter();

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

154 155 156 157
    /**
     * print some statistics about the simulation
     */
    void PrintStatistics();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
158

159 160 161
    /**
     * @return the agents source manager
     */
162
    AgentsSourcesManager& GetAgentSrcManager();
163 164 165 166 167 168

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

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

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

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

Ulrich Kemloh's avatar
Ulrich Kemloh committed
186 187 188
};

#endif /*SIMULATION_H_*/