|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Exporter writing networks using the MATSim format 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 #include "NWWriter_MATSim.h" 00030 #include <utils/common/MsgHandler.h> 00031 #include <netbuild/NBEdge.h> 00032 #include <netbuild/NBEdgeCont.h> 00033 #include <netbuild/NBNode.h> 00034 #include <netbuild/NBNodeCont.h> 00035 #include <netbuild/NBNetBuilder.h> 00036 #include <utils/options/OptionsCont.h> 00037 #include <utils/iodevices/OutputDevice.h> 00038 00039 #ifdef CHECK_MEMORY_LEAKS 00040 #include <foreign/nvwa/debug_new.h> 00041 #endif // CHECK_MEMORY_LEAKS 00042 00043 00044 00045 // =========================================================================== 00046 // method definitions 00047 // =========================================================================== 00048 // --------------------------------------------------------------------------- 00049 // static methods 00050 // --------------------------------------------------------------------------- 00051 void 00052 NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) { 00053 // check whether a matsim-file shall be generated 00054 if (!oc.isSet("matsim-output")) { 00055 return; 00056 } 00057 OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output")); 00058 device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 00059 device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n"; 00060 device << "<network name=\"NAME\">\n"; // !!! name 00061 // write nodes 00062 device << " <nodes>\n"; 00063 NBNodeCont& nc = nb.getNodeCont(); 00064 for (std::map<std::string, NBNode*>::const_iterator i=nc.begin(); i!=nc.end(); ++i) { 00065 device << " <node id=\"" << (*i).first 00066 << "\" x=\"" << (*i).second->getPosition().x() 00067 << "\" y=\"" << (*i).second->getPosition().y() 00068 << "\"/>\n"; 00069 } 00070 device << " </nodes>\n"; 00071 // write edges 00072 device << " <links capperiod=\"01:00:00\">\n"; 00073 NBEdgeCont& ec = nb.getEdgeCont(); 00074 for (std::map<std::string, NBEdge*>::const_iterator i=ec.begin(); i!=ec.end(); ++i) { 00075 device << " <link id=\"" << (*i).first 00076 << "\" from=\"" << (*i).second->getFromNode()->getID() 00077 << "\" to=\"" << (*i).second->getToNode()->getID() 00078 << "\" length=\"" << (*i).second->getLoadedLength() 00079 << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm")*(*i).second->getNumLanes()) 00080 << "\" freespeed=\"" << (*i).second->getSpeed() 00081 << "\" permlanes=\"" << (*i).second->getNumLanes() 00082 << "\"/>\n"; 00083 } 00084 device << " </links>\n"; 00085 // 00086 device << "</network>\n"; // !!! name 00087 device.close(); 00088 } 00089 00090 00091 /****************************************************************************/ 00092