Eclipse SUMO - Simulation of Urban MObility
MSVTypeProbe.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // Writes positions of vehicles that have a certain (named) type
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
28 #include <microsim/MSNet.h>
29 #include <microsim/MSVehicle.h>
32 #include <microsim/MSLane.h>
35 
36 #include "MSVTypeProbe.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 MSVTypeProbe::MSVTypeProbe(const std::string& id,
43  const std::string& vType,
44  OutputDevice& od, SUMOTime frequency)
45  : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) {
47  myOutputDevice.writeXMLHeader("vehicle-type-probes", "vtypeprobe_file.xsd");
48 }
49 
50 
52 }
53 
54 
62  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
63  const SUMOVehicle* veh = it->second;
64  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
65  if (myVType == "" || myVType == veh->getVehicleType().getID()) {
66  if (veh->isOnRoad()) {
67  Position pos = veh->getPosition();
70  if (microVeh != nullptr) {
72  }
78  }
85  }
88  }
89  }
90  }
92  return myFrequency;
93 }
94 
95 
96 /****************************************************************************/
SUMOTrafficObject::getPosition
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:52
MSNet.h
Named
Base class for objects which have an id.
Definition: Named.h:56
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
Position::z
double z() const
Returns the z-position.
Definition: Position.h:66
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
WrappingCommand.h
SUMO_ATTR_Z
Definition: SUMOXMLDefinitions.h:400
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
GeoConvHelper.h
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
SUMO_ATTR_SPEED
Definition: SUMOXMLDefinitions.h:384
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMO_ATTR_LANE
Definition: SUMOXMLDefinitions.h:637
MSVTypeProbe.h
GeoConvHelper::usingGeoProjection
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
Definition: GeoConvHelper.cpp:281
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:74
gPrecisionGeo
int gPrecisionGeo
Definition: StdDefs.cpp:27
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
MSVTypeProbe::myFrequency
SUMOTime myFrequency
The frequency of reporting.
Definition: MSVTypeProbe.h:95
MSVTypeProbe::execute
SUMOTime execute(SUMOTime currentTime)
Writes values into the given stream.
Definition: MSVTypeProbe.cpp:56
GeoConvHelper::getFinal
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
Definition: GeoConvHelper.h:105
MSNet::getEndOfTimestepEvents
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:439
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:185
OutputDevice.h
GeoConvHelper::cartesian2geo
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Definition: GeoConvHelper.cpp:293
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
SUMO_ATTR_Y
Definition: SUMOXMLDefinitions.h:399
MSVTypeProbe::myVType
std::string myVType
The id of the vehicle type vehicles must have to be reported.
Definition: MSVTypeProbe.h:89
MSNet::hasElevation
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:648
SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:119
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:676
MSVTypeProbe::~MSVTypeProbe
virtual ~MSVTypeProbe()
Destructor.
Definition: MSVTypeProbe.cpp:51
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:660
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
MSVTypeProbe::myOutputDevice
OutputDevice & myOutputDevice
The device to write into.
Definition: MSVTypeProbe.h:92
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
SUMO_TAG_TIMESTEP
Definition: SUMOXMLDefinitions.h:320
SUMO_ATTR_LAT
Definition: SUMOXMLDefinitions.h:815
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
MSEventControl.h
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:177
MSLane.h
OutputDevice::writeXMLHeader
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Definition: OutputDevice.cpp:227
SUMO_ATTR_LON
Definition: SUMOXMLDefinitions.h:814
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMO_ATTR_X
Definition: SUMOXMLDefinitions.h:398
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
MSVTypeProbe::MSVTypeProbe
MSVTypeProbe(const std::string &id, const std::string &vType, OutputDevice &od, SUMOTime frequency)
Constructor.
Definition: MSVTypeProbe.cpp:42
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79