Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NWWriter_MATSim.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Exporter writing networks using the MATSim format
20/****************************************************************************/
21#include <config.h>
22#include "NWWriter_MATSim.h"
24#include <netbuild/NBEdge.h>
25#include <netbuild/NBEdgeCont.h>
26#include <netbuild/NBNode.h>
27#include <netbuild/NBNodeCont.h>
31
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37// ---------------------------------------------------------------------------
38// static methods
39// ---------------------------------------------------------------------------
40void
42 // check whether a matsim-file shall be generated
43 if (!oc.isSet("matsim-output")) {
44 return;
45 }
46 OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
47 device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
48 device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
49 device << "<network name=\"NAME\">\n"; // !!! name
50 // write nodes
51 device << " <nodes>\n";
52 NBNodeCont& nc = nb.getNodeCont();
53 for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
54 device << " <node id=\"" << (*i).first
55 << "\" x=\"" << (*i).second->getPosition().x()
56 << "\" y=\"" << (*i).second->getPosition().y()
57 << "\"/>\n";
58 }
59 device << " </nodes>\n";
60 // write edges
61 device << " <links capperiod=\"01:00:00\">\n";
62 NBEdgeCont& ec = nb.getEdgeCont();
63 for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
64 device << " <link id=\"" << (*i).first
65 << "\" from=\"" << (*i).second->getFromNode()->getID()
66 << "\" to=\"" << (*i).second->getToNode()->getID()
67 << "\" length=\"" << (*i).second->getLoadedLength()
68 << "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
69 << "\" freespeed=\"" << (*i).second->getSpeed()
70 << "\" permlanes=\"" << (*i).second->getNumLanes()
71 << "\"/>\n";
72 }
73 device << " </links>\n";
74 //
75 device << "</network>\n"; // !!! name
76 device.close();
77}
78
79
80/****************************************************************************/
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition NBEdgeCont.h:171
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition NBEdgeCont.h:178
Instance responsible for building networks.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
NBEdgeCont & getEdgeCont()
Container for nodes during the netbuilding process.
Definition NBNodeCont.h:57
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition NBNodeCont.h:113
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition NBNodeCont.h:118
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a MATSim-file.
A storage for options typed value containers)
Definition OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
double getFloat(const std::string &name) const
Returns the double-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)
Static storage of an output device and its base (abstract) implementation.
void close()
Closes the device and removes it from the dictionary.
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.