SUMO - Simulation of Urban MObility
NWWriter_MATSim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Exporter writing networks using the MATSim format
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 #include "NWWriter_MATSim.h"
33 #include <netbuild/NBEdge.h>
34 #include <netbuild/NBEdgeCont.h>
35 #include <netbuild/NBNode.h>
36 #include <netbuild/NBNodeCont.h>
37 #include <netbuild/NBNetBuilder.h>
40 
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // static methods
48 // ---------------------------------------------------------------------------
49 void
51  // check whether a matsim-file shall be generated
52  if (!oc.isSet("matsim-output")) {
53  return;
54  }
55  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
56  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
57  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
58  device << "<network name=\"NAME\">\n"; // !!! name
59  // write nodes
60  device << " <nodes>\n";
61  NBNodeCont& nc = nb.getNodeCont();
62  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
63  device << " <node id=\"" << (*i).first
64  << "\" x=\"" << (*i).second->getPosition().x()
65  << "\" y=\"" << (*i).second->getPosition().y()
66  << "\"/>\n";
67  }
68  device << " </nodes>\n";
69  // write edges
70  device << " <links capperiod=\"01:00:00\">\n";
71  NBEdgeCont& ec = nb.getEdgeCont();
72  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
73  device << " <link id=\"" << (*i).first
74  << "\" from=\"" << (*i).second->getFromNode()->getID()
75  << "\" to=\"" << (*i).second->getToNode()->getID()
76  << "\" length=\"" << (*i).second->getLoadedLength()
77  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
78  << "\" freespeed=\"" << (*i).second->getSpeed()
79  << "\" permlanes=\"" << (*i).second->getNumLanes()
80  << "\"/>\n";
81  }
82  device << " </links>\n";
83  //
84  device << "</network>\n"; // !!! name
85  device.close();
86 }
87 
88 
89 /****************************************************************************/
90 
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:114
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:119
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:155
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:160
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:99
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.