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-2018 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 /****************************************************************************/
18 // Writes positions of vehicles that have a certain (named) type
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSVehicle.h>
33 #include <microsim/MSLane.h>
36 
37 #include "MSVTypeProbe.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 MSVTypeProbe::MSVTypeProbe(const std::string& id,
44  const std::string& vType,
45  OutputDevice& od, SUMOTime frequency)
46  : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) {
48  myOutputDevice.writeXMLHeader("vehicle-type-probes", "vtypeprobe_file.xsd");
49 }
50 
51 
53 }
54 
55 
63  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
64  const SUMOVehicle* veh = it->second;
65  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
66  if (myVType == "" || myVType == veh->getVehicleType().getID()) {
67  if (veh->isOnRoad()) {
68  Position pos = veh->getPosition();
71  if (microVeh != nullptr) {
73  }
79  }
86  }
89  }
90  }
91  }
93  return myFrequency;
94 }
95 
96 
97 /****************************************************************************/
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:79
long long int SUMOTime
Definition: SUMOTime.h:36
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double z() const
Returns the z-position.
Definition: Position.h:67
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
MSVTypeProbe(const std::string &id, const std::string &vType, OutputDevice &od, SUMOTime frequency)
Constructor.
double y() const
Returns the y-position.
Definition: Position.h:62
bool usingGeoProjection() const
Returns whether a transformation from geo to metric coordinates will be performed.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
SUMOTime myFrequency
The frequency of reporting.
Definition: MSVTypeProbe.h:96
const std::string & getID() const
Returns the id.
Definition: Named.h:78
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
SUMOTime execute(SUMOTime currentTime)
Writes values into the given stream.
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.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
int gPrecisionGeo
Definition: StdDefs.cpp:28
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:316
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
OutputDevice & myOutputDevice
The device to write into.
Definition: MSVTypeProbe.h:93
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
bool hasElevation() const
return whether the network contains elevation data
Definition: MSNet.h:610
Base class for objects which have an id.
Definition: Named.h:58
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:419
trigger: the time of the step
std::string myVType
The id of the vehicle type vehicles must have to be reported.
Definition: MSVTypeProbe.h:90
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
virtual ~MSVTypeProbe()
Destructor.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
description of a vehicle
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
The class responsible for building and deletion of vehicles.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.