LCOV - code coverage report
Current view: top level - src/netwrite - NWWriter_MATSim.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 26 26
Test Date: 2024-11-22 15:46:21 Functions: 100.0 % 1 1

            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         1689 : NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
      42              :     // check whether a matsim-file shall be generated
      43         3378 :     if (!oc.isSet("matsim-output")) {
      44              :         return;
      45              :     }
      46            2 :     OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
      47            2 :     device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
      48            2 :     device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
      49            2 :     device << "<network name=\"NAME\">\n"; // !!! name
      50              :     // write nodes
      51            2 :     device << "   <nodes>\n";
      52              :     NBNodeCont& nc = nb.getNodeCont();
      53           92 :     for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
      54           90 :         device << "      <node id=\"" << (*i).first
      55           90 :                << "\" x=\"" << (*i).second->getPosition().x()
      56          180 :                << "\" y=\"" << (*i).second->getPosition().y()
      57           90 :                << "\"/>\n";
      58              :     }
      59            2 :     device << "   </nodes>\n";
      60              :     // write edges
      61            2 :     device << "   <links capperiod=\"01:00:00\">\n";
      62              :     NBEdgeCont& ec = nb.getEdgeCont();
      63          216 :     for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
      64          214 :         device << "      <link id=\"" << (*i).first
      65          214 :                << "\" from=\"" << (*i).second->getFromNode()->getID()
      66          214 :                << "\" to=\"" << (*i).second->getToNode()->getID()
      67          405 :                << "\" length=\"" << (*i).second->getLoadedLength()
      68          428 :                << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
      69          214 :                << "\" freespeed=\"" << (*i).second->getSpeed()
      70          428 :                << "\" permlanes=\"" << (*i).second->getNumLanes()
      71          214 :                << "\"/>\n";
      72              :     }
      73            2 :     device << "   </links>\n";
      74              :     //
      75            2 :     device << "</network>\n"; // !!! name
      76            2 :     device.close();
      77              : }
      78              : 
      79              : 
      80              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1