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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Exporter writing networks using the MATSim format
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 #include "NWWriter_MATSim.h"
32 #include <netbuild/NBEdge.h>
33 #include <netbuild/NBEdgeCont.h>
34 #include <netbuild/NBNode.h>
35 #include <netbuild/NBNodeCont.h>
36 #include <netbuild/NBNetBuilder.h>
39 
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 // ---------------------------------------------------------------------------
46 // static methods
47 // ---------------------------------------------------------------------------
48 void
50  // check whether a matsim-file shall be generated
51  if (!oc.isSet("matsim-output")) {
52  return;
53  }
54  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
55  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
56  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
57  device << "<network name=\"NAME\">\n"; // !!! name
58  // write nodes
59  device << " <nodes>\n";
60  NBNodeCont& nc = nb.getNodeCont();
61  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
62  device << " <node id=\"" << (*i).first
63  << "\" x=\"" << (*i).second->getPosition().x()
64  << "\" y=\"" << (*i).second->getPosition().y()
65  << "\"/>\n";
66  }
67  device << " </nodes>\n";
68  // write edges
69  device << " <links capperiod=\"01:00:00\">\n";
70  NBEdgeCont& ec = nb.getEdgeCont();
71  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
72  device << " <link id=\"" << (*i).first
73  << "\" from=\"" << (*i).second->getFromNode()->getID()
74  << "\" to=\"" << (*i).second->getToNode()->getID()
75  << "\" length=\"" << (*i).second->getLoadedLength()
76  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
77  << "\" freespeed=\"" << (*i).second->getSpeed()
78  << "\" permlanes=\"" << (*i).second->getNumLanes()
79  << "\"/>\n";
80  }
81  device << " </links>\n";
82  //
83  device << "</network>\n"; // !!! name
84  device.close();
85 }
86 
87 
88 /****************************************************************************/
89 
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:117
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:122
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:156
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:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:98
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:66
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.