SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00011 // Realises dumping the complete network state 00012 /****************************************************************************/ 00013 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00014 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00015 /****************************************************************************/ 00016 // 00017 // This file is part of SUMO. 00018 // SUMO is free software: you can redistribute it and/or modify 00019 // it under the terms of the GNU General Public License as published by 00020 // the Free Software Foundation, either version 3 of the License, or 00021 // (at your option) any later version. 00022 // 00023 /****************************************************************************/ 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <cassert> 00036 #include <microsim/MSEdgeControl.h> 00037 #include <microsim/MSEdge.h> 00038 #include <microsim/MSLane.h> 00039 #include <microsim/MSNet.h> 00040 #include <microsim/MSVehicle.h> 00041 #include <microsim/MSGlobals.h> 00042 #include <utils/iodevices/OutputDevice.h> 00043 #include "MSXMLRawOut.h" 00044 00045 #ifdef HAVE_MESOSIM 00046 #include <mesosim/MELoop.h> 00047 #include <mesosim/MESegment.h> 00048 #endif 00049 00050 #ifdef CHECK_MEMORY_LEAKS 00051 #include <foreign/nvwa/debug_new.h> 00052 #endif // CHECK_MEMORY_LEAKS 00053 00054 00055 // =========================================================================== 00056 // method definitions 00057 // =========================================================================== 00058 void 00059 MSXMLRawOut::write(OutputDevice& of, const MSEdgeControl& ec, 00060 SUMOTime timestep) { 00061 of.openTag("timestep") << " time=\"" << time2string(timestep) << "\">\n"; 00062 const std::vector<MSEdge*> &edges = ec.getEdges(); 00063 for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) { 00064 writeEdge(of, **e); 00065 } 00066 of.closeTag(); 00067 } 00068 00069 00070 void 00071 MSXMLRawOut::writeEdge(OutputDevice& of, const MSEdge& edge) { 00072 //en 00073 bool dump = !MSGlobals::gOmitEmptyEdgesOnDump; 00074 if (!dump) { 00075 #ifdef HAVE_MESOSIM 00076 if (MSGlobals::gUseMesoSim) { 00077 MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); 00078 while (seg != 0) { 00079 if (seg->getCarNumber() != 0) { 00080 dump = true; 00081 break; 00082 } 00083 seg = seg->getNextSegment(); 00084 } 00085 } else { 00086 #endif 00087 const std::vector<MSLane*> &lanes = edge.getLanes(); 00088 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 00089 if (((**lane).getVehicleNumber() != 0)) { 00090 dump = true; 00091 break; 00092 } 00093 } 00094 #ifdef HAVE_MESOSIM 00095 } 00096 #endif 00097 } 00098 //en 00099 if (dump) { 00100 of.openTag("edge") << " id=\"" << edge.getID() << "\">\n"; 00101 #ifdef HAVE_MESOSIM 00102 if (MSGlobals::gUseMesoSim) { 00103 MESegment* seg = MSGlobals::gMesoNet->getSegmentForEdge(edge); 00104 while (seg != 0) { 00105 seg->writeVehicles(of); 00106 seg = seg->getNextSegment(); 00107 } 00108 } else { 00109 #endif 00110 const std::vector<MSLane*> &lanes = edge.getLanes(); 00111 for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) { 00112 writeLane(of, **lane); 00113 } 00114 #ifdef HAVE_MESOSIM 00115 } 00116 #endif 00117 of.closeTag(); 00118 } 00119 } 00120 00121 00122 void 00123 MSXMLRawOut::writeLane(OutputDevice& of, const MSLane& lane) { 00124 of.openTag("lane") << " id=\"" << lane.myID << "\""; 00125 if (lane.getVehicleNumber() != 0) { 00126 of << ">\n"; 00127 for (std::vector<MSVehicle*>::const_iterator veh = lane.myVehBuffer.begin(); 00128 veh != lane.myVehBuffer.end(); ++veh) { 00129 writeVehicle(of, **veh); 00130 } 00131 for (MSLane::VehCont::const_iterator veh = lane.myVehicles.begin(); 00132 veh != lane.myVehicles.end(); ++veh) { 00133 writeVehicle(of, **veh); 00134 } 00135 } 00136 of.closeTag(lane.getVehicleNumber() == 0); 00137 } 00138 00139 00140 void 00141 MSXMLRawOut::writeVehicle(OutputDevice& of, const MSBaseVehicle& veh) { 00142 if (veh.isOnRoad()) { 00143 of.openTag("vehicle") << " id=\"" << veh.getID() << "\" pos=\"" 00144 << veh.getPositionOnLane() << "\" speed=\"" << veh.getSpeed() << "\""; 00145 of.closeTag(true); 00146 } 00147 } 00148 00149 00150 00151 /****************************************************************************/ 00152