Simulation.h 5.02 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
Oliver Schmidts's avatar
Oliver Schmidts committed
73
    std::unique_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 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;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
91
    bool _gotSources; // is true if we got some sources. Otherwise, false.
92
public:
93 94 95
    /**
     * Constructor
     */
GrgrLmml's avatar
GrgrLmml committed
96
    Simulation(const Configuration* args);
97 98 99 100

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * Update the flow for the door that the pedestrian just crossed
     * @param ped
     */
GrgrLmml's avatar
GrgrLmml committed
180
    void UpdateFlowAtDoors(const Pedestrian& ped) const;
181 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;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
188 189 190
};

#endif /*SIMULATION_H_*/