SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_Tripinfo.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device which collects info on the vehicle trip
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 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 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSVehicle.h>
37 #include "MSDevice_Tripinfo.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 // ---------------------------------------------------------------------------
48 // static initialisation methods
49 // ---------------------------------------------------------------------------
50 void
51 MSDevice_Tripinfo::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
52  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
53  MSDevice_Tripinfo* device = new MSDevice_Tripinfo(v, "tripinfo_" + v.getID());
54  into.push_back(device);
55  }
56 }
57 
58 
59 // ---------------------------------------------------------------------------
60 // MSDevice_Tripinfo-methods
61 // ---------------------------------------------------------------------------
62 MSDevice_Tripinfo::MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id)
63  : MSDevice(holder, id), myDepartLane(""), myDepartPos(-1), myDepartSpeed(-1),
64  myWaitingSteps(0), myArrivalTime(-1), myArrivalLane(""), myArrivalPos(-1), myArrivalSpeed(-1) {
65 }
66 
67 
69 }
70 
71 
72 bool
74  SUMOReal /*newPos*/, SUMOReal newSpeed) {
75  if (newSpeed <= SUMO_const_haltingSpeed) {
77  }
78  return true;
79 }
80 
81 
82 bool
86  myDepartLane = static_cast<MSVehicle&>(veh).getLane()->getID();
87  }
89  myDepartSpeed = veh.getSpeed();
90  }
91  return true;
92 }
93 
94 
95 bool
100  if (!MSGlobals::gUseMesoSim) {
101  myArrivalLane = static_cast<MSVehicle&>(veh).getLane()->getID();
102  }
103  // @note vehicle may have moved past its arrivalPos during the last step
104  // due to non-zero arrivalspeed but we consider it as arrived at the desired position
106  myArrivalSpeed = veh.getSpeed();
107  }
108  return true;
109 }
110 
111 
112 void
114  SUMOReal routeLength = myHolder.getRoute().getLength();
115  // write
116  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
117  os.openTag("tripinfo").writeAttr("id", myHolder.getID());
118  routeLength -= myDepartPos;
119  os.writeAttr("depart", time2string(myHolder.getDeparture())).writeAttr("departLane", myDepartLane)
120  .writeAttr("departPos", myDepartPos).writeAttr("departSpeed", myDepartSpeed)
122  if (myArrivalLane != "") {
123  routeLength -= MSLane::dictionary(myArrivalLane)->getLength() - myArrivalPos;
124  }
125  os.writeAttr("arrival", time2string(myArrivalTime)).writeAttr("arrivalLane", myArrivalLane)
126  .writeAttr("arrivalPos", myArrivalPos).writeAttr("arrivalSpeed", myArrivalSpeed)
128  .writeAttr("routeLength", routeLength).writeAttr("waitSteps", myWaitingSteps)
129  .writeAttr("rerouteNo", myHolder.getNumberReroutes());
130  const std::vector<MSDevice*>& devices = myHolder.getDevices();
131  std::ostringstream str;
132  for (std::vector<MSDevice*>::const_iterator i = devices.begin(); i != devices.end(); ++i) {
133  if (i != devices.begin()) {
134  str << ' ';
135  }
136  str << (*i)->getID();
137  }
138  os.writeAttr("devices", str.str()).writeAttr("vType", myHolder.getVehicleType().getID())
139  .writeAttr("vaporized", (myHolder.getEdge() == *(myHolder.getRoute().end() - 1) ? "" : "0"));
140 }
141 
142 
143 /****************************************************************************/
144 
SUMOTime myArrivalTime
The vehicle's arrival time.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
virtual const MSRoute & getRoute() const =0
Returns the current route.
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
SUMOVehicle & myHolder
The vehicle that stores the device.
Definition: MSDevice.h:152
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle's position along the lane.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
void generateOutput() const
Called on writing tripinfo output.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
SUMOReal myArrivalPos
The position on the lane the vehicle arrived at.
~MSDevice_Tripinfo()
Destructor.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:210
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks for waiting steps when the vehicle moves.
const MSLane * getLane() const
Returns the lane the reminder works on.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
SUMOReal myDepartSpeed
The speed on departure.
SUMOReal myArrivalSpeed
The speed when arriving.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason)
Saves departure info on insertion.
virtual const std::vector< MSDevice * > & getDevices() const =0
Returns this vehicle's devices.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
unsigned int myWaitingSteps
The overall number of waiting steps.
The vehicle arrived at its destination (is deleted)
SUMOTime depart
The vehicle's departure time.
SUMOReal myDepartPos
The position on the lane the vehicle departed at.
SUMOReal getLength() const
Definition: MSRoute.cpp:254
std::string myDepartLane
The lane the vehicle departed at.
Abstract in-vehicle device.
Definition: MSDevice.h:68
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:829
The vehicle has departed (was inserted into the network)
virtual SUMOReal getSpeed() const =0
Returns the vehicle's current speed.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition: MSRoute.cpp:80
std::string myArrivalLane
The lane the vehicle arrived at.
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
virtual const SUMOVehicleParameter & getParameter() const =0
Returns the vehicle's parameter (including departure definition)
MSDevice_Tripinfo()
dummy constructor
const SUMOReal SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:53
const std::string & getID() const
Returns the name of the vehicle type.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, MSMoveReminder::Notification reason)
Saves arrival info.
#define SUMOReal
Definition: config.h:215
static const bool gUseMesoSim
Definition: MSGlobals.h:98
virtual SUMOReal getArrivalPos() const =0
Returns this vehicle's desired arrivalPos for its current route (may change on reroute) ...
virtual unsigned int getNumberReroutes() const =0
Returns the number of new routes this vehicle got.
virtual const std::string & getID() const =0
Get the vehicle's ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.