SUMO - Simulation of Urban MObility
MSVTypeProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Writes positions of vehicles that have a certain (named) type
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 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 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <string>
36 #include <microsim/MSNet.h>
37 #include <microsim/MSVehicle.h>
38 #include <microsim/MSLane.h>
41 
42 #include "MSVTypeProbe.h"
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 MSVTypeProbe::MSVTypeProbe(const std::string& id,
53  const std::string& vType,
54  OutputDevice& od, SUMOTime frequency)
55  : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) {
57  myOutputDevice.writeXMLHeader("vehicle-type-probes");
58 }
59 
60 
62 }
63 
64 
67  myOutputDevice.openTag("timestep") << " time=\"" << time2string(currentTime) << "\" id=\"" << getID() << "\" vType=\"" << myVType << "\"";
71  for (; it != end; ++it) {
72  const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second);
73  if (myVType == "" || myVType == veh->getVehicleType().getID()) {
74  if (!veh->isOnRoad()) {
75  continue;
76  }
78  myOutputDevice.openTag("vehicle") << " id=\"" << veh->getID()
79  << "\" lane=\"" << veh->getLane()->getID()
80  << "\" pos=\"" << veh->getPositionOnLane()
81  << "\" x=\"" << pos.x()
82  << "\" y=\"" << pos.y();
83  if (GeoConvHelper::getFinal().usingGeoProjection()) {
86  myOutputDevice << "\" lat=\"" << pos.y() << "\" lon=\"" << pos.x();
88  }
89  myOutputDevice << "\" speed=\"" << veh->getSpeed() << "\"";
91  }
92 
93  }
95  return myFrequency;
96 }
97 
98 
99 /****************************************************************************/
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
MSEventControl & getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:350
MSVTypeProbe(const std::string &id, const std::string &vType, OutputDevice &od, SUMOTime frequency)
Constructor.
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
SUMOTime myFrequency
The frequency of reporting.
Definition: MSVTypeProbe.h:103
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
Definition: MSVehicle.h:283
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
bool writeXMLHeader(const std::string &rootElement, const std::string &attrs="", const std::string &comment="")
Writes an XML header with optional configuration.
const std::string & getID() const
Returns the id.
Definition: Named.h:60
void setPrecision(unsigned int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
SUMOTime execute(SUMOTime currentTime)
Writes values into the given stream.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:269
OutputDevice & myOutputDevice
The device to write into.
Definition: MSVTypeProbe.h:100
Position positionAtOffset(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
Base class for objects which have an id.
Definition: Named.h:45
std::string myVType
The id of the vehicle type vehicles must have to be reported.
Definition: MSVTypeProbe.h:97
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
virtual ~MSVTypeProbe()
Destructor.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:95
const std::string & getID() const
Returns the name of the vehicle type.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
int SUMOTime
Definition: SUMOTime.h:43
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:323
Patch the time in a way that it is at least as high as the simulation begin time. ...
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
The class responsible for building and deletion of vehicles.
bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
Definition: MSVehicle.h:336
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const std::string & getID() const
Returns the name of the vehicle.