AgentsSource.h 5.28 KB
Newer Older
1 2 3
/**
 * \file        AgentSource.h
 * \date        Apr 04, 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
 * \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.
 * The optimal position where to put the agents is given by various algorithms, for instance
 * the Voronoi algorithm or the Mitchell Best candidate algorithm.
 *
 **/
29 30 31 32 33 34

#ifndef AGENTSOURCE_H_
#define AGENTSOURCE_H_

#include <string>
#include <vector>
35
#include <memory>
36 37 38

class Pedestrian;
class OutputHandler;
39
class StartDistribution;
40
class Building;
41 42 43 44 45 46 47 48 49 50 51

// external variables
extern OutputHandler* Log;


class AgentsSource
{
public:
     /**
      * Constructor
      */
Mohcine Chraibi's avatar
Mohcine Chraibi committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
     AgentsSource(int id,
                  const std::string& caption,
                  int max_agents,
                  int group_id,
                  int frequency,
                  bool greedy,
                  double time,
                  int agent_id,
                  float startx,
                  float starty,
                  float percent,
                  float rate,
                  int chunkAgents,
                  std::vector<float> boundaries,
                  std::vector<int> lifeSpan);
67 68 69 70 71 72 73 74 75 76

     /**
      * Destructor
      */
     virtual ~AgentsSource();

     /**
      * Add a new agent to this source
      * @param ped
      */
77
     void AddToPool(Pedestrian* ped);
78 79 80

     /**
      * Generate a number of agents, based on the frequency given in the constructor.
Mohcine Chraibi's avatar
Mohcine Chraibi committed
81
      * No agents are generated if the maximum (_maxAgents) is reached.
82 83 84
      * @see _maxAgents
      * @param ped
      */
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
     void GenerateAgentsAndAddToPool(int count, Building* building);

     /**
      * Generate agents, but do not add them to the pool
      * @param ped, the container for the agents
      * @param count, the number of agents to generate
      * @param building, a pointer to the building object
      */
     void GenerateAgents(std::vector<Pedestrian*>& peds, int count, Building* building);

     /**
      * Generate count agents and save them in the vector
      * @param ped, the container for the agents
      * @param count, the number of agents to generate
      */
     void RemoveAgentsFromPool(std::vector<Pedestrian*>& peds, int count);
101

102 103 104 105 106 107 108
     /**
      * Add the agents to the pool. This might be important in the case the removed agents could not
      * be placed correctly. They can be requeued using this function.
      * @param peds
      */
     void AddAgentsToPool(std::vector<Pedestrian*>& peds);

109 110 111 112 113 114 115 116 117 118 119 120
     /**
      * @return the number of agents remaining
      */
     int GetPoolSize() const;

     /**
      * Print relevant information
      */
     void Dump() const;

     int GetAgentsGenerated() const;
     void SetAgentsGenerated(int agentsGenerated);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
121 122
     const std::vector<float> GetBoundaries() const;
     void Setboundaries(std::vector<float> bounds);
123 124 125 126
     const std::string& GetCaption() const;
     int GetFrequency() const;
     int GetGroupId() const;
     int GetId() const;
127
     int GetAgentId() const;
128 129
     float GetStartX() const;
     float GetStartY() const;
130
     double GetPlanTime() const;
131
     int GetMaxAgents() const;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
132 133
     int GetChunkAgents() const;
     int GetRemainingAgents() const;
134
     void ResetRemainingAgents();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
135 136 137 138
     void UpdateRemainingAgents(int remaining);
     float GetPercent() const;
     float GetRate() const;
     std::vector<int> GetLifeSpan() const;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
139
     bool Greedy() const;
140
     void SetStartDistribution(std::shared_ptr<StartDistribution>);
141 142
     const std::shared_ptr<StartDistribution> GetStartDistribution() const;

143 144
private:
     int _id=-1;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
145
     int _frequency=1; /// create \var _chunkAgents every \var _frequency seconds
146 147 148
     int _maxAgents=0;
     int _groupID=-1;
     std::string _caption="no caption";
Mohcine Chraibi's avatar
Mohcine Chraibi committed
149 150
     bool _greedy = false;
     int _agentsGenerated=0;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
151
     std::vector<float> _boundaries;
152
     int _agent_id;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
153 154 155 156 157 158 159 160 161 162 163 164
     double _time; /// planned generation time. here \var _maxAgents = 1
     float _startx; /// \var _maxAgents = 1
     float _starty; /// \var _maxAgents = 1
     std::vector<int> _lifeSpan;

     int _chunkAgents; /// generate \var chunk_agents per \var frequency seconds
     int _remainingAgents; /// After generating \var chunk_agents \time \var
                           /// _percent per \var frequency seconds, this is the
                           /// remaining of agents still to be produced
     float _percent=1.0; /// generate \var _percent * \var _chunkAgents
     float _rate=1.0;

165
     std::vector<Pedestrian*> _agents;
166
     std::shared_ptr<StartDistribution> _startDistribution;
167 168 169
};

#endif /* AGENTSOURCE_H_ */