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 /****************************************************************************/
16 // Exporter writing networks using the MATSim format
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 #include "NWWriter_MATSim.h"
26 #include <netbuild/NBEdge.h>
27 #include <netbuild/NBEdgeCont.h>
28 #include <netbuild/NBNode.h>
29 #include <netbuild/NBNodeCont.h>
30 #include <netbuild/NBNetBuilder.h>
33 
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 // ---------------------------------------------------------------------------
40 // static methods
41 // ---------------------------------------------------------------------------
42 void
44  // check whether a matsim-file shall be generated
45  if (!oc.isSet("matsim-output")) {
46  return;
47  }
48  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
49  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
50  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
51  device << "<network name=\"NAME\">\n"; // !!! name
52  // write nodes
53  device << " <nodes>\n";
54  NBNodeCont& nc = nb.getNodeCont();
55  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
56  device << " <node id=\"" << (*i).first
57  << "\" x=\"" << (*i).second->getPosition().x()
58  << "\" y=\"" << (*i).second->getPosition().y()
59  << "\"/>\n";
60  }
61  device << " </nodes>\n";
62  // write edges
63  device << " <links capperiod=\"01:00:00\">\n";
64  NBEdgeCont& ec = nb.getEdgeCont();
65  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
66  device << " <link id=\"" << (*i).first
67  << "\" from=\"" << (*i).second->getFromNode()->getID()
68  << "\" to=\"" << (*i).second->getToNode()->getID()
69  << "\" length=\"" << (*i).second->getLoadedLength()
70  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
71  << "\" freespeed=\"" << (*i).second->getSpeed()
72  << "\" permlanes=\"" << (*i).second->getNumLanes()
73  << "\"/>\n";
74  }
75  device << " </links>\n";
76  //
77  device << "</network>\n"; // !!! name
78  device.close();
79 }
80 
81 
82 /****************************************************************************/
83 
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:116
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:121
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:193
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:185
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:151
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:61
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:156
Instance responsible for building networks.
Definition: NBNetBuilder.h:110
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:90
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:60
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.