SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NBNetBuilder.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // Instance responsible for building networks
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
15 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <string>
37 #include <fstream>
38 #include "NBNetBuilder.h"
39 #include "NBNodeCont.h"
40 #include "NBEdgeCont.h"
42 #include "NBDistrictCont.h"
43 #include "NBDistrict.h"
44 #include "NBDistribution.h"
45 #include "NBRequest.h"
46 #include "NBTypeCont.h"
51 #include <utils/common/ToString.h>
53 
54 #include "NBAlgorithms.h"
55 
56 #ifdef CHECK_MEMORY_LEAKS
57 #include <foreign/nvwa/debug_new.h>
58 #endif // CHECK_MEMORY_LEAKS
59 
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
65  : myEdgeCont(myTypeCont) {}
66 
67 
69 
70 
71 void
73  // we possibly have to load the edges to keep
74  if (oc.isSet("keep-edges.input-file")) {
75  std::ifstream strm(oc.getString("keep-edges.input-file").c_str());
76  if (!strm.good()) {
77  throw ProcessError("Could not load names of edges too keep from '" + oc.getString("keep-edges.input-file") + "'.");
78  }
79  std::ostringstream oss;
80  bool first = true;
81  while (strm.good()) {
82  if (!first) {
83  oss << ',';
84  }
85  std::string name;
86  strm >> name;
87  oss << name;
88  first = false;
89  }
90  oc.set("keep-edges.explicit", oss.str());
91  }
92  // apply options to type control
93  myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.speed"), oc.getInt("default.priority"));
94  // apply options to edge control
96  // apply options to traffic light logics control
98 }
99 
100 
101 void
103  const std::set<std::string> &explicitTurnarounds,
104  bool removeUnwishedNodes) {
105  GeoConvHelper& geoConvHelper = GeoConvHelper::getProcessing();
106 
107 
108  // MODIFYING THE SETS OF NODES AND EDGES
109  // join junctions
110 
111  if (oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
112  myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
113  }
115  if (oc.getBool("junctions.join")) {
116  PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
117  numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont);
119  }
120  if (numJoined > 0) {
121  // bit of a misnomer since we're already done
122  WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
123  }
124 
125  // Removes edges that are connecting the same node
126  PROGRESS_BEGIN_MESSAGE("Removing self-loops");
129  //
130  if (oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
131  PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
134  }
135  //
136  if (oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
137  if (oc.isSet("keep-edges.explicit")) {
138  PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
141  }
142  }
143  //
144  if (removeUnwishedNodes) {
145  unsigned int no = 0;
146  const bool removeGeometryNodes = oc.exists("geometry.remove") && oc.getBool("geometry.remove");
147  PROGRESS_BEGIN_MESSAGE("Removing empty nodes" + std::string(removeGeometryNodes ? " and geometry nodes" : ""));
150  WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
151  }
152  // @note: removing geometry can create similar edges so "Joining" must come afterwards
153  // @note: likewise splitting can destroy similarities so "Joining" must come before
154  PROGRESS_BEGIN_MESSAGE("Joining similar edges");
158  //
159  if (oc.exists("geometry.split") && oc.getBool("geometry.split")) {
160  PROGRESS_BEGIN_MESSAGE("Splitting geometry edges");
163  }
164  // guess ramps
165  if ((oc.exists("ramps.guess") && oc.getBool("ramps.guess")) || (oc.exists("ramps.set") && oc.isSet("ramps.set"))) {
166  PROGRESS_BEGIN_MESSAGE("Guessing and setting on-/off-ramps");
169  }
170 
171 
172  // MOVE TO ORIGIN
173  if (!oc.getBool("offset.disable-normalization") && oc.isDefault("offset.x") && oc.isDefault("offset.y")) {
174  PROGRESS_BEGIN_MESSAGE("Moving network to origin");
175  const SUMOReal x = -geoConvHelper.getConvBoundary().xmin();
176  const SUMOReal y = -geoConvHelper.getConvBoundary().ymin();
177  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
178  (*i).second->reshiftPosition(x, y);
179  }
180  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
181  (*i).second->reshiftPosition(x, y);
182  }
183  for (std::map<std::string, NBDistrict*>::const_iterator i = myDistrictCont.begin(); i != myDistrictCont.end(); ++i) {
184  (*i).second->reshiftPosition(x, y);
185  }
186  geoConvHelper.moveConvertedBy(x, y);
188  }
189  geoConvHelper.computeFinal(); // information needed for location element fixed at this point
190 
191  // @todo Why?
193 
194  // APPLY SPEED MODIFICATIONS
195  if (oc.exists("speed.offset")) {
196  const SUMOReal speedOffset = oc.getFloat("speed.offset");
197  const SUMOReal speedFactor = oc.getFloat("speed.factor");
198  if (speedOffset != 0 || speedFactor != 1) {
199  PROGRESS_BEGIN_MESSAGE("Applying speed modifications");
200  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
201  (*i).second->setSpeed(-1, (*i).second->getSpeed() * speedFactor + speedOffset);
202  }
204  }
205  }
206 
207  // GUESS TLS POSITIONS
208  PROGRESS_BEGIN_MESSAGE("Assigning nodes to traffic lights");
209  if (oc.isSet("tls.set")) {
210  std::vector<std::string> tlControlledNodes = oc.getStringVector("tls.set");
211  for (std::vector<std::string>::const_iterator i = tlControlledNodes.begin(); i != tlControlledNodes.end(); ++i) {
212  NBNode* node = myNodeCont.retrieve(*i);
213  if (node == 0) {
214  WRITE_WARNING("Building a tl-logic for node '" + *i + "' is not possible." + "\n The node '" + *i + "' is not known.");
215  } else {
217  }
218  }
219  }
222  //
223  if (oc.getBool("tls.join")) {
224  PROGRESS_BEGIN_MESSAGE("Joining traffic light nodes");
227  }
228 
229 
230  // CONNECTIONS COMPUTATION
231  //
232  PROGRESS_BEGIN_MESSAGE("Computing turning directions");
235  //
236  PROGRESS_BEGIN_MESSAGE("Sorting nodes' edges");
239  //
240  PROGRESS_BEGIN_MESSAGE("Computing node types");
243  //
244  PROGRESS_BEGIN_MESSAGE("Computing priorities");
247  //
248  if (oc.getBool("roundabouts.guess")) {
249  PROGRESS_BEGIN_MESSAGE("Guessing and setting roundabouts");
252  }
253  //
254  PROGRESS_BEGIN_MESSAGE("Computing approached edges");
255  myEdgeCont.computeEdge2Edges(oc.getBool("no-left-connections"));
257  //
258  PROGRESS_BEGIN_MESSAGE("Computing approaching lanes");
261  //
262  PROGRESS_BEGIN_MESSAGE("Dividing of lanes on approached lanes");
266  //
267  PROGRESS_BEGIN_MESSAGE("Processing turnarounds");
268  if (!oc.getBool("no-turnarounds")) {
269  myEdgeCont.appendTurnarounds(oc.getBool("no-turnarounds.tls"));
270  } else {
271  myEdgeCont.appendTurnarounds(explicitTurnarounds, oc.getBool("no-turnarounds.tls"));
272  }
274  //
275  PROGRESS_BEGIN_MESSAGE("Rechecking of lane endings");
278 
279 
280  // GEOMETRY COMPUTATION
281  //
282  PROGRESS_BEGIN_MESSAGE("Computing node shapes");
283  myNodeCont.computeNodeShapes(oc.getBool("lefthand"));
285  //
286  PROGRESS_BEGIN_MESSAGE("Computing edge shapes");
289 
290 
291  // COMPUTING RIGHT-OF-WAY AND TRAFFIC LIGHT PROGRAMS
292  //
293  PROGRESS_BEGIN_MESSAGE("Computing traffic light control information");
296  //
297  PROGRESS_BEGIN_MESSAGE("Computing node logics");
300  //
301  PROGRESS_BEGIN_MESSAGE("Computing traffic light logics");
302  std::pair<unsigned int, unsigned int> numbers = myTLLCont.computeLogics(myEdgeCont, oc);
304  std::string progCount = "";
305  if (numbers.first != numbers.second) {
306  progCount = "(" + toString(numbers.second) + " programs) ";
307  }
308  WRITE_MESSAGE(" " + toString(numbers.first) + " traffic light(s) " + progCount + "computed.");
309 
310 
311  // FINISHING INNER EDGES
312  if (!oc.getBool("no-internal-links")) {
313  PROGRESS_BEGIN_MESSAGE("Building inner edges");
314  for (std::map<std::string, NBEdge*>::const_iterator i = myEdgeCont.begin(); i != myEdgeCont.end(); ++i) {
315  (*i).second->sortOutgoingConnectionsByIndex();
316  }
317  for (std::map<std::string, NBNode*>::const_iterator i = myNodeCont.begin(); i != myNodeCont.end(); ++i) {
318  (*i).second->buildInnerEdges();
319  }
321  }
322 
323 
324  // report
325  WRITE_MESSAGE("-----------------------------------------------------");
326  WRITE_MESSAGE("Summary:");
328  WRITE_MESSAGE(" Network boundaries:");
329  WRITE_MESSAGE(" Original boundary : " + toString(geoConvHelper.getOrigBoundary()));
330  WRITE_MESSAGE(" Applied offset : " + toString(geoConvHelper.getOffsetBase()));
331  WRITE_MESSAGE(" Converted boundary : " + toString(geoConvHelper.getConvBoundary()));
332  WRITE_MESSAGE("-----------------------------------------------------");
334 }
335 
336 
337 /****************************************************************************/