Eclipse SUMO - Simulation of Urban MObility
NWWriter_MATSim.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // Exporter writing networks using the MATSim format
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 #include "NWWriter_MATSim.h"
25 #include <netbuild/NBEdge.h>
26 #include <netbuild/NBEdgeCont.h>
27 #include <netbuild/NBNode.h>
28 #include <netbuild/NBNodeCont.h>
29 #include <netbuild/NBNetBuilder.h>
32 
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 // ---------------------------------------------------------------------------
39 // static methods
40 // ---------------------------------------------------------------------------
41 void
43  // check whether a matsim-file shall be generated
44  if (!oc.isSet("matsim-output")) {
45  return;
46  }
47  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
48  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
49  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
50  device << "<network name=\"NAME\">\n"; // !!! name
51  // write nodes
52  device << " <nodes>\n";
53  NBNodeCont& nc = nb.getNodeCont();
54  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
55  device << " <node id=\"" << (*i).first
56  << "\" x=\"" << (*i).second->getPosition().x()
57  << "\" y=\"" << (*i).second->getPosition().y()
58  << "\"/>\n";
59  }
60  device << " </nodes>\n";
61  // write edges
62  device << " <links capperiod=\"01:00:00\">\n";
63  NBEdgeCont& ec = nb.getEdgeCont();
64  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
65  device << " <link id=\"" << (*i).first
66  << "\" from=\"" << (*i).second->getFromNode()->getID()
67  << "\" to=\"" << (*i).second->getToNode()->getID()
68  << "\" length=\"" << (*i).second->getLoadedLength()
69  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
70  << "\" freespeed=\"" << (*i).second->getSpeed()
71  << "\" permlanes=\"" << (*i).second->getNumLanes()
72  << "\"/>\n";
73  }
74  device << " </links>\n";
75  //
76  device << "</network>\n"; // !!! name
77  device.close();
78 }
79 
80 
81 /****************************************************************************/
82 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NBNodeCont::end
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:120
OptionsCont.h
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
NBEdgeCont.h
NBNodeCont::begin
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:115
NWWriter_MATSim.h
NBNetBuilder::getEdgeCont
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:59
OutputDevice.h
NBNetBuilder.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBEdgeCont::end
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:192
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
NBNodeCont.h
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:54
config.h
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
NBNode.h
NBEdgeCont::begin
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:184
NBEdge.h
NWWriter_MATSim::writeNetwork
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.
Definition: NWWriter_MATSim.cpp:42