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