SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // Network state mean data collector for edges/lanes 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 00021 00022 00023 // =========================================================================== 00024 // included modules 00025 // =========================================================================== 00026 #ifdef _MSC_VER 00027 #include <windows_config.h> 00028 #else 00029 #include <config.h> 00030 #endif 00031 00032 #include <microsim/MSEdgeControl.h> 00033 #include <microsim/MSEdge.h> 00034 #include <microsim/MSLane.h> 00035 #include <microsim/MSVehicle.h> 00036 #include <utils/common/SUMOTime.h> 00037 #include <utils/common/ToString.h> 00038 #include <utils/iodevices/OutputDevice.h> 00039 #include "MSMeanData_Net.h" 00040 #include <limits> 00041 00042 #ifdef HAVE_MESOSIM 00043 #include <microsim/MSGlobals.h> 00044 #include <mesosim/MELoop.h> 00045 #include <mesosim/MESegment.h> 00046 #endif 00047 00048 #ifdef CHECK_MEMORY_LEAKS 00049 #include <foreign/nvwa/debug_new.h> 00050 #endif // CHECK_MEMORY_LEAKS 00051 00052 00053 // =========================================================================== 00054 // method definitions 00055 // =========================================================================== 00056 // --------------------------------------------------------------------------- 00057 // MSMeanData_Net::MSLaneMeanDataValues - methods 00058 // --------------------------------------------------------------------------- 00059 MSMeanData_Net::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, 00060 const SUMOReal length, 00061 const bool doAdd, 00062 const std::set<std::string>* const vTypes, 00063 const MSMeanData_Net* parent) 00064 : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes), myParent(parent), 00065 nVehDeparted(0), nVehArrived(0), nVehEntered(0), nVehLeft(0), 00066 nVehLaneChangeFrom(0), nVehLaneChangeTo(0), waitSeconds(0), vehLengthSum(0) {} 00067 00068 00069 MSMeanData_Net::MSLaneMeanDataValues::~MSLaneMeanDataValues() { 00070 } 00071 00072 00073 void 00074 MSMeanData_Net::MSLaneMeanDataValues::reset(bool) { 00075 nVehDeparted = 0; 00076 nVehArrived = 0; 00077 nVehEntered = 0; 00078 nVehLeft = 0; 00079 nVehLaneChangeFrom = 0; 00080 nVehLaneChangeTo = 0; 00081 sampleSeconds = 0.; 00082 travelledDistance = 0; 00083 waitSeconds = 0; 00084 vehLengthSum = 0; 00085 } 00086 00087 00088 void 00089 MSMeanData_Net::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const { 00090 MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val; 00091 v.nVehDeparted += nVehDeparted; 00092 v.nVehArrived += nVehArrived; 00093 v.nVehEntered += nVehEntered; 00094 v.nVehLeft += nVehLeft; 00095 v.nVehLaneChangeFrom += nVehLaneChangeFrom; 00096 v.nVehLaneChangeTo += nVehLaneChangeTo; 00097 v.sampleSeconds += sampleSeconds; 00098 v.travelledDistance += travelledDistance; 00099 v.waitSeconds += waitSeconds; 00100 v.vehLengthSum += vehLengthSum; 00101 } 00102 00103 00104 void 00105 MSMeanData_Net::MSLaneMeanDataValues::notifyMoveInternal(SUMOVehicle& veh, SUMOReal timeOnLane, SUMOReal speed) { 00106 sampleSeconds += timeOnLane; 00107 travelledDistance += speed * timeOnLane; 00108 vehLengthSum += veh.getVehicleType().getLength() * timeOnLane; 00109 if (myParent != 0 && speed < myParent->myHaltSpeed) { 00110 waitSeconds += timeOnLane; 00111 } 00112 } 00113 00114 00115 bool 00116 MSMeanData_Net::MSLaneMeanDataValues::notifyLeave(SUMOVehicle& veh, SUMOReal /*lastPos*/, MSMoveReminder::Notification reason) { 00117 if (vehicleApplies(veh) && (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane())) { 00118 #ifdef HAVE_MESOSIM 00119 if (MSGlobals::gUseMesoSim) { 00120 myLastVehicleUpdateValues.erase(&veh); 00121 } 00122 #endif 00123 if (reason == MSMoveReminder::NOTIFICATION_ARRIVED) { 00124 ++nVehArrived; 00125 } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { 00126 ++nVehLaneChangeFrom; 00127 } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { 00128 ++nVehLeft; 00129 } 00130 } 00131 #ifdef HAVE_MESOSIM 00132 if (MSGlobals::gUseMesoSim) { 00133 return false; 00134 } 00135 #endif 00136 return reason == MSMoveReminder::NOTIFICATION_JUNCTION; 00137 } 00138 00139 00140 bool 00141 MSMeanData_Net::MSLaneMeanDataValues::notifyEnter(SUMOVehicle& veh, MSMoveReminder::Notification reason) { 00142 if (vehicleApplies(veh)) { 00143 if (getLane() == 0 || getLane() == static_cast<MSVehicle&>(veh).getLane()) { 00144 if (reason == MSMoveReminder::NOTIFICATION_DEPARTED) { 00145 ++nVehDeparted; 00146 } else if (reason == MSMoveReminder::NOTIFICATION_LANE_CHANGE) { 00147 ++nVehLaneChangeTo; 00148 } else if (myParent == 0 || reason != MSMoveReminder::NOTIFICATION_SEGMENT) { 00149 ++nVehEntered; 00150 } 00151 } 00152 return true; 00153 } 00154 return false; 00155 } 00156 00157 00158 bool 00159 MSMeanData_Net::MSLaneMeanDataValues::isEmpty() const { 00160 return sampleSeconds == 0 && nVehDeparted == 0 && nVehArrived == 0 && nVehEntered == 0 && nVehLeft == 0 && nVehLaneChangeFrom == 0 && nVehLaneChangeTo == 0; 00161 } 00162 00163 00164 void 00165 MSMeanData_Net::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOTime period, 00166 const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles) const { 00167 if (myParent == 0) { 00168 if (sampleSeconds > 0) { 00169 dev << "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength << 00170 "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 << 00171 "\" waitingTime=\"" << waitSeconds << 00172 "\" speed=\"" << travelledDistance / sampleSeconds; 00173 } 00174 dev << "\" departed=\"" << nVehDeparted << 00175 "\" arrived=\"" << nVehArrived << 00176 "\" entered=\"" << nVehEntered << 00177 "\" left=\"" << nVehLeft << "\""; 00178 dev.closeTag(true); 00179 return; 00180 } 00181 if (sampleSeconds > myParent->myMinSamples) { 00182 SUMOReal traveltime = myParent->myMaxTravelTime; 00183 if (travelledDistance > 0.f) { 00184 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance); 00185 } 00186 if (numVehicles > 0) { 00187 dev << "\" traveltime=\"" << sampleSeconds / numVehicles << 00188 "\" waitingTime=\"" << waitSeconds << 00189 "\" speed=\"" << travelledDistance / sampleSeconds; 00190 } else { 00191 dev << "\" traveltime=\"" << traveltime << 00192 "\" density=\"" << sampleSeconds / STEPS2TIME(period) *(SUMOReal) 1000 / myLaneLength << 00193 "\" occupancy=\"" << vehLengthSum / STEPS2TIME(period) / myLaneLength / numLanes *(SUMOReal) 100 << 00194 "\" waitingTime=\"" << waitSeconds << 00195 "\" speed=\"" << travelledDistance / sampleSeconds; 00196 } 00197 } else if (defaultTravelTime >= 0.) { 00198 dev << "\" traveltime=\"" << defaultTravelTime << 00199 "\" speed=\"" << myLaneLength / defaultTravelTime; 00200 } 00201 dev << "\" departed=\"" << nVehDeparted << 00202 "\" arrived=\"" << nVehArrived << 00203 "\" entered=\"" << nVehEntered << 00204 "\" left=\"" << nVehLeft << 00205 "\" laneChangedFrom=\"" << nVehLaneChangeFrom << 00206 "\" laneChangedTo=\"" << nVehLaneChangeTo << "\""; 00207 dev.closeTag(true); 00208 } 00209 00210 // --------------------------------------------------------------------------- 00211 // MSMeanData_Net - methods 00212 // --------------------------------------------------------------------------- 00213 MSMeanData_Net::MSMeanData_Net(const std::string& id, 00214 const SUMOTime dumpBegin, 00215 const SUMOTime dumpEnd, const bool useLanes, 00216 const bool withEmpty, const bool printDefaults, 00217 const bool withInternal, 00218 const bool trackVehicles, 00219 const SUMOReal maxTravelTime, 00220 const SUMOReal minSamples, 00221 const SUMOReal haltSpeed, 00222 const std::set<std::string> vTypes) 00223 : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults, 00224 withInternal, trackVehicles, maxTravelTime, minSamples, vTypes), 00225 myHaltSpeed(haltSpeed) { 00226 } 00227 00228 00229 MSMeanData_Net::~MSMeanData_Net() {} 00230 00231 00232 MSMeanData::MeanDataValues* 00233 MSMeanData_Net::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const { 00234 return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this); 00235 } 00236 00237 00238 /****************************************************************************/ 00239