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-2016 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  if (myPlan != 0) {
102  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
103  delete *i;
104  }
105  delete myPlan;
106  myPlan = 0;
107  }
108  delete myParameter;
109 }
110 
111 const std::string&
113  return myParameter->id;
114 }
115 
116 SUMOTime
118  return myParameter->depart;
119 }
120 
121 void
123  (*myStep)->setDeparted(now);
124 }
125 
126 SUMOReal
128  return (*myStep)->getEdgePos(MSNet::getInstance()->getCurrentTimeStep());
129 }
130 
131 Position
133  return (*myStep)->getPosition(MSNet::getInstance()->getCurrentTimeStep());
134 }
135 
136 SUMOReal
138  return (*myStep)->getAngle(MSNet::getInstance()->getCurrentTimeStep());
139 }
140 
141 SUMOReal
143  return STEPS2TIME((*myStep)->getWaitingTime(MSNet::getInstance()->getCurrentTimeStep()));
144 }
145 
146 SUMOReal
148  return (*myStep)->getSpeed();
149 }
150 
151 
152 void
154  for (MSTransportablePlan::const_iterator i = myPlan->begin(); i != myPlan->end(); ++i) {
155  (*i)->tripInfoOutput(os);
156  }
157 }
158 
159 
160 /****************************************************************************/
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&#39;s lanes.
Definition: MSEdge.h:185
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:160
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:80
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
SUMOTime myArrived
the time at which this stage ended
SUMOTime myDeparted
the time at which this stage started
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&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
virtual ~MSTransportable()
destructor
SUMOTime depart
The vehicle&#39;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:333
virtual Position getPosition() const
Return the Network coordinate of the transportable.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:322
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:213
MSTransportablePlan * myPlan
the plan of the transportable
virtual ~Stage()
destructor
const MSEdge & myDestination
the next edge to reach by getting transported
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
std::string id
The vehicle&#39;s id.