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.sourceforge.net/
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 {
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  Position getEdgePosition(const MSEdge* e, SUMOReal at, SUMOReal offset) const;
126 
127  SUMOReal getEdgeAngle(const MSEdge* e, SUMOReal at) const;
128 
133  virtual void tripInfoOutput(OutputDevice& os) const = 0;
134 
139  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const = 0;
140 
145  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const = 0;
146 
147 
148  protected:
151 
154 
157 
160 
161  private:
164 
167 
168  };
169 
176  public:
178  MSPersonStage_Walking(const std::vector<const MSEdge*>& route, MSBusStop* toBS, SUMOTime walkingTime, SUMOReal speed, SUMOReal departPos, SUMOReal arrivalPos);
179 
182 
184  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
185 
187  const MSEdge* getEdge(SUMOTime now) const;
188  const MSEdge* getFromEdge() const;
189  SUMOReal getEdgePos(SUMOTime now) const;
190 
192  Position getPosition(SUMOTime now) const;
193 
194  SUMOReal getAngle(SUMOTime now) const;
195 
196  std::string getStageTypeName() const {
197  return "walking";
198  }
199 
204  virtual void tripInfoOutput(OutputDevice& os) const;
205 
210  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
211 
216  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
217 
218  SUMOTime moveToNextEdge(MSPerson* person, SUMOTime currentTime);
219 
220 
221  class MoveToNextEdge : public Command {
222  public:
223  MoveToNextEdge(MSPerson* person, MSPersonStage_Walking& walk) : myParent(walk), myPerson(person) {}
225  SUMOTime execute(SUMOTime currentTime) {
226  return myParent.moveToNextEdge(myPerson, currentTime);
227  }
228  private:
231  private:
234 
235  };
236 
237 
238  private:
239  void computeWalkingTime(const MSEdge* const e, SUMOReal fromPos, SUMOReal toPos, MSBusStop* bs);
240  bool checkNoDuration(MSNet* net, MSPerson* person, SUMOTime duration, SUMOTime now);
241 
242 
243  private:
246 
248  std::vector<const MSEdge*> myRoute;
249 
250 
251  std::vector<const MSEdge*>::iterator myRouteStep;
252 
254  //std::vector<SUMOTime> myArrivalTimes;
255 
261 
263  //bool myDurationWasGiven;
264  //SUMOReal myOverallLength;
265 
267  public:
269  explicit arrival_finder(SUMOTime time) : myTime(time) {}
270 
272  bool operator()(SUMOReal t) const {
273  return myTime > t;
274  }
275 
276  private:
279  };
280 
281  private:
284 
287 
288  };
289 
295  public:
297  MSPersonStage_Driving(const MSEdge& destination, MSBusStop* toBS,
298  const std::vector<std::string>& lines);
299 
302 
304  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
305 
307  const MSEdge* getEdge(SUMOTime now) const;
308  const MSEdge* getFromEdge() const;
309  SUMOReal getEdgePos(SUMOTime now) const;
310 
312  Position getPosition(SUMOTime now) const;
313 
314  SUMOReal getAngle(SUMOTime now) const;
315 
316  std::string getStageTypeName() const;
317 
319  bool isWaitingFor(const std::string& line) const;
320 
322  bool isWaiting4Vehicle() const;
323 
325  myVehicle = v;
326  }
327 
333  virtual void tripInfoOutput(OutputDevice& os) const;
334 
339  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
340 
345  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
346 
347  private:
349  const std::set<std::string> myLines;
350 
353 
355  //Position myWaitingPos;
358 
359  private:
362 
365 
366  };
367 
372  public:
374  MSPersonStage_Waiting(const MSEdge& destination,
375  SUMOTime duration, SUMOTime until, SUMOReal pos, const std::string& actType);
376 
379 
381  const MSEdge* getEdge(SUMOTime now) const;
382  const MSEdge* getFromEdge() const;
383  SUMOReal getEdgePos(SUMOTime now) const;
384 
386  Position getPosition(SUMOTime now) const;
387 
388  SUMOReal getAngle(SUMOTime now) const;
389 
390  std::string getStageTypeName() const {
391  return "waiting (" + myActType + ")";
392  }
393 
395  virtual void proceed(MSNet* net, MSPerson* person, SUMOTime now, MSEdge* previousEdge, const SUMOReal at);
396 
402  virtual void tripInfoOutput(OutputDevice& os) const;
403 
408  virtual void beginEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
409 
414  virtual void endEventOutput(const MSPerson& p, SUMOTime t, OutputDevice& os) const;
415 
416  private:
419 
422 
424  std::string myActType;
425 
427 
428 
429  private:
432 
435 
436  };
437 
438 public:
440  typedef std::vector<MSPersonStage*> MSPersonPlan;
441 
442 protected:
445 
448 
451 
453  MSPersonPlan::iterator myStep;
454 
457 
458 public:
460  MSPerson(const SUMOVehicleParameter* pars, const MSVehicleType* vtype, MSPersonPlan* plan);
461 
463  virtual ~MSPerson();
464 
466  const std::string& getID() const;
467 
468  /* @brief proceeds to the next step of the route,
469  * @return Whether the persons plan continues */
470  bool proceed(MSNet* net, SUMOTime time);
471 
473  SUMOTime getDesiredDepart() const;
474 
476  void setDeparted(SUMOTime now);
477 
479  const MSEdge& getDestination() const {
480  return (*myStep)->getDestination();
481  }
482 
484  const MSEdge* getEdge(SUMOTime now) const {
485  return (*myStep)->getEdge(now);
486  }
487 
489  const MSEdge* getFromEdge() const {
490  return (*myStep)->getFromEdge();
491  }
492 
494  return (*myStep)->getEdgePos(now);
495  }
496 
498  virtual Position getPosition(SUMOTime now) const {
499  return (*myStep)->getPosition(now);
500  }
501 
502 
504  return (*myStep)->getAngle(now);
505  }
506 
509  return (*myStep)->getStageType();
510  }
511 
512 
513  std::string getCurrentStageTypeName() const {
514  return (*myStep)->getStageTypeName();
515  }
516 
518  return *myStep;
519  }
520 
526  void tripInfoOutput(OutputDevice& os) const;
527 
529  bool isWaitingFor(const std::string& line) const {
530  return (*myStep)->isWaitingFor(line);
531  }
532 
534  bool isWaiting4Vehicle() const {
535  return (*myStep)->isWaiting4Vehicle();
536  }
537 
539  return *myParameter;
540  }
541 
542 
543  inline const MSVehicleType& getVehicleType() const {
544  return *myVType;
545  }
546 
547 
549  static const SUMOReal SIDEWALK_OFFSET;
550 
551 private:
553  MSPerson(const MSPerson&);
554 
556  MSPerson& operator=(const MSPerson&);
557 
558 };
559 
560 
561 #endif
562 
563 /****************************************************************************/