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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // Exporter writing networks using the Amitran format
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 #include <netbuild/NBEdge.h>
32 #include <netbuild/NBEdgeCont.h>
33 #include <netbuild/NBNode.h>
34 #include <netbuild/NBNodeCont.h>
35 #include <netbuild/NBNetBuilder.h>
38 #include "NWWriter_DlrNavteq.h"
39 #include "NWWriter_Amitran.h"
40 
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // static methods
48 // ---------------------------------------------------------------------------
49 void
51  // check whether an amitran-file shall be generated
52  if (!oc.isSet("amitran-output")) {
53  return;
54  }
55  NBEdgeCont& ec = nb.getEdgeCont();
56  OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
57  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
58  device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/amitran/network.xsd\">\n";
59  // write nodes
60  int index = 0;
61  NBNodeCont& nc = nb.getNodeCont();
62  std::set<NBNode*> singleRoundaboutNodes;
63  std::set<NBNode*> multiRoundaboutNodes;
64  const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
65  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
66  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
67  if ((*j)->getNumLanes() > 1) {
68  multiRoundaboutNodes.insert((*j)->getFromNode());
69  } else {
70  singleRoundaboutNodes.insert((*j)->getFromNode());
71  }
72  }
73  }
74  std::map<NBNode*, int> nodeIds;
75  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
76  device << " <node id=\"" << index;
77  nodeIds[i->second] = index++;
78  if (singleRoundaboutNodes.count(i->second) > 0) {
79  device << "\" type=\"roundaboutSingle\"/>\n";
80  continue;
81  }
82  if (multiRoundaboutNodes.count(i->second) > 0) {
83  device << "\" type=\"roundaboutMulti\"/>\n";
84  continue;
85  }
86  switch (i->second->getType()) {
90  device << "\" type=\"trafficLight";
91  break;
92  case NODETYPE_PRIORITY:
93  device << "\" type=\"priority";
94  break;
96  device << "\" type=\"priorityStop";
97  break;
99  device << "\" type=\"rightBeforeLeft";
100  break;
102  device << "\" type=\"allwayStop";
103  break;
104  case NODETYPE_ZIPPER:
105  device << "\" type=\"zipper";
106  break;
108  device << "\" type=\"railSignal";
109  break;
111  device << "\" type=\"railCrossing";
112  break;
113  case NODETYPE_DEAD_END:
115  device << "\" type=\"deadEnd";
116  break;
117  case NODETYPE_DISTRICT:
118  case NODETYPE_NOJUNCTION:
119  case NODETYPE_INTERNAL:
120  case NODETYPE_UNKNOWN:
121  break;
122  }
123  device << "\"/>\n";
124  }
125  // write edges
126  index = 0;
127  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
128  device << " <link id=\"" << index++
129  << "\" from=\"" << nodeIds[i->second->getFromNode()]
130  << "\" to=\"" << nodeIds[i->second->getToNode()]
131  << "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
132  << "\" length=\"" << int(1000 * i->second->getLoadedLength())
133  << "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
134  << "\" laneNr=\"" << (*i).second->getNumLanes()
135  << "\"/>\n";
136  }
137  device << "</network>\n";
138  device.close();
139 }
140 
141 
142 /****************************************************************************/
143 
static void writeNetwork(const OptionsCont &oc, NBNetBuilder &nb)
Writes the network into a Amitran-file.
std::map< std::string, NBNode * >::const_iterator begin() const
Returns the pointer to the begin of the stored nodes.
Definition: NBNodeCont.h:117
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:122
static int getRoadClass(NBEdge *edge)
get the navteq road class
std::map< std::string, NBEdge * >::const_iterator end() const
Returns the pointer to the end of the stored edges.
Definition: NBEdgeCont.h:198
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::map< std::string, NBEdge * >::const_iterator begin() const
Returns the pointer to the begin of the stored edges.
Definition: NBEdgeCont.h:190
NBEdgeCont & getEdgeCont()
Definition: NBNetBuilder.h:156
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:66
const std::set< EdgeSet > getRoundabouts() const
Returns the determined roundabouts.
NBNodeCont & getNodeCont()
Returns a reference to the node container.
Definition: NBNetBuilder.h:161
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:98
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:66