SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSPerson.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The class for modelling person-movements
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSPerson_h
24 #define MSPerson_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <vector>
38 #include <set>
39 #include <utils/common/SUMOTime.h>
40 #include <utils/common/Command.h>
41 #include <utils/geom/Position.h>
42 
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSNet;
48 class MSEdge;
49 class OutputDevice;
51 class MSBusStop;
52 class SUMOVehicle;
54 
55 typedef std::vector<const MSEdge*> MSEdgeVector;
56 
57 
58 // ===========================================================================
59 // class definitions
60 // ===========================================================================
66 class MSPerson {
67 public:
68  enum StageType {
69  WALKING = 0,
70  DRIVING = 1,
71  WAITING = 2
72  };
73 
74 
79  class MSPersonStage {
80  public:
82  MSPersonStage(const MSEdge& destination, StageType type);
83 
85  virtual ~MSPersonStage();
86 
88  const MSEdge& getDestination() const;
89 
91  virtual const MSEdge* getEdge(SUMOTime now) const = 0;
92  virtual const MSEdge* getFromEdge() const = 0;
93  virtual SUMOReal getEdgePos(SUMOTime now) const = 0;
94 
96  virtual Position getPosition(SUMOTime now) const = 0;
97  virtual SUMOReal getAngle(SUMOTime now) const = 0;
98 
101  return myType;
102  }
103 
105  virtual std::string getStageTypeName() const = 0;
106 
108  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at) = 0;
109 
111  void setDeparted(SUMOTime now);
112 
114  void setArrived(SUMOTime now);
115 
117  virtual bool isWaitingFor(const std::string& line) const;
118 
120  virtual bool isWaiting4Vehicle() const {
121  return false;
122  }
123 
125  virtual SUMOTime timeWaiting4Vehicle(SUMOTime /*now*/) const {
126  return false;
127  }
128 
130  Position getEdgePosition(const MSEdge* e, SUMOReal at, SUMOReal offset) const;
131 
132  SUMOReal getEdgeAngle(const MSEdge* e, SUMOReal at) const;
133 
138  virtual void tripInfoOutput(OutputDevice& os) const = 0;
139 
144  virtual void routeOutput(OutputDevice& os) const = 0;
145 
150  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const = 0;
151 
156  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const = 0;
157 
158 
159  protected:
162 
165 
168 
171 
172  private:
175 
178 
179  };
180 
187  public:
189  MSPersonStage_Walking(const std::vector<const MSEdge*>& route, MSBusStop* toBS, SUMOTime walkingTime, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos);
190 
193 
195  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
196 
198  const MSEdge* getEdge(SUMOTime now) const;
199  const MSEdge* getFromEdge() const;
200  SUMOReal getEdgePos(SUMOTime now) const;
201 
203  Position getPosition(SUMOTime now) const;
204 
205  SUMOReal getAngle(SUMOTime now) const;
206 
207  std::string getStageTypeName() const {
208  return "walking";
209  }
210 
215  virtual void tripInfoOutput(OutputDevice& os) const;
216 
221  virtual void routeOutput(OutputDevice& os) const;
222 
227  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
228 
233  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
234 
235  SUMOTime moveToNextEdge(MSPerson* person, SUMOTime currentTime);
236 
237 
238  class MoveToNextEdge : public Command {
239  public:
240  MoveToNextEdge(MSPerson* person, MSPersonStage_Walking& walk) : myParent(walk), myPerson(person) {}
242  SUMOTime execute(SUMOTime currentTime) {
243  return myParent.moveToNextEdge(myPerson, currentTime);
244  }
245  private:
248  private:
251 
252  };
253 
254 
255  private:
256  void computeWalkingTime(const MSEdge* const e, SUMOReal fromPos, SUMOReal toPos, MSBusStop* bs);
257 
258 
259  private:
262 
264  std::vector<const MSEdge*> myRoute;
265 
266 
267  std::vector<const MSEdge*>::iterator myRouteStep;
268 
270  //std::vector<SUMOTime> myArrivalTimes;
271 
277 
279  //bool myDurationWasGiven;
280  //SUMOReal myOverallLength;
281 
283  public:
285  explicit arrival_finder(SUMOTime time) : myTime(time) {}
286 
288  bool operator()(SUMOReal t) const {
289  return myTime > t;
290  }
291 
292  private:
295  };
296 
297  private:
300 
303 
304  };
305 
311  public:
313  MSPersonStage_Driving(const MSEdge& destination, MSBusStop* toBS,
314  const std::vector<std::string>& lines);
315 
318 
320  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
321 
323  const MSEdge* getEdge(SUMOTime now) const;
324  const MSEdge* getFromEdge() const;
325  SUMOReal getEdgePos(SUMOTime now) const;
326 
328  Position getPosition(SUMOTime now) const;
329 
330  SUMOReal getAngle(SUMOTime now) const;
331 
332  std::string getStageTypeName() const;
333 
335  bool isWaitingFor(const std::string& line) const;
336 
338  bool isWaiting4Vehicle() const;
339 
342 
344  myVehicle = v;
345  }
346 
352  virtual void tripInfoOutput(OutputDevice& os) const;
353 
359  virtual void routeOutput(OutputDevice& os) const;
360 
365  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
366 
371  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
372 
373  private:
375  const std::set<std::string> myLines;
376 
379 
385 
386  private:
389 
392 
393  };
394 
399  public:
401  MSPersonStage_Waiting(const MSEdge& destination,
402  SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string& actType);
403 
406 
408  const MSEdge* getEdge(SUMOTime now) const;
409  const MSEdge* getFromEdge() const;
410  SUMOReal getEdgePos(SUMOTime now) const;
411  SUMOTime getUntil() const;
412 
414  Position getPosition(SUMOTime now) const;
415 
416  SUMOReal getAngle(SUMOTime now) const;
417 
418  std::string getStageTypeName() const {
419  return "waiting (" + myActType + ")";
420  }
421 
423  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
424 
430  virtual void tripInfoOutput(OutputDevice& os) const;
431 
437  virtual void routeOutput(OutputDevice& os) const;
438 
443  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
444 
449  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
450 
451  private:
454 
457 
459  std::string myActType;
460 
462 
463 
464  private:
467 
470 
471  };
472 
473 public:
475  typedef std::vector<MSPersonStage*> MSPersonPlan;
476 
477 protected:
480 
483 
486 
488  MSPersonPlan::iterator myStep;
489 
492 
493 public:
495  MSPerson(const SUMOVehicleParameter* pars, const MSVehicleType* vtype, MSPersonPlan* plan);
496 
498  virtual ~MSPerson();
499 
501  const std::string& getID() const;
502 
503  /* @brief proceeds to the next step of the route,
504  * @return Whether the persons plan continues */
505  bool proceed(MSNet* net, SUMOTime time);
506 
508  SUMOTime getDesiredDepart() const;
509 
511  void setDeparted(SUMOTime now);
512 
514  const MSEdge& getDestination() const {
515  return (*myStep)->getDestination();
516  }
517 
519  const MSEdge* getEdge(SUMOTime now) const {
520  return (*myStep)->getEdge(now);
521  }
522 
524  const MSEdge* getFromEdge() const {
525  return (*myStep)->getFromEdge();
526  }
527 
529  return (*myStep)->getEdgePos(now);
530  }
531 
533  virtual Position getPosition(SUMOTime now) const {
534  return (*myStep)->getPosition(now);
535  }
536 
537 
539  return (*myStep)->getAngle(now);
540  }
541 
544  return (*myStep)->getStageType();
545  }
546 
547 
548  std::string getCurrentStageTypeName() const {
549  return (*myStep)->getStageTypeName();
550  }
551 
553  return *myStep;
554  }
555 
561  void tripInfoOutput(OutputDevice& os) const;
562 
568  void routeOutput(OutputDevice& os) const;
569 
571  bool isWaitingFor(const std::string& line) const {
572  return (*myStep)->isWaitingFor(line);
573  }
574 
576  bool isWaiting4Vehicle() const {
577  return (*myStep)->isWaiting4Vehicle();
578  }
579 
580 
583  return (*myStep)->timeWaiting4Vehicle(now);
584  }
585 
587  return *myParameter;
588  }
589 
590 
591  inline const MSVehicleType& getVehicleType() const {
592  return *myVType;
593  }
594 
595 
597  static const SUMOReal SIDEWALK_OFFSET;
598 
599 private:
601  MSPerson(const MSPerson&);
602 
604  MSPerson& operator=(const MSPerson&);
605 
606 };
607 
608 
609 #endif
610 
611 /****************************************************************************/
virtual void routeOutput(OutputDevice &os) const =0
Called on writing vehroute output.
SUMOTime getUntil() const
Definition: MSPerson.cpp:466
SUMOReal getAngle(SUMOTime now) const
Definition: MSPerson.cpp:478
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:553
const MSEdge * myWaitingEdge
Definition: MSPerson.h:384
virtual void beginEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
Definition: MSPerson.cpp:408
SUMOTime myArrived
the time at which this stage ended
Definition: MSPerson.h:167
const MSEdge * getFromEdge() const
Definition: MSPerson.cpp:307
SUMOTime getDesiredDepart() const
Returns the desired departure time.
Definition: MSPerson.cpp:587
virtual ~MSPerson()
destructor
Definition: MSPerson.cpp:543
const SUMOVehicleParameter * myParameter
the plan of the person
Definition: MSPerson.h:479
bool myWriteEvents
Whether events shall be written.
Definition: MSPerson.h:491
const MSEdge & getDestination() const
returns the destination edge
Definition: MSPerson.cpp:70
const MSVehicleType & getVehicleType() const
Definition: MSPerson.h:591
const MSEdge * getEdge(SUMOTime now) const
Returns the current edge.
Definition: MSPerson.cpp:143
void setDeparted(SUMOTime now)
logs end of the step
Definition: MSPerson.cpp:593
bool isWaitingFor(const std::string &line) const
Whether the person waits for a vehicle of the line specified.
Definition: MSPerson.h:571
arrival_finder(SUMOTime time)
constructor
Definition: MSPerson.h:285
MSPersonStage(const MSEdge &destination, StageType type)
constructor
Definition: MSPerson.cpp:62
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.h:576
std::vector< const MSEdge * > myRoute
The route of the person.
Definition: MSPerson.h:264
const MSEdge * getFromEdge() const
Returns the departure edge.
Definition: MSPerson.h:524
static const SUMOReal SIDEWALK_OFFSET
the offset for computing person positions when walking
Definition: MSPerson.h:597
virtual bool isWaitingFor(const std::string &line) const
Whether the person waits for a vehicle of the line specified.
Definition: MSPerson.cpp:90
StageType getCurrentStageType() const
Definition: MSPerson.h:543
virtual void beginEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
Definition: MSPerson.cpp:514
void setDeparted(SUMOTime now)
logs end of the step
Definition: MSPerson.cpp:76
SUMOTime myWaitingSince
The time since which this person is waiting for a ride.
Definition: MSPerson.h:383
Position getPosition(SUMOTime now) const
Definition: MSPerson.cpp:162
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:493
virtual bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.h:120
const std::set< std::string > myLines
the lines to choose from
Definition: MSPerson.h:375
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.cpp:374
SUMOReal getEdgePos(SUMOTime now) const
Definition: MSPerson.cpp:313
SUMOTime myWaitingUntil
the time until the person is waiting
Definition: MSPerson.h:456
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Definition: MSPerson.cpp:227
const MSVehicleType * myVType
This Persons&#39;s type. (mainly used for drawing related information.
Definition: MSPerson.h:482
SUMOReal getEdgePos(SUMOTime now) const
Definition: MSPerson.h:528
virtual std::string getStageTypeName() const =0
return string representation of the current stage
std::string getStageTypeName() const
return string representation of the current stage
Definition: MSPerson.h:418
Base (microsim) event class.
Definition: Command.h:61
MSPersonStage & operator=(const MSPersonStage &)
Invalidated assignment operator.
const MSEdge * getEdge(SUMOTime now) const
Returns the current edge.
Definition: MSPerson.h:519
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
Definition: MSPerson.cpp:106
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:392
virtual void proceed(MSNet *net, MSPerson *person, SUMOTime now, MSEdge *previousEdge, const SUMOReal at)
proceeds to the next step
Definition: MSPerson.cpp:178
virtual SUMOTime timeWaiting4Vehicle(SUMOTime) const
the time this person spent waiting for a vehicle
Definition: MSPerson.h:125
The simulated network and simulation perfomer.
Definition: MSNet.h:87
SUMOReal getEdgePos(SUMOTime now) const
Definition: MSPerson.cpp:155
The car-following model and parameter.
Definition: MSVehicleType.h:74
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSPerson.h:514
const SUMOVehicleParameter & getParameter() const
Definition: MSPerson.h:586
MSPersonStage_Walking(const std::vector< const MSEdge * > &route, MSBusStop *toBS, SUMOTime walkingTime, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos)
constructor
Definition: MSPerson.cpp:116
MoveToNextEdge(MSPerson *person, MSPersonStage_Walking &walk)
Definition: MSPerson.h:240
std::string getCurrentStageTypeName() const
Definition: MSPerson.h:548
A road/street connecting two junctions.
Definition: MSEdge.h:73
Position getEdgePosition(const MSEdge *e, SUMOReal at, SUMOReal offset) const
get position on edge e at length at with orthogonal offset
Definition: MSPerson.cpp:96
virtual const MSEdge * getEdge(SUMOTime now) const =0
Returns the current edge.
MSPersonPlan * myPlan
the plan of the person
Definition: MSPerson.h:485
void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Definition: MSPerson.cpp:607
virtual Position getPosition(SUMOTime now) const
Definition: MSPerson.h:533
virtual void proceed(MSNet *net, MSPerson *person, SUMOTime now, MSEdge *previousEdge, const SUMOReal at)=0
proceeds to the next step
SUMOTime moveToNextEdge(MSPerson *person, SUMOTime currentTime)
Definition: MSPerson.cpp:261
SUMOReal getEdgePos(SUMOTime now) const
Definition: MSPerson.cpp:460
Representation of a vehicle.
Definition: SUMOVehicle.h:63
SUMOTime myDeparted
the time at which this stage started
Definition: MSPerson.h:164
MSPersonStage_Walking & operator=(const MSPersonStage_Walking &)
Invalidated assignment operator.
std::vector< const MSEdge * > MSEdgeVector
Definition: MSPerson.h:53
virtual SUMOReal getAngle(SUMOTime now) const =0
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
virtual void beginEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (begin of an action)
SUMOReal getAngle(SUMOTime now) const
Definition: MSPerson.cpp:333
A lane area vehicles can halt at.
Definition: MSBusStop.h:63
virtual void endEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const =0
Called for writing the events output (end of an action)
MSPersonStage * getCurrentStage() const
Definition: MSPerson.h:552
virtual void tripInfoOutput(OutputDevice &os) const =0
Called on writing tripinfo output.
SUMOTime myWaitingDuration
the time the person is waiting
Definition: MSPerson.h:453
virtual void endEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
Definition: MSPerson.cpp:250
Position getPosition(SUMOTime now) const
Definition: MSPerson.cpp:472
virtual const MSEdge * getFromEdge() const =0
virtual void proceed(MSNet *net, MSPerson *person, SUMOTime now, MSEdge *previousEdge, const SUMOReal at)
proceeds to the next step
Definition: MSPerson.cpp:484
std::vector< const MSEdge * >::iterator myRouteStep
Definition: MSPerson.h:267
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Definition: MSPerson.cpp:401
std::string myActType
The type of activity.
Definition: MSPerson.h:459
MSPerson & operator=(const MSPerson &)
Invalidated assignment operator.
MSPersonStage_Driving & operator=(const MSPersonStage_Driving &)
Invalidated assignment operator.
const MSEdge * getFromEdge() const
Definition: MSPerson.cpp:454
const MSEdge * getEdge(SUMOTime now) const
Returns the current edge.
Definition: MSPerson.cpp:298
bool operator()(SUMOReal t) const
comparison operator
Definition: MSPerson.h:288
void setVehicle(SUMOVehicle *v)
Definition: MSPerson.h:343
SUMOReal getAngle(SUMOTime now) const
Definition: MSPerson.h:538
bool isWaitingFor(const std::string &line) const
Whether the person waits for a vehicle of the line specified.
Definition: MSPerson.cpp:368
MSPersonStage_Waiting(const MSEdge &destination, SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string &actType)
constructor
Definition: MSPerson.cpp:432
std::string getStageTypeName() const
return string representation of the current stage
Definition: MSPerson.cpp:386
virtual SUMOReal getEdgePos(SUMOTime now) const =0
SUMOReal getAngle(SUMOTime now) const
Definition: MSPerson.cpp:170
MSPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSPersonPlan *plan)
constructor
Definition: MSPerson.cpp:537
virtual void beginEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output.
Definition: MSPerson.cpp:239
virtual Position getPosition(SUMOTime now) const =0
void computeWalkingTime(const MSEdge *const e, SUMOReal fromPos, SUMOReal toPos, MSBusStop *bs)
Definition: MSPerson.cpp:202
SUMOTime timeWaiting4Vehicle(SUMOTime now) const
the time this person spent waiting for a vehicle
Definition: MSPerson.h:582
Structure representing possible vehicle parameter.
virtual void routeOutput(OutputDevice &os) const
Called on writing vehroute output.
Definition: MSPerson.cpp:501
virtual void endEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
Definition: MSPerson.cpp:419
void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:599
SUMOTime myTime
the searched arrival time
Definition: MSPerson.h:294
MSPersonStage_Waiting & operator=(const MSPersonStage_Waiting &)
Invalidated assignment operator.
MSPersonPlan::iterator myStep
the iterator over the route
Definition: MSPerson.h:488
SUMOTime myWalkingTime
the time the person is walking
Definition: MSPerson.h:261
StageType myType
The type of this stage.
Definition: MSPerson.h:170
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Definition: MSPerson.h:242
Position getPosition(SUMOTime now) const
Definition: MSPerson.cpp:323
const MSEdge * getEdge(SUMOTime now) const
Returns the current edge.
Definition: MSPerson.cpp:448
SUMOTime timeWaiting4Vehicle(SUMOTime now) const
time spent waiting for a ride
Definition: MSPerson.cpp:380
bool proceed(MSNet *net, SUMOTime time)
Definition: MSPerson.cpp:559
MSPersonStage_Driving(const MSEdge &destination, MSBusStop *toBS, const std::vector< std::string > &lines)
constructor
Definition: MSPerson.cpp:288
virtual void endEventOutput(const MSPerson &p, SUMOTime t, OutputDevice &os) const
Called for writing the events output (end of an action)
Definition: MSPerson.cpp:525
const MSEdge * getFromEdge() const
Definition: MSPerson.cpp:149
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:221
virtual void proceed(MSNet *net, MSPerson *person, SUMOTime now, MSEdge *previousEdge, const SUMOReal at)
proceeds to the next step
Definition: MSPerson.cpp:348
std::string getStageTypeName() const
return string representation of the current stage
Definition: MSPerson.h:207
const MSEdge & myDestination
the next edge to reach (either by walking or driving)
Definition: MSPerson.h:161
virtual ~MSPersonStage()
destructor
Definition: MSPerson.cpp:66
SUMOReal myDepartPos
A vector of computed times an edge is reached.
Definition: MSPerson.h:272
SUMOVehicle * myVehicle
The taken vehicle.
Definition: MSPerson.h:378
void setArrived(SUMOTime now)
logs end of the step
Definition: MSPerson.cpp:84
std::vector< MSPersonStage * > MSPersonPlan
the structure holding the plan of a person
Definition: MSPerson.h:475
MoveToNextEdge & operator=(const MoveToNextEdge &)
Invalidated assignment operator.
virtual void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
Definition: MSPerson.cpp:219
StageType getStageType() const
Definition: MSPerson.h:100