SUMO - Simulation of Urban MObility
NWWriter_Amitran.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Exporter writing networks using the Amitran format
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2014-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
32 #include <netbuild/NBEdge.h>
33 #include <netbuild/NBEdgeCont.h>
34 #include <netbuild/NBNode.h>
35 #include <netbuild/NBNodeCont.h>
36 #include <netbuild/NBNetBuilder.h>
39 #include "NWWriter_DlrNavteq.h"
40 #include "NWWriter_Amitran.h"
41 
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 // ---------------------------------------------------------------------------
48 // static methods
49 // ---------------------------------------------------------------------------
50 void
52  // check whether an amitran-file shall be generated
53  if (!oc.isSet("amitran-output")) {
54  return;
55  }
56  NBEdgeCont& ec = nb.getEdgeCont();
57  OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
58  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
59  device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.dlr.de/xsd/amitran/network.xsd\">\n";
60  // write nodes
61  int index = 0;
62  NBNodeCont& nc = nb.getNodeCont();
63  std::set<NBNode*> singleRoundaboutNodes;
64  std::set<NBNode*> multiRoundaboutNodes;
65  const std::set<EdgeSet>& roundabouts = ec.getRoundabouts();
66  for (std::set<EdgeSet>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
67  for (EdgeSet::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
68  if ((*j)->getNumLanes() > 1) {
69  multiRoundaboutNodes.insert((*j)->getFromNode());
70  } else {
71  singleRoundaboutNodes.insert((*j)->getFromNode());
72  }
73  }
74  }
75  std::map<NBNode*, int> nodeIds;
76  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
77  device << " <node id=\"" << index;
78  nodeIds[i->second] = index++;
79  if (singleRoundaboutNodes.count(i->second) > 0) {
80  device << "\" type=\"roundaboutSingle\"/>\n";
81  continue;
82  }
83  if (multiRoundaboutNodes.count(i->second) > 0) {
84  device << "\" type=\"roundaboutMulti\"/>\n";
85  continue;
86  }
87  switch (i->second->getType()) {
91  device << "\" type=\"trafficLight";
92  break;
93  case NODETYPE_PRIORITY:
94  device << "\" type=\"priority";
95  break;
97  device << "\" type=\"priorityStop";
98  break;
100  device << "\" type=\"rightBeforeLeft";
101  break;
103  device << "\" type=\"allwayStop";
104  break;
105  case NODETYPE_ZIPPER:
106  device << "\" type=\"zipper";
107  break;
109  device << "\" type=\"railSignal";
110  break;
112  device << "\" type=\"railCrossing";
113  break;
114  case NODETYPE_DEAD_END:
116  device << "\" type=\"deadEnd";
117  break;
118  case NODETYPE_DISTRICT:
119  case NODETYPE_NOJUNCTION:
120  case NODETYPE_INTERNAL:
121  case NODETYPE_UNKNOWN:
122  break;
123  }
124  device << "\"/>\n";
125  }
126  // write edges
127  index = 0;
128  for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
129  device << " <link id=\"" << index++
130  << "\" from=\"" << nodeIds[i->second->getFromNode()]
131  << "\" to=\"" << nodeIds[i->second->getToNode()]
132  << "\" roadClass=\"" << NWWriter_DlrNavteq::getRoadClass((*i).second)
133  << "\" length=\"" << int(1000 * i->second->getLoadedLength())
134  << "\" speedLimitKmh=\"" << int(3.6 * (*i).second->getSpeed() + 0.5)
135  << "\" laneNr=\"" << (*i).second->getNumLanes()
136  << "\"/>\n";
137  }
138  device << "</network>\n";
139  device.close();
140 }
141 
142 
143 /****************************************************************************/
144 
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:114
std::map< std::string, NBNode * >::const_iterator end() const
Returns the pointer to the end of the stored nodes.
Definition: NBNodeCont.h:119
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:155
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:160
Instance responsible for building networks.
Definition: NBNetBuilder.h:114
static OutputDevice & getDevice(const std::string &name)
Returns the described OutputDevice.
A storage for options typed value containers)
Definition: OptionsCont.h:99
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
Container for nodes during the netbuilding process.
Definition: NBNodeCont.h:63