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.dlr.de/
13 // Copyright (C) 2001-2016 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 
72  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
73  const SUMOVehicle* veh = it->second;
74  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
75  if (myVType == "" || myVType == veh->getVehicleType().getID()) {
76  if (veh->isOnRoad()) {
77  Position pos = veh->getPosition();
80  if (microVeh != 0) {
82  }
88  }
95  }
98  }
99  }
100  }
102  return myFrequency;
103 }
104 
105 
106 /****************************************************************************/
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
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:81
long long int SUMOTime
Definition: SUMOTime.h:43
MSVTypeProbe(const std::string &id, const std::string &vType, OutputDevice &od, SUMOTime frequency)
Constructor.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
#define GEO_OUTPUT_ACCURACY
Definition: config.h:16
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
void setPrecision(int precision=OUTPUT_ACCURACY)
Sets the precison or resets it to default.
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 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:66
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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:307
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
OutputDevice & myOutputDevice
The device to write into.
Definition: MSVTypeProbe.h:100
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
Base class for objects which have an id.
Definition: Named.h:46
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:410
virtual SUMOReal getSpeed() const =0
Returns the vehicle&#39;s current speed.
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.
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
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...
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
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.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
The class responsible for building and deletion of vehicles.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:447
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:649
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.