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

#ifndef SIMULATION_H_
#define SIMULATION_H_

36

Ulrich Kemloh's avatar
Ulrich Kemloh committed
37 38
#include "general/ArgumentParser.h"
#include "geometry/Building.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
39
#include "geometry/SubRoom.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
40 41
#include "IO/OutputHandler.h"
#include "IO/IODispatcher.h"
42
#include "math/OperationalModel.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
43 44 45 46
#include "math/ODESolver.h"
#include "routing/GlobalRouter.h"
#include "routing/QuickestPathRouter.h"
#include "routing/DirectionStrategy.h"
47
#include "routing/DummyRouter.h"
48
#include "routing/MeshRouter.h"
49
#include "routing/RoutingEngine.h"
50
#include "routing/SafestPathRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
51
#include "pedestrian/PedDistributor.h"
52
#include "routing/CognitiveMapRouter.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
53
#include "events/EventManager.h"
54 55
#include "pedestrian/AgentsSourcesManager.h"

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

61 62
class Simulation
{
63
private:
64
     ///Number of pedestrians in the simulation
65
    long _nPeds;
66
    ///Maximum simulation time
67
    //double _tmax;
68 69 70 71
    /// time step
    double _deltaT;
    /// frame rate for the trajectories
    double _fps;
72 73
    ///seed using for the random number generator
    unsigned int _seed;
74
    /// building object
75
    std::unique_ptr<Building> _building;
76
    /// Force model to use
77
    std::shared_ptr<OperationalModel> _operationalModel;
78
    /// Manage all route choices algorithms
79
    std::shared_ptr<RoutingEngine> _routingEngine;
80
    /// differential equation solver
81 82 83
    ODESolver* _solver;
    /// writing the trajectories to file
    IODispatcher* _iod;
84
    /// EventManager
85
    EventManager* _em;
86
    /// argument parser
87
    ArgumentParser _argsParser;
88 89
    /// Agents sources manager
    AgentsSourcesManager _agentSrcManager;
90 91 92
    /// hybrid simulation manager
    //HybridSimulationManager
    std::shared_ptr<HybridSimulationManager>_hybridSimManager=nullptr;
93 94

public:
95 96 97
    /**
     * Constructor
     */
98
    Simulation(const ArgumentParser& args);
99 100 101 102

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

    /**
     * Initialize the number of agents in the simulation
     */
108
    long GetPedsNumber() const;
109 110 111 112

    /**
     * Read parameters from the argument parser class.
     */
113
    bool InitArgs(const ArgumentParser& args);
114 115

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

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


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

    /**
143
     * Run the main part of the simulation
144
     */
145
    int RunBody(double maxSimTime);
146

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

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

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

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

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

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


    /**
     * Update the flow for the door that the pedestrian just crossed
     * @param ped
     */
    void UpdateFlowAtDoors(const Pedestrian &ped) const;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
185 186 187
};

#endif /*SIMULATION_H_*/