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