Simulation.h 4.77 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 43 44 45
#include "math/ODESolver.h"
#include "routing/GlobalRouter.h"
#include "routing/QuickestPathRouter.h"
#include "routing/DirectionStrategy.h"
46
#include "routing/DummyRouter.h"
47
#include "routing/MeshRouter.h"
48
#include "routing/RoutingEngine.h"
49
#include "routing/SafestPathRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
50
#include "pedestrian/PedDistributor.h"
51
#include "routing/CognitiveMapRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
52
#include "events/EventManager.h"
53
#include "pedestrian/AgentsSourcesManager.h"
GrgrLmml's avatar
GrgrLmml committed
54
#include "general/Configuration.h"
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::unique_ptr<Building> _building;
74
    /// Force model to use
75
    std::shared_ptr<OperationalModel> _operationalModel;
76
    /// Manage all route choices algorithms
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 85
    /// config
    const 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
public:
92 93 94
    /**
     * Constructor
     */
GrgrLmml's avatar
GrgrLmml committed
95
    Simulation(const Configuration* args);
96 97 98 99

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#endif /*SIMULATION_H_*/