SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
10 // Copyright (C) 2014-2014 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 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 // ---------------------------------------------------------------------------
52 // static methods
53 // ---------------------------------------------------------------------------
54 void
56  // check whether an amitran-file shall be generated
57  if (!oc.isSet("amitran-output")) {
58  return;
59  }
60  OutputDevice& device = OutputDevice::getDevice(oc.getString("amitran-output"));
61  device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
62  device << "<network xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo-sim.org/xsd/amitran/network.xsd\">\n";
63  // write nodes
64  int index = 0;
65  NBNodeCont& nc = nb.getNodeCont();
66  std::set<NBNode*> singleRoundaboutNodes;
67  std::set<NBNode*> multiRoundaboutNodes;
68  const std::vector<EdgeVector>& roundabouts = nb.getRoundabouts();
69  for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
70  for (EdgeVector::const_iterator j = (*i).begin(); j != (*i).end(); ++j) {
71  if ((*j)->getNumLanes() > 1) {
72  multiRoundaboutNodes.insert((*j)->getFromNode());
73  } else {
74  singleRoundaboutNodes.insert((*j)->getFromNode());
75  }
76  }
77  }
78  std::map<NBNode*, int> nodeIds;
79  for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
80  device << " <node id=\"" << index;
81  nodeIds[i->second] = index++;
82  if (singleRoundaboutNodes.count(i->second) > 0) {
83  device << "\" type=\"roundaboutSingle\"/>\n";
84  continue;
85  }
86  if (multiRoundaboutNodes.count(i->second) > 0) {
87  device << "\" type=\"roundaboutMulti\"/>\n";
88  continue;
89  }
90  switch (i->second->getType()) {
93  device << "\" type=\"trafficLight";
94  break;
95  case NODETYPE_PRIORITY:
96  device << "\" type=\"priority";
97  break;
99  device << "\" type=\"priorityStop";
100  break;
102  device << "\" type=\"rightBeforeLeft";
103  break;
105  device << "\" type=\"allwayStop";
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  NBEdgeCont& ec = nb.getEdgeCont();
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 /****************************************************************************/
138