SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // Writes positions of vehicles that have a certain (named) type 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 00024 00025 // =========================================================================== 00026 // included modules 00027 // =========================================================================== 00028 #ifdef _MSC_VER 00029 #include <windows_config.h> 00030 #else 00031 #include <config.h> 00032 #endif 00033 00034 #include <string> 00035 #include <utils/common/WrappingCommand.h> 00036 #include <microsim/MSNet.h> 00037 #include <microsim/MSVehicle.h> 00038 #include <microsim/MSLane.h> 00039 #include <utils/iodevices/OutputDevice.h> 00040 #include <utils/geom/GeoConvHelper.h> 00041 00042 #include "MSVTypeProbe.h" 00043 00044 #ifdef CHECK_MEMORY_LEAKS 00045 #include <foreign/nvwa/debug_new.h> 00046 #endif // CHECK_MEMORY_LEAKS 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 MSVTypeProbe::MSVTypeProbe(const std::string& id, 00053 const std::string& vType, 00054 OutputDevice& od, SUMOTime frequency) 00055 : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) { 00056 MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 0, MSEventControl::ADAPT_AFTER_EXECUTION); 00057 myOutputDevice.writeXMLHeader("vehicle-type-probes"); 00058 } 00059 00060 00061 MSVTypeProbe::~MSVTypeProbe() { 00062 } 00063 00064 00065 SUMOTime 00066 MSVTypeProbe::execute(SUMOTime currentTime) { 00067 const std::string indent(" "); 00068 myOutputDevice << indent << "<timestep time=\"" << time2string(currentTime) << "\" id=\"" << getID() << "\" vType=\"" << myVType << "\">" << "\n"; 00069 MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl(); 00070 MSVehicleControl::constVehIt it = vc.loadedVehBegin(); 00071 MSVehicleControl::constVehIt end = vc.loadedVehEnd(); 00072 for (; it != end; ++it) { 00073 const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second); 00074 if (myVType == "" || myVType == veh->getVehicleType().getID()) { 00075 if (!veh->isOnRoad()) { 00076 continue; 00077 } 00078 Position pos = veh->getLane()->getShape().positionAtLengthPosition(veh->getPositionOnLane()); 00079 myOutputDevice << indent << indent 00080 << "<vehicle id=\"" << veh->getID() 00081 << "\" lane=\"" << veh->getLane()->getID() 00082 << "\" pos=\"" << veh->getPositionOnLane() 00083 << "\" x=\"" << pos.x() 00084 << "\" y=\"" << pos.y(); 00085 if (GeoConvHelper::getFinal().usingGeoProjection()) { 00086 GeoConvHelper::getFinal().cartesian2geo(pos); 00087 myOutputDevice.setPrecision(GEO_OUTPUT_ACCURACY); 00088 myOutputDevice << "\" lat=\"" << pos.y() << "\" lon=\"" << pos.x(); 00089 myOutputDevice.setPrecision(); 00090 } 00091 myOutputDevice << "\" speed=\"" << veh->getSpeed() << "\"/>" << "\n"; 00092 } 00093 00094 } 00095 myOutputDevice << indent << "</timestep>" << "\n"; 00096 return myFrequency; 00097 } 00098 00099 00100 /****************************************************************************/