SUMO - Simulation of Urban MObility
MSTransportable.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The common superclass for modelling transportable objects like persons and containers
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include "MSEdge.h"
35 #include "MSLane.h"
36 #include "MSTransportable.h"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 /* -------------------------------------------------------------------------
46  * MSTransportable::Stage - methods
47  * ----------------------------------------------------------------------- */
48 MSTransportable::Stage::Stage(const MSEdge& destination, MSStoppingPlace* toStop, const SUMOReal arrivalPos, StageType type)
49  : myDestination(destination), myDestinationStop(toStop), myArrivalPos(arrivalPos), myDeparted(-1), myArrived(-1), myType(type) {}
50 
52 
53 const MSEdge&
55  return myDestination;
56 }
57 
58 
59 void
61  if (myDeparted < 0) {
62  myDeparted = now;
63  }
64 }
65 
66 void
68  myArrived = now;
69 }
70 
71 bool
72 MSTransportable::Stage::isWaitingFor(const std::string& /*line*/) const {
73  return false;
74 }
75 
78  return getLanePosition(e->getLanes()[0], at, offset);
79 }
80 
83  return lane->getShape().positionAtOffset(lane->interpolateLanePosToGeometryPos(at), offset);
84 }
85 
88  return e->getLanes()[0]->getShape().rotationAtOffset(at);
89 }
90 
91 
92 /* -------------------------------------------------------------------------
93  * MSTransportable - methods
94  * ----------------------------------------------------------------------- */
96  : myParameter(pars), myVType(vtype), myPlan(plan) {
97  myStep = myPlan->begin();
98 }
99 
101  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
102  delete *i;
103  }
104  delete myPlan;
105  delete myParameter;
106 }
107 
108 const std::string&
110  return myParameter->id;
111 }
112 
113 SUMOTime
115  return myParameter->depart;
116 }
117 
118 void
120  (*myStep)->setDeparted(now);
121 }
122 
123 SUMOReal
125  return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
126 }
127 
128 Position
130  return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
131 }
132 
133 SUMOReal
135  return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
136 }
137 
138 SUMOReal
140  return STEPS2TIME((*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep()));
141 }
142 
143 SUMOReal
145  return (*myStep)->getSpeed();
146 }
147 
148 
149 void
151  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
152  (*i)->tripInfoOutput(os);
153  }
154 }
155 
156 
157 /****************************************************************************/
void setArrived(SUMOTime now)
logs end of the step
long long int SUMOTime
Definition: SUMOTime.h:43
void tripInfoOutput(OutputDevice &os) const
Called on writing tripinfo output.
A lane area vehicles can halt at.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:186
Stage(const MSEdge &destination, MSStoppingPlace *toStop, const SUMOReal arrivalPos, StageType type)
constructor
virtual SUMOReal getWaitingSeconds() const
the time this transportable spent waiting in seconds
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:162
const std::string & getID() const
returns the id of the transportable
virtual SUMOReal getEdgePos() const
Return the position on the edge.
MSTransportablePlan::iterator myStep
the iterator over the route
virtual SUMOReal getAngle() const
return the current angle of the transportable
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:255
MSTransportable(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportablePlan *plan)
constructor
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
get angle of the edge at a certain position
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOTime getDesiredDepart() const
Returns the desired departure time.
const SUMOVehicleParameter * myParameter
the plan of the transportable
const MSEdge & getDestination() const
returns the destination edge
A road/street connecting two junctions.
Definition: MSEdge.h:81
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
Position getLanePosition(const MSLane *lane, SUMOReal at, SUMOReal offset) const
get position on lane at length at with orthogonal offset
Position getEdgePosition(const MSEdge *e, SUMOReal at, SUMOReal offset) const
get position on edge e at length at with orthogonal offset
void setDeparted(SUMOTime now)
logs depart time of the current stage
virtual bool isWaitingFor(const std::string &line) const
Whether the transportable waits for a vehicle of the line specified.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
const MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
virtual ~MSTransportable()
destructor
SUMOTime depart
The vehicle's departure time.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
virtual SUMOReal getSpeed() const
the current speed of the transportable
Structure representing possible vehicle parameter.
SUMOReal interpolateLanePosToGeometryPos(SUMOReal lanePos) const
Definition: MSLane.h:334
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
void setDeparted(SUMOTime now)
logs end of the step
#define SUMOReal
Definition: config.h:215
MSTransportablePlan * myPlan
the plan of the transportable
virtual ~Stage()
destructor
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
std::string id
The vehicle's id.