AgentsSourcesManager.h 4.96 KB
Newer Older
1 2 3
/**
 * \file        AgentsSourcesManager.h
 * \date        Apr 14, 2015
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
6
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * \section License
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * 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.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
 * \section Description
 * This class is responsible for materialising agent in a given location at a given frequency up to a maximum number.
 * The optimal position where to put the agents is given by various algorithms, for instance
 * the Voronoi algorithm or the Mitchell Best candidate algorithm.
 *
 **/

30 31 32 33 34 35

#ifndef AGENTSSOURCESMANAGER_H_
#define AGENTSSOURCESMANAGER_H_

#include <vector>
#include <memory>
36
#include <atomic>
37 38 39

//Forward declarations
class AgentsSource;
40
class Building;
41
class Pedestrian;
42
class Point;
43 44 45 46 47 48 49 50 51

class AgentsSourcesManager
{
public:
     /**
      * Constructor
      */
     AgentsSourcesManager();

52 53 54
     /**
      * disable copying
      */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
55
     AgentsSourcesManager(const AgentsSourcesManager& ) = delete;
56

57 58 59 60 61 62 63 64 65
     /**
      * Destructor
      */
     virtual ~AgentsSourcesManager();

     /**
      * Make the class "runnable" by overloading the operator
      * @param value
      */
66
     void operator()();
67

68 69 70
     /**
      *
      */
71 72
     void Run();

73 74 75 76 77 78 79 80 81 82
     /**
      *  Add a new agent source
      */
     void AddSource(std::shared_ptr<AgentsSource> src);

     /**
      * @return all sources
      */
     const std::vector<std::shared_ptr<AgentsSource> >& GetSources() const;

83 84 85 86
     /**
      * Set the building object
      */
     void SetBuilding(Building* building);
87
     void SetRunning(bool running);
88

89 90 91 92 93
     /**
      * @return true if all agents have been generated
      * and the class is ready to leave
      */
     bool IsCompleted() const;
94

95 96 97 98 99 100 101 102
     /**
      * @return true if the building is updated
      *
      */
     bool IsBuildingUpdated() const;

     void SetBuildingUpdated(bool update);

103 104 105 106 107
     /**
      * Return a pointer to the building object
      */
     Building* GetBuilding() const;

108
     /**
109
      *Schedule the pedestrians for the simulation
110 111
      * @return true if all source are empty
      */
112 113 114 115 116 117 118
     bool ProcessAllSources() const;

     /**
      * Trigger the sources to generate the specified
      * number of agents for this frequency
      */
     void GenerateAgents();
119

120 121 122
     /**
      * Return the total number of agents that will be generated.
      * used by visualisation to allocate space
123
      *
124 125 126
      */
     long GetMaxAgentNumber() const;

127 128
     int GetMaxSimTime() const;
     void SetMaxSimTime(int t);
129
     bool IsRunning() const;
130 131 132 133 134 135 136 137 138
private:

     /**
      * Position incoming pedestrian using voronoi methods
      * @param src
      * @param agent
      */
     void ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent) const;

139

140
     void ComputeBestPositionDummy(AgentsSource* src, std::vector<Pedestrian*>& peds) const;
141

142 143 144 145 146 147
     /**
      * Position incoming pedestrians completely random
      */
     void ComputeBestPositionCompleteRandom(AgentsSource* src, std::vector<Pedestrian*>& peds) const;


148 149 150 151 152 153 154
     /**
      * Position incoming pedestrians randomly
      * @param src
      * @param peds
      */
     void ComputeBestPositionRandom(AgentsSource* src, std::vector<Pedestrian*>& peds) const;

155

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
     /**
      * Adjust the velocity of the pedestrian using the weidmann fundamental diagram
      */
     void AdjustVelocityUsingWeidmann(Pedestrian* ped) const;

     /**
      *
      * @param ped adjust the velocity by using the mean velocity of the neighbor in front of me
      */
     void AdjustVelocityByNeighbour(Pedestrian* ped) const;

     /**
      * Sort the given position vector by decreasing density
      * @param positions,
      * @param extra_position, an additional vector containing position to be considered in the density calculation
      */
     void SortPositionByDensity(std::vector<Point>& positions, std::vector<Point>& extra_positions) const;


175 176
private:
     /// contain the sources
177 178 179
     std::vector<std::shared_ptr<AgentsSource> > _sources;
     ///to control the trigger of the events
     long int _lastUpdateTime = 0;
180
     int maxSimTime = 0;
181
     /// building object
182
     Building* _building=nullptr;
183
     /// whether all agents have been dispatched
184 185
     static bool _isCompleted;
     //std::atomic<bool>_isCompleted=false;
186 187
//     std::atomic<bool>_buildingUpdated=false;
     bool _buildingUpdated;
188 189
     bool _isRunning = false;

190 191 192
};

#endif /* AGENTSSOURCESMANAGER_H_ */