Eclipse SUMO - Simulation of Urban MObility
NWWriter_Amitran.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-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 /****************************************************************************/
14 // Exporter writing networks using the Amitran format
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
24 #include <netbuild/NBEdge.h>
25 #include <netbuild/NBEdgeCont.h>
26 #include <netbuild/NBNode.h>
27 #include <netbuild/NBNodeCont.h>
28 #include <netbuild/NBNetBuilder.h>
31 #include "NWWriter_DlrNavteq.h"
32 #include "NWWriter_Amitran.h"
33 
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 // ---------------------------------------------------------------------------
40 // static methods
41 // ---------------------------------------------------------------------------
42 void
44  // check whether an amitran-file shall be generated
45  if (!oc.isSet("amitran-output")) {
46  return;
47  }
48  NBEdgeCont& ec = nb.getEdgeCont();
49  OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
50  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
51  device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/amitran/network.xsd\">\n";
52  // write nodes
53  int index = 0;
54  NBNodeCont& nc = nb.getNodeCont();
55  std::set<NBNode*> singleRoundaboutNodes;
56  std::set<NBNode*> multiRoundaboutNodes;
57  const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
58  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
59  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
60  if ((*j)->getNumLanes() > 1) {
61  multiRoundaboutNodes.insert((*j)->getFromNode());
62  } else {
63  singleRoundaboutNodes.insert((*j)->getFromNode());
64  }
65  }
66  }
67  std::map<NBNode*, int> nodeIds;
68  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
69  device << " <node id=\"" << index;
70  nodeIds[i->second] = index++;
71  if (singleRoundaboutNodes.count(i->second) > 0) {
72  device << "\" type=\"roundaboutSingle\"/>\n";
73  continue;
74  }
75  if (multiRoundaboutNodes.count(i->second) > 0) {
76  device << "\" type=\"roundaboutMulti\"/>\n";
77  continue;
78  }
79  switch (i->second->getType()) {
83  device << "\" type=\"trafficLight";
84  break;
85  case NODETYPE_PRIORITY:
86  device << "\" type=\"priority";
87  break;
89  device << "\" type=\"priorityStop";
90  break;
92  device << "\" type=\"rightBeforeLeft";
93  break;
95  device << "\" type=\"allwayStop";
96  break;
97  case NODETYPE_ZIPPER:
98  device << "\" type=\"zipper";
99  break;
101  device << "\" type=\"railSignal";
102  break;
104  device << "\" type=\"railCrossing";
105  break;
106  case NODETYPE_DEAD_END:
108  device << "\" type=\"deadEnd";
109  break;
110  case NODETYPE_DISTRICT:
111  case NODETYPE_NOJUNCTION:
112  case NODETYPE_INTERNAL:
113  case NODETYPE_UNKNOWN:
114  break;
115  }
116  device << "\"/>\n";
117  }
118  // write edges
119  index = 0;
120  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
121  device << " <link id=\"" << index++
122  << "\" from=\"" << nodeIds[i->second->getFromNode()]
123  << "\" to=\"" << nodeIds[i->second->getToNode()]
124  << "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
125  << "\" length=\"" << int(1000 * i->second->getLoadedLength())
126  << "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
127  << "\" laneNr=\"" << (*i).second->getNumLanes()
128  << "\"/>\n";
129  }
130  device << "</network>\n";
131  device.close();
132 }
133 
134 
135 /****************************************************************************/
136 
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
NODETYPE_PRIORITY
@ NODETYPE_PRIORITY
Definition: SUMOXMLDefinitions.h:1061
NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED
@ NODETYPE_TRAFFIC_LIGHT_RIGHT_ON_RED
Definition: SUMOXMLDefinitions.h:1058
NODETYPE_ZIPPER
@ NODETYPE_ZIPPER
Definition: SUMOXMLDefinitions.h:1065
NWWriter_Amitran.h
NODETYPE_DEAD_END_DEPRECATED
@ NODETYPE_DEAD_END_DEPRECATED
Definition: SUMOXMLDefinitions.h:1070
NBEdgeCont
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:60
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
NBNodeCont::end
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:120
OptionsCont.h
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
NBEdgeCont.h
NODETYPE_INTERNAL
@ NODETYPE_INTERNAL
Definition: SUMOXMLDefinitions.h:1068
NBNodeCont::begin
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:115
NODETYPE_UNKNOWN
@ NODETYPE_UNKNOWN
Definition: SUMOXMLDefinitions.h:1055
OutputDevice::close
void close()
Closes the device and removes it from the dictionary.
Definition: OutputDevice.cpp:207
NBNodeCont
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:59
NBNetBuilder::getEdgeCont
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:150
NODETYPE_ALLWAY_STOP
@ NODETYPE_ALLWAY_STOP
Definition: SUMOXMLDefinitions.h:1064
NODETYPE_RAIL_SIGNAL
@ NODETYPE_RAIL_SIGNAL
Definition: SUMOXMLDefinitions.h:1059
NODETYPE_PRIORITY_STOP
@ NODETYPE_PRIORITY_STOP
Definition: SUMOXMLDefinitions.h:1062
NODETYPE_TRAFFIC_LIGHT_NOJUNCTION
@ NODETYPE_TRAFFIC_LIGHT_NOJUNCTION
Definition: SUMOXMLDefinitions.h:1057
OutputDevice.h
NBNetBuilder.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NODETYPE_RAIL_CROSSING
@ NODETYPE_RAIL_CROSSING
Definition: SUMOXMLDefinitions.h:1060
NODETYPE_RIGHT_BEFORE_LEFT
@ NODETYPE_RIGHT_BEFORE_LEFT
Definition: SUMOXMLDefinitions.h:1063
NBEdgeCont::end
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:192
NODETYPE_DEAD_END
@ NODETYPE_DEAD_END
Definition: SUMOXMLDefinitions.h:1069
NODETYPE_DISTRICT
@ NODETYPE_DISTRICT
Definition: SUMOXMLDefinitions.h:1066
NBNodeCont.h
OutputDevice::getDevice
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
Definition: OutputDevice.cpp:54
NWWriter_DlrNavteq::getRoadClass
static int getRoadClass(NBEdge *edge)
get the navteq road class
Definition: NWWriter_DlrNavteq.cpp:292
config.h
NBNetBuilder::getNodeCont
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:155
NBNode.h
NBEdgeCont::begin
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:184
NBEdgeCont::getRoundabouts
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
Definition: NBEdgeCont.cpp:1345
NWWriter_Amitran::writeNetwork
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a Amitran-file.
Definition: NWWriter_Amitran.cpp:43
NBEdge.h
NODETYPE_NOJUNCTION
@ NODETYPE_NOJUNCTION
Definition: SUMOXMLDefinitions.h:1067
NWWriter_DlrNavteq.h
NODETYPE_TRAFFIC_LIGHT
@ NODETYPE_TRAFFIC_LIGHT
Definition: SUMOXMLDefinitions.h:1056