SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Writes route distributions at a certain edge 00010 /****************************************************************************/ 00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00013 /****************************************************************************/ 00014 // 00015 // This file is part of SUMO. 00016 // SUMO is free software: you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation, either version 3 of the License, or 00019 // (at your option) any later version. 00020 // 00021 /****************************************************************************/ 00022 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <string> 00034 #include <microsim/MSEdge.h> 00035 #include <microsim/MSLane.h> 00036 #include <microsim/MSGlobals.h> 00037 #include <microsim/MSRoute.h> 00038 #include <microsim/MSVehicle.h> 00039 #include <utils/common/ToString.h> 00040 #include <utils/iodevices/OutputDevice.h> 00041 #ifdef HAVE_MESOSIM 00042 #include <mesosim/MELoop.h> 00043 #include <mesosim/MESegment.h> 00044 #endif 00045 #include "MSRouteProbe.h" 00046 00047 #ifdef CHECK_MEMORY_LEAKS 00048 #include <foreign/nvwa/debug_new.h> 00049 #endif // CHECK_MEMORY_LEAKS 00050 00051 00052 // =========================================================================== 00053 // method definitions 00054 // =========================================================================== 00055 MSRouteProbe::MSRouteProbe(const std::string& id, const MSEdge* edge, SUMOTime begin) 00056 : MSDetectorFileOutput(id), myCurrentRouteDistribution(0) { 00057 const std::string distID = id + "_" + toString(begin); 00058 myCurrentRouteDistribution = MSRoute::distDictionary(distID); 00059 if (myCurrentRouteDistribution == 0) { 00060 myCurrentRouteDistribution = new RandomDistributor<const MSRoute*>(); 00061 MSRoute::dictionary(distID, myCurrentRouteDistribution); 00062 } 00063 #ifdef HAVE_MESOSIM 00064 if (MSGlobals::gUseMesoSim) { 00065 MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(*edge); 00066 while (seg != 0) { 00067 seg->addDetector(this); 00068 seg = seg->getNextSegment(); 00069 } 00070 return; 00071 } 00072 #endif 00073 for (std::vector<MSLane*>::const_iterator it = edge->getLanes().begin(); it != edge->getLanes().end(); ++it) { 00074 (*it)->addMoveReminder(this); 00075 } 00076 } 00077 00078 00079 MSRouteProbe::~MSRouteProbe() { 00080 } 00081 00082 00083 bool 00084 MSRouteProbe::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) { 00085 if (myCurrentRouteDistribution != 0 && reason != MSMoveReminder::NOTIFICATION_SEGMENT && reason != MSMoveReminder::NOTIFICATION_LANE_CHANGE) { 00086 veh.getRoute().addReference(); 00087 myCurrentRouteDistribution->add(1., &veh.getRoute()); 00088 } 00089 return false; 00090 } 00091 00092 00093 void 00094 MSRouteProbe::writeXMLOutput(OutputDevice& dev, 00095 SUMOTime startTime, SUMOTime stopTime) { 00096 if (myCurrentRouteDistribution->getOverallProb() > 0) { 00097 dev.openTag("routeDistribution") << " id=\"" << getID() + "_" + time2string(startTime) << "\">\n"; 00098 const std::vector<const MSRoute*> &routes = myCurrentRouteDistribution->getVals(); 00099 const std::vector<SUMOReal> &probs = myCurrentRouteDistribution->getProbs(); 00100 for (unsigned int j = 0; j < routes.size(); ++j) { 00101 const MSRoute* r = routes[j]; 00102 dev.openTag("route") << " id=\"" << r->getID() + "_" + time2string(startTime) << "\" edges=\""; 00103 for (MSRouteIterator i = r->begin(); i != r->end(); ++i) { 00104 if (i != r->begin()) { 00105 dev << " "; 00106 } 00107 dev << (*i)->getID(); 00108 } 00109 dev << "\" probability=\"" << probs[j] << "\""; 00110 dev.closeTag(true); 00111 } 00112 dev.closeTag(); 00113 myCurrentRouteDistribution = new RandomDistributor<const MSRoute*>(); 00114 MSRoute::dictionary(getID() + "_" + toString(stopTime), myCurrentRouteDistribution); 00115 } 00116 } 00117 00118 00119 void 00120 MSRouteProbe::writeXMLDetectorProlog(OutputDevice& dev) const { 00121 dev.writeXMLHeader("route-probes"); 00122 }