SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 /****************************************************************************/