Pedestrian.h 12.1 KB
Newer Older
1
/**
2 3
 * \file        Pedestrian.h
 * \date        Sep 30, 2010
4
 * \version     v0.6
5
 * \copyright   <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
6
 *
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/>.
 *
23
 * \section Description
24 25
 *
 *
26 27
 **/

Ulrich Kemloh's avatar
Ulrich Kemloh committed
28 29

#ifndef _PEDESTRIAN_H
Mohcine Chraibi's avatar
Mohcine Chraibi committed
30
#define _PEDESTRIAN_H
Ulrich Kemloh's avatar
Ulrich Kemloh committed
31 32

#include <vector>
33
#include <queue>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
34
#include <map>
35
#include <set>
36
#include <time.h>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
37

Ulrich Kemloh's avatar
Ulrich Kemloh committed
38
#include "Ellipse.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
39
#include "../general/Macros.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
40
#include "../geometry/NavLine.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
41 42

class Building;
43
class NavLine;
44
class Router;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
45
class Knowledge;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
46

47 48
class Pedestrian
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
49
private:
50 51 52 53 54
     //generic parameters, independent from models
     int _id; //starting with 1
     int _exitIndex; // current exit
     int _group;
     int _desiredFinalDestination;
55 56
     double _height;
     double _age;
57
     double _premovement = 0;
58
     double _riskTolerance=0;
59 60 61
     std::string _gender;

     //gcfm specific parameters
62 63 64
     double _mass; // Mass: 1
     double _tau; // Reaction time: 0.5
     double _deltaT; // step size
65
     JEllipse _ellipse;// the shape of this pedestrian
66 67 68 69 70
     Point _V0; //vector V0

     //double _V0;
     double _V0UpStairs;
     double _V0DownStairs;
71

72
     //location parameters
73 74 75
     std::string _roomCaption;
     int _roomID;
     int _subRoomID;
76 77
     int _oldRoomID;
     int _oldSubRoomID;
78 79 80 81 82 83


     NavLine* _navLine; // current exit line
     std::map<int, int>_mentalMap; // map the actual room to a destination
     std::vector<int> _destHistory;
     std::vector<int> _trip;
84

85 86 87
     Point _lastPosition;
     int _lastCellPosition;

88
     ///state of doors with time stamps
Ulrich Kemloh's avatar
Ulrich Kemloh committed
89
     std::map<int, Knowledge> _knownDoors;
90

91 92
     /// distance to nearest obstacle that blocks the sight of ped.
     double _distToBlockade;
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
     //routing parameters
     /// new orientation after 10 seconds
     double _reroutingThreshold;
     /// a new orientation starts after this time
     double _timeBeforeRerouting;
     /// actual time im Jam
     double _timeInJam;
     /// time after which the ped feels to be in jam
     double _patienceTime;
     /// data from the last <_recordingTime> seconds will be kept
     double _recordingTime;
     /// store the last positions
     std::queue <Point> _lastPositions;
     /// store the last velocities
     std::queue <Point> _lastVelocites;
108 109
     /// routing strategy followed
     RoutingStrategy _routingStrategy;
110 111 112 113 114 115 116 117

     int _newOrientationDelay; //2 seconds, in steps

     /// necessary for smooth turning at sharp bend
     int _updateRate;
     double _turninAngle;
     bool _reroutingEnabled;
     bool _tmpFirstOrientation; // possibility to get rid of this variable
118
     bool _newOrientationFlag; //this is used in the DirectionGeneral::GetTarget()
119
     bool _newEventFlag;
120 121 122

     // the current time in the simulation
     static double _globalTime;
123
     static AgentColorMode _colorMode;
124 125 126 127 128 129
     bool _spotlight;

     /// the router responsible for this pedestrian
     Router* _router;
     /// a pointer to the complete building
     Building * _building;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
130

131 132
     static int _agentsCreated;

Ulrich Kemloh's avatar
Ulrich Kemloh committed
133
public:
134
     // constructors
135 136 137 138 139 140 141 142 143 144
     Pedestrian();
     virtual ~Pedestrian();

     // Setter-Funktionen
     void SetID(int i);
     void SetRoomID(int i, std::string roomCaption);
     void SetSubRoomID(int i);
     void SetMass(double m);
     void SetTau(double tau);
     void SetEllipse(const JEllipse& e);
