EventManager.h 4.64 KB
Newer Older
Weichen's avatar
Weichen committed
1 2 3
/**
 * \file        EventManager.h
 * \date        Jul 4, 2014
4 5
 * \version     v0.7
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
Weichen's avatar
Weichen committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * \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
 *
 *
 **/
Ulrich Kemloh's avatar
Ulrich Kemloh committed
27

28
#include <vector>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
29
#include <string>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
30
#include <random>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
31 32

class Building;
33 34 35
class Router;
class QuickestPathRouter;
class RoutingEngine;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
36
class Event;
37

38 39
extern OutputHandler* Log;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
40 41
class EventManager
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
42 43 44 45
public:
     /**
      * Constructor
      */
46
     EventManager(Building *_b, unsigned int seed);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

     /**
      * destructor
      */
     ~EventManager();

     /**
      * Read and parse the events
      * @return false if an error occured
      */
     bool ReadEventsXml();

     /**
      * Print the parsed events
      */
     void ListEvents();

     /**
      * Read and parse events from a text file
      * @param time
      */
     void ReadEventsTxt(double time);

70 71 72 73
     /**
      * Reads the schedule file
      */
     bool ReadSchedule();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
74 75 76 77 78 79

     //process the event using the current time stamp
     //from the pedestrian class
     void ProcessEvent();
     //Eventhandling
     void CloseDoor(int id);
80
     void TempCloseDoor(int id);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
81 82 83 84
     void OpenDoor(int id);
     //void ChangeRouting(int id, const std::string& state);
     void GetEvent(char* c);

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

private:
     /**
      * collect the close doors and generate a new graph
      * @param _building
      */
     bool CreateRoutingEngine(Building* _b, int first_engine=false);

     /**
      * Create a router corresponding to the given strategy
      * @param strategy
      * @return a router/NULL for invalid strategies
      */
     Router * CreateRouter(const RoutingStrategy& strategy);

     /**
      * Update the knowledge about closed doors.
      * Each pedestrian who is xx metres from a closed door,
      * will save that information
      * @param _b, the building object
      */
106 107 108 109 110 111 112 113 114
     bool DisseminateKnowledge(Building* _b);

     /**
      * Gather knowledge about the state of the doors.
      * Which is going to be disseminated afterwards.
      * @param _b
      * @return
      */
     bool CollectNewKnowledge(Building* _b);
115 116

     /**
Ulrich Kemloh's avatar
Ulrich Kemloh committed
117
      * Synchronize the knowledge of the two pedestrians.
118 119 120 121
      * The information with the newest timestamp
      * is always accepted with a probability of one.
      * @param p1, first pedestrian
      * @param p2, second pedestrian
Ulrich Kemloh's avatar
Ulrich Kemloh committed
122
      * @return true if the information could be synchronized
123
      */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
124 125 126 127 128 129 130 131 132 133
     bool SynchronizeKnowledge(Pedestrian* p1, Pedestrian* p2);

     /**
      * Merge the knowledge of the two pedestrians. Ped1 is informing ped2 who depending
      * on his risk awareness probability could accept of refuse the new information.
      * @param p1, the informant with the new information
      * @param p2, the pedestrian receiving the information
      * @return true in the case p2 accepted the new information
      */
     bool MergeKnowledge(Pedestrian* p1, Pedestrian* p2);
134

135 136 137
     bool MergeKnowledgeUsingProbability(Pedestrian* p1, Pedestrian* p2);


138 139 140 141 142 143
     /**
      * Update the pedestrian route based on the new information
      * @param p1
      * @return
      */
     bool UpdateRoute(Pedestrian* p1);
144

145
     void CreateSomeEngines();
146

Ulrich Kemloh's avatar
Ulrich Kemloh committed
147
private:
148

Ulrich Kemloh's avatar
Ulrich Kemloh committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
     std::vector<Event> _events;
     std::string _projectFilename;
     std::string _projectRootDir;
     Building *_building;
     FILE *_file;
     bool _dynamic;
     int _eventCounter;
     long int _lastUpdateTime;
     //information propagation time in seconds
     int _updateFrequency;
     //information propagation range in meters
     int _updateRadius;
     //save the router corresponding to the actual state of the building
     std::map<std::string, RoutingEngine*> _eventEngineStorage;
     //save the available routers defined in the simulation
     std::vector<RoutingStrategy> _availableRouters;
165

Ulrich Kemloh's avatar
Ulrich Kemloh committed
166 167 168 169
     // random number generator
     std::mt19937 _rdGenerator;
     std::uniform_real_distribution<double> _rdDistribution;
//     std::uniform_real_distribution<double> d(0, 1);
170
     std::map<int, std::vector<int>> groupDoor;
171
};