Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
NWWriter_Amitran.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2014-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/****************************************************************************/
18// Exporter writing networks using the Amitran format
19/****************************************************************************/
20#include <config.h>
21
23#include <netbuild/NBEdge.h>
24#include <netbuild/NBEdgeCont.h>
25#include <netbuild/NBNode.h>
26#include <netbuild/NBNodeCont.h>
30#include "NWWriter_DlrNavteq.h"
31#include "NWWriter_Amitran.h"
32
33
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38// ---------------------------------------------------------------------------
39// static methods
40// ---------------------------------------------------------------------------
41void
43 // check whether an amitran-file shall be generated
44 if (!oc.isSet("amitran-output")) {
45 return;
46 }
47 NBEdgeCont& ec = nb.getEdgeCont();
48 OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
49 device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
50 device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/amitran/network.xsd\">\n";
51 // write nodes
52 int index = 0;
53 NBNodeCont& nc = nb.getNodeCont();
54 std::set<NBNode*> singleRoundaboutNodes;
55 std::set<NBNode*> multiRoundaboutNodes;
56 const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
57 for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
58 for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
59 if ((*j)->getNumLanes() > 1) {
60 multiRoundaboutNodes.insert((*j)->getFromNode());
61 } else {
62 singleRoundaboutNodes.insert((*j)->getFromNode());
63 }
64 }
65 }
66 std::map<NBNode*, int> nodeIds;
67 for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
68 device << " <node id=\"" << index;
69 nodeIds[i->second] = index++;
70 if (singleRoundaboutNodes.count(i->second) > 0) {
71 device << "\" type=\"roundaboutSingle\"/>\n";
72 continue;
73 }
74 if (multiRoundaboutNodes.count(i->second) > 0) {
75 device << "\" type=\"roundaboutMulti\"/>\n";
76 continue;
77 }
78 switch (i->second->getType()) {
82 device << "\" type=\"trafficLight";
83 break;
85 device << "\" type=\"priority";
86 break;
88 device << "\" type=\"priorityStop";
89 break;
91 device << "\" type=\"rightBeforeLeft";
92 break;
94 device << "\" type=\"leftBeforeRight";
95 break;
97 device << "\" type=\"allwayStop";
98 break;
100 device << "\" type=\"zipper";
101 break;
103 device << "\" type=\"railSignal";
104 break;
106 device << "\" type=\"railCrossing";
107 break;
110 device << "\" type=\"deadEnd";
111 break;
116 break;
117 }
118 device << "\"/>\n";
119 }
120 // write edges
121 index = 0;
122 for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
123 device << " <link id=\"" << index++
124 << "\" from=\"" << nodeIds[i->second->getFromNode()]
125 << "\" to=\"" << nodeIds[i->second->getToNode()]
126 << "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
127 << "\" length=\"" << int(1000 * i->second->getLoadedLength())
128 << "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
129 << "\" laneNr=\"" << (*i).second->getNumLanes()
130 << "\"/>\n";
131 }
132 device << "</network>\n";
133 device.close();
134}
135
136
137/****************************************************************************/
Storage for edges, including some functionality operating on multiple edges.
Definition NBEdgeCont.h:59
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
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 Amitran-file.
static int getRoadClass(const NBEdge *const edge)
get the navteq road class
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.
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.