AgentsSourcesManager.h 3.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * AgentsSourcesManager.h
 *
 *  Created on: 14.04.2015
 *      Author: piccolo
 */

#ifndef AGENTSSOURCESMANAGER_H_
#define AGENTSSOURCESMANAGER_H_

#include <vector>
#include <memory>
13
#include <atomic>
14 15 16

//Forward declarations
class AgentsSource;
17
class Building;
18
class Pedestrian;
19
class Point;
20 21 22 23 24 25 26 27 28

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

29 30 31
     /**
      * disable copying
      */
32
     //AgentsSourcesManager(const AgentsSourcesManager& ) = delete;
33

34 35 36 37 38 39 40 41 42
     /**
      * Destructor
      */
     virtual ~AgentsSourcesManager();

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

45 46 47
     /**
      *
      */
48 49
     void Run();

50 51 52 53 54 55 56 57 58 59
     /**
      *  Add a new agent source
      */
     void AddSource(std::shared_ptr<AgentsSource> src);

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

60 61 62 63 64
     /**
      * Set the building object
      */
     void SetBuilding(Building* building);

65 66 67 68 69
     /**
      * @return true if all agents have been generated
      * and the class is ready to leave
      */
     bool IsCompleted() const;
70

71 72 73 74 75
     /**
      * Return a pointer to the building object
      */
     Building* GetBuilding() const;

76
     /**
77
      *Schedule the pedestrians for the simulation
78 79
      * @return true if all source are empty
      */
80 81 82 83 84 85 86
     bool ProcessAllSources() const;

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

88 89 90 91 92 93
     /**
      * Return the total number of agents that will be generated.
      * used by visualisation to allocate space
      */
     long GetMaxAgentNumber() const;

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

private:

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

     /**
      * Position incoming pedestrians randomly
      * @param src
      * @param peds
      */
     void ComputeBestPositionRandom(AgentsSource* src, std::vector<Pedestrian*>& peds) const;

     /**
      * 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;


130 131
private:
     /// contain the sources
132 133 134
     std::vector<std::shared_ptr<AgentsSource> > _sources;
     ///to control the trigger of the events
     long int _lastUpdateTime = 0;
135
     /// building object
136
     Building* _building=nullptr;
137
     /// whether all agents have been dispatched
138 139
     static bool _isCompleted;
     //std::atomic<bool>_isCompleted=false;
140 141 142
};

#endif /* AGENTSSOURCESMANAGER_H_ */