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