145 146

     //TODO: merge this two functions
147 148
     void SetExitIndex(int i);
     void SetExitLine(const NavLine* l);
149

150 151 152
     void Setdt(double dt);
     double Getdt();

153 154 155
     void SetDistToBlockade(double dist);
     double GetDistToBlockade();
     
156
     // Eigenschaften der Ellipse
157
     void SetPos(const Point& pos, bool initial=false); // setzt x und y-Koordinaten
158 159
     void SetCellPos(int cp);
     void SetV(const Point& v); // setzt x und y-Koordinaten der Geschwindigkeit
160
     void SetV0Norm(double v0,double v0UpStairs, double v0DownStairs);
161
     void SetSmoothTurning(); // activate the smooth turning with a delay of 2 sec
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
     void SetPhiPed();
     void SetFinalDestination(int UID);
     void SetTrip(const std::vector<int>& trip);
     void SetRouter(Router* router);

     // Getter-Funktionen
     const std::vector<int>& GetTrip() const;
     int GetID() const;
     int GetRoomID() const;
     int GetSubRoomID() const;
     double GetMass() const;
     double GetTau() const;
     const JEllipse& GetEllipse() const;
     int GetExitIndex() const;
     Router* GetRouter() const;
     NavLine* GetExitLine() const;

     // Eigenschaften der Ellipse
     const Point& GetPos() const;
     int GetCellPos() const;
     const Point& GetV() const;
     const Point& GetV0() const;
     const Point& GetV0(const Point& target);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
185
     void InitV0(const Point& target);
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
     /**
      * the desired speed is the projection of the speed on the horizontal plane.
      * @return the norm of the desired speed.
      */
     double GetV0Norm() const;

     ///get axis in the walking direction
     double GetLargerAxis() const;
     ///get axis in the shoulder direction = orthogonal to the walking direction
     double GetSmallerAxis() const;
     double GetTimeInJam()const;
     int GetFinalDestination() const;
     void ClearMentalMap(); // erase the peds memory

     // functions for known closed Doors (needed for the Graphrouting and Rerouting)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
202
     void AddKnownClosedDoor(int door, double time);
203
     // needed for information sharing
Ulrich Kemloh's avatar
Ulrich Kemloh committed
204
     const std::map<int, Knowledge>& GetKnownledge() const;
205

206 207
     /**
      * For convenience
Ulrich Kemloh's avatar
Ulrich Kemloh committed
208
      * @return a string representation of the knowledge
209 210 211
      */
     const std::string GetKnowledgeAsString() const;

212 213 214 215
     /**
      * clear all information related to the knowledge about closed doors
      */
     void ClearKnowledge();
216

217
     RoutingStrategy GetRoutingStrategy() const;
218 219 220 221 222 223
     int GetUniqueRoomID() const;
     int GetNextDestination();
     int GetLastDestination();
     int GetDestinationCount();
     double GetDistanceToNextTarget() const;
     double GetDisTanceToPreviousTarget() const;
224 225
     void SetNewOrientationFlag(bool flag);
     bool GetNewOrientationFlag();
226 227
     bool GetNewEventFlag();
     void SetNewEventFlag(bool flag);
228 229 230 231 232
     bool ChangedSubRoom();
     void RecordActualPosition();
     double GetDistanceSinceLastRecord();

     /**
233 234
      * The elevation is computed using the plane
      * equation given in the subroom.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
      * @return the z coordinate of the pedestrian.
      */

     double GetElevation() const;

     /**
      * Compute and update the route.
      * This method should be called at each time step;
      *
      * @return -1 if no route could be found. The ID of the
      * next target is returned otherwise.
      *
      */
     int FindRoute();

     ///write the pedestrian path (room and exit taken ) to file
     void WritePath(std::ofstream& file, Building* building=NULL);

     ///write the pedestrian path (room and exit taken ) to file
     /// in the format room1:exit1>room2:exit2
     std::string GetPath();

257 258 259 260 261 262
     /**
      * Dump the parameters of this pedestrians.
      * @param ID, the id of the pedestrian
      * @param pa, the parameter to display (0 for all parameters)
      */
     void Dump(int ID, int pa = 0);
263 264 265 266 267 268 269 270 271 272 273

     /**
      * observe the reference pedestrians and collect some data, e.g distance to exit
      * and average/maximal velocities
      *
      * @param maxObservationTime in sec.
      * @return false, if the observation time is over and the observation data can be retrieved
      */
     bool Observe(double maxObservationTime=-1);

     /**
274 275
      * @return true, if reference pedestrian have been selected
      * and the observation process has started
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
      */
     bool IsObserving();

     /**
      * return the observation data in an array
      *
      * @param exitID, the concerned exit
      * @param data, a float array to store the data
      */
     void GetObservationData(int exitID, float* data);

     /**
      * @return true if the time spent in jam exceed the patience time
      * @see GetPatienceTime
      */
     bool IsFeelingLikeInJam();

     /**
      * Set/Get the patience time.
      * Higher value will cause the agent to almost never changes its current path.
      * Small values will increase the frequency of looking for alternative
      */
     double GetPatienceTime() const;

     /**
      * Set/Get the patience time.
      * Higher value will cause the agent to almost never changes its current path.
      * Small values will increase the frequency of looking for alternative
      */
     void SetPatienceTime(double patienceTime);

     /**
      * Set/Get the spotlight value. If true,
      * this pedestrians will be coloured and all other grey out.
      * @param spotlight true for enabling, false for disabling
      */
     void SetSpotlight(bool spotlight);

     /**
      * Set/Get the spotlight value. If true,
      * this pedestrians will be coloured and all other grey out.
      * @param spotlight true for enabling, false for disabling
      */
     bool GetSpotlight();

321 322 323 324 325 326 327 328 329
     /***
      * Set/Get the time after which this pedestrian will start taking actions.
      */
     void SetPremovementTime(double time);

     /***
      * Set/Get the time after which this pedestrian will start taking actions.
      */
     double GetPremovementTime();
330

331 332 333 334 335 336 337 338 339 340 341 342 343 344
     /**
      * Set/Get the risk tolerance of a pedestrians.
      * The value should be in the interval [0 1].
      * It will be truncated accordingly if not in that interval.
      */
     void SetRiskTolerance(double tol);

     /**
      * Set/Get the risk tolerance of a pedestrians.
      * The value should be in the interval [0 1].
      * It will be truncated accordingly if not in that interval.
      */
     double GetRiskTolerance() const;

345 346 347 348 349 350 351
     /**
      * return the pedestrian color used for visualiation.
      * Default mode is coded by velocity.
      * @return a value in [-1 255]
      */
     int GetColor();

352 353 354 355
     void ResetTimeInJam();
     void UpdateTimeInJam();
     void UpdateJamData();
     void UpdateReroutingTime();
356
     double GetReroutingTime();
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
     void RerouteIn(double time);
     bool IsReadyForRerouting();

     /**
      * clear the parameter related to the re routing
      */
     void ResetRerouting();

     /**
      * Set/Get the time period for which the data of the pedestrian should be kept.
      * The results are used by the quickest path router
      */
     void SetRecordingTime(double timeInSec);

     /**
      * Set/Get the time period for which the data of the pedestrian should be kept
      * The results are used by the quickest path router
      */
     double GetRecordingTime() const;
376

377 378 379 380
     /**
      * @return the average velocity over the recording period
      */
     double GetMeanVelOverRecTime() const;
381

382 383 384 385 386 387 388 389 390 391 392 393
     double GetAge() const;
     void SetAge(double age);
     std::string GetGender() const;
     void SetGender(std::string gender);
     double GetHeight() const;
     void SetHeight(double height);
     int GetGroup() const;
     void SetGroup(int group);

     static double GetGlobalTime();
     static void SetGlobalTime(double time);

394 395 396 397 398 399 400
     /**
      * @return the total number of pedestrians objects created.
      * This is useful for the linked-cells algorithm, since it uses the ID of the pedestrians
      * and the  maximal count must be known in advance.
      */
     static int GetAgentsCreated();

401

402 403 404 405 406 407
     /**
      * Set the color mode for the pedestrians
      * @param mode
      */
     static void SetColorMode(AgentColorMode mode);

408 409 410 411 412 413 414 415 416
     /**
      * Set/Get the Building object
      */
     const Building* GetBuilding();

     /**
      * Set/Get the Building object
      */
     void SetBuilding(Building* building);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
417 418 419

};

Mohcine Chraibi's avatar
Mohcine Chraibi committed
420
#endif  /* _PEDESTRIAN_H */