Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file NWWriter_MATSim.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @date Tue, 04.05.2011 18 : /// 19 : // Exporter writing networks using the MATSim format 20 : /****************************************************************************/ 21 : #include <config.h> 22 : #include "NWWriter_MATSim.h" 23 : #include <utils/common/MsgHandler.h> 24 : #include <netbuild/NBEdge.h> 25 : #include <netbuild/NBEdgeCont.h> 26 : #include <netbuild/NBNode.h> 27 : #include <netbuild/NBNodeCont.h> 28 : #include <netbuild/NBNetBuilder.h> 29 : #include <utils/options/OptionsCont.h> 30 : #include <utils/iodevices/OutputDevice.h> 31 : 32 : 33 : 34 : // =========================================================================== 35 : // method definitions 36 : // =========================================================================== 37 : // --------------------------------------------------------------------------- 38 : // static methods 39 : // --------------------------------------------------------------------------- 40 : void 41 1830 : NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) { 42 : // check whether a matsim-file shall be generated 43 3660 : if (!oc.isSet("matsim-output")) { 44 : return; 45 : } 46 6 : OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output")); 47 3 : device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; 48 3 : device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n"; 49 3 : device << "<network name=\"NAME\">\n"; // !!! name 50 : // write nodes 51 3 : device << " <nodes>\n"; 52 : NBNodeCont& nc = nb.getNodeCont(); 53 168 : for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) { 54 165 : device << " <node id=\"" << (*i).first 55 165 : << "\" x=\"" << (*i).second->getPosition().x() 56 330 : << "\" y=\"" << (*i).second->getPosition().y() 57 165 : << "\"/>\n"; 58 : } 59 3 : device << " </nodes>\n"; 60 : // write edges 61 3 : device << " <links capperiod=\"01:00:00\">\n"; 62 : NBEdgeCont& ec = nb.getEdgeCont(); 63 408 : for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) { 64 405 : device << " <link id=\"" << (*i).first 65 405 : << "\" from=\"" << (*i).second->getFromNode()->getID() 66 405 : << "\" to=\"" << (*i).second->getToNode()->getID() 67 787 : << "\" length=\"" << (*i).second->getLoadedLength() 68 810 : << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes()) 69 405 : << "\" freespeed=\"" << (*i).second->getSpeed() 70 810 : << "\" permlanes=\"" << (*i).second->getNumLanes() 71 405 : << "\"/>\n"; 72 : } 73 3 : device << " </links>\n"; 74 : // 75 3 : device << "</network>\n"; // !!! name 76 3 : device.close(); 77 : } 78 : 79 : 80 : /****************************************************************************/