|
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/MSLane.h> 00037 #include <utils/iodevices/OutputDevice.h> 00038 #include <utils/geom/GeoConvHelper.h> 00039 00040 #include "MSVTypeProbe.h" 00041 00042 #ifdef CHECK_MEMORY_LEAKS 00043 #include <foreign/nvwa/debug_new.h> 00044 #endif // CHECK_MEMORY_LEAKS 00045 00046 00047 // =========================================================================== 00048 // method definitions 00049 // =========================================================================== 00050 MSVTypeProbe::MSVTypeProbe(const std::string& id, 00051 const std::string& vType, 00052 OutputDevice& od, SUMOTime frequency) 00053 : Named(id), myVType(vType), myOutputDevice(od), myFrequency(frequency) { 00054 MSNet::getInstance()->getEndOfTimestepEvents().addEvent(this, 0, MSEventControl::ADAPT_AFTER_EXECUTION); 00055 myOutputDevice.writeXMLHeader("vehicle-type-probes"); 00056 } 00057 00058 00059 MSVTypeProbe::~MSVTypeProbe() { 00060 } 00061 00062 00063 SUMOTime 00064 MSVTypeProbe::execute(SUMOTime currentTime) { 00065 const std::string indent(" "); 00066 myOutputDevice << indent << "<timestep time=\"" << time2string(currentTime) << "\" id=\"" << getID() << "\" vType=\"" << myVType << "\">" << "\n"; 00067 MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl(); 00068 MSVehicleControl::constVehIt it = vc.loadedVehBegin(); 00069 MSVehicleControl::constVehIt end = vc.loadedVehEnd(); 00070 for (; it != end; ++it) { 00071 const MSVehicle* veh = static_cast<const MSVehicle*>((*it).second); 00072 if (myVType == "" || myVType == veh->getVehicleType().getID()) { 00073 if (!veh->isOnRoad()) { 00074 continue; 00075 } 00076 Position pos = veh->getLane()->getShape().positionAtLengthPosition(veh->getPositionOnLane()); 00077 myOutputDevice << indent << indent 00078 << "<vehicle id=\"" << veh->getID() 00079 << "\" lane=\"" << veh->getLane()->getID() 00080 << "\" pos=\"" << veh->getPositionOnLane() 00081 << "\" x=\"" << pos.x() 00082 << "\" y=\"" << pos.y(); 00083 if (GeoConvHelper::getFinal().usingGeoProjection()) { 00084 GeoConvHelper::getFinal().cartesian2geo(pos); 00085 myOutputDevice.setPrecision(GEO_OUTPUT_ACCURACY); 00086 myOutputDevice << "\" lat=\"" << pos.y() << "\" lon=\"" << pos.x(); 00087 myOutputDevice.setPrecision(); 00088 } 00089 myOutputDevice << "\" speed=\"" << veh->getSpeed() << "\"/>" << "\n"; 00090 } 00091 00092 } 00093 myOutputDevice << indent << "</timestep>" << "\n"; 00094 return myFrequency; 00095 } 00096 00097 00098 /****************************************************************************/