SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
11 // Copyright (C) 2001-2013 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 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // static methods
52 // ---------------------------------------------------------------------------
53 void
55  // check whether a matsim-file shall be generated
56  if (!oc.isSet("matsim-output")) {
57  return;
58  }
59  OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
60  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
61  device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
62  device << "<network name=\"NAME\">\n"; // !!! name
63  // write nodes
64  device << " <nodes>\n";
65  NBNodeCont& nc = nb.getNodeCont();
66  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
67  device << " <node id=\"" << (*i).first
68  << "\" x=\"" << (*i).second->getPosition().x()
69  << "\" y=\"" << (*i).second->getPosition().y()
70  << "\"/>\n";
71  }
72  device << " </nodes>\n";
73  // write edges
74  device << " <links capperiod=\"01:00:00\">\n";
75  NBEdgeCont& ec = nb.getEdgeCont();
76  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
77  device << " <link id=\"" << (*i).first
78  << "\" from=\"" << (*i).second->getFromNode()->getID()
79  << "\" to=\"" << (*i).second->getToNode()->getID()
80  << "\" length=\"" << (*i).second->getLoadedLength()
81  << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
82  << "\" freespeed=\"" << (*i).second->getSpeed()
83  << "\" permlanes=\"" << (*i).second->getNumLanes()
84  << "\"/>\n";
85  }
86  device << " </links>\n";
87  //
88  device << "</network>\n"; // !!! name
89  device.close();
90 }
91 
92 
93 /****************************************************************************/
94 
SUMOReal getFloat(const std::string &name) const
Returns the SUMOReal-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
NBEdgeCont & getEdgeCont()
Returns the edge container.
Definition: NBNetBuilder.h:154
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:149
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
NBNodeCont & getNodeCont()
Returns the node container.
Definition: NBNetBuilder.h:162
Instance responsible for building networks.
Definition: NBNetBuilder.h:113
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:108
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:63
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:141
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.