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