PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/3A/res/sumo/src/netbuild/NBNetBuilder.cpp

https://bitbucket.org/sieben/ensiie
C++ | 311 lines | 225 code | 26 blank | 60 comment | 39 complexity | 6e3f5dedd4adba2f3b1319ebc902eca7 MD5 | raw file
  1. /****************************************************************************/
  2. /// @file NBNetBuilder.cpp
  3. /// @author Daniel Krajzewicz
  4. /// @date 20 Nov 2001
  5. /// @version $Id: NBNetBuilder.cpp 11445 2011-10-31 23:24:01Z behrisch $
  6. ///
  7. // Instance responsible for building networks
  8. /****************************************************************************/
  9. // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
  10. // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
  11. /****************************************************************************/
  12. //
  13. // This program is free software; you can redistribute it and/or modify
  14. // it under the terms of the GNU General Public License as published by
  15. // the Free Software Foundation; either version 2 of the License, or
  16. // (at your option) any later version.
  17. //
  18. /****************************************************************************/
  19. // ===========================================================================
  20. // included modules
  21. // ===========================================================================
  22. #ifdef _MSC_VER
  23. #include <windows_config.h>
  24. #else
  25. #include <config.h>
  26. #endif
  27. #include <string>
  28. #include <fstream>
  29. #include "NBNetBuilder.h"
  30. #include "NBNodeCont.h"
  31. #include "NBEdgeCont.h"
  32. #include "NBTrafficLightLogicCont.h"
  33. #include "NBDistrictCont.h"
  34. #include "NBDistrict.h"
  35. #include "NBDistribution.h"
  36. #include "NBRequest.h"
  37. #include "NBTypeCont.h"
  38. #include <utils/options/OptionsCont.h>
  39. #include <utils/common/MsgHandler.h>
  40. #include <utils/common/UtilExceptions.h>
  41. #include <utils/common/StringTokenizer.h>
  42. #include <utils/common/ToString.h>
  43. #include <utils/geom/GeoConvHelper.h>
  44. #ifdef CHECK_MEMORY_LEAKS
  45. #include <foreign/nvwa/debug_new.h>
  46. #endif // CHECK_MEMORY_LEAKS
  47. // ===========================================================================
  48. // method definitions
  49. // ===========================================================================
  50. NBNetBuilder::NBNetBuilder() throw()
  51. : myEdgeCont(myTypeCont) {}
  52. NBNetBuilder::~NBNetBuilder() throw() {}
  53. void
  54. NBNetBuilder::applyOptions(OptionsCont& oc) throw(ProcessError) {
  55. // we possibly have to load the edges to keep
  56. if (oc.isSet("keep-edges.input-file")) {
  57. std::ifstream strm(oc.getString("keep-edges.input-file").c_str());
  58. if (!strm.good()) {
  59. throw ProcessError("Could not load names of edges too keep from '" + oc.getString("keep-edges.input-file") + "'.");
  60. }
  61. std::ostringstream oss;
  62. bool first = true;
  63. while (strm.good()) {
  64. if (!first) {
  65. oss << ',';
  66. }
  67. std::string name;
  68. strm >> name;
  69. oss << name;
  70. first = false;
  71. }
  72. oc.set("keep-edges.explicit", oss.str());
  73. }
  74. // apply options to type control
  75. myTypeCont.setDefaults(oc.getInt("default.lanenumber"), oc.getFloat("default.speed"), oc.getInt("default.priority"));
  76. // apply options to edge control
  77. myEdgeCont.applyOptions(oc);
  78. // apply options to traffic light logics control
  79. myTLLCont.applyOptions(oc);
  80. }
  81. void
  82. NBNetBuilder::compute(OptionsCont& oc,
  83. const std::set<std::string> &explicitTurnarounds,
  84. bool removeUnwishedNodes) {
  85. GeoConvHelper& geoConvHelper = GeoConvHelper::getDefaultInstance();
  86. // join junctions
  87. if (oc.exists("junctions.join-exclude") && oc.isSet("junctions.join-exclude")) {
  88. myNodeCont.addJoinExclusion(oc.getStringVector("junctions.join-exclude"));
  89. }
  90. unsigned int numJoined = myNodeCont.joinLoadedClusters(myDistrictCont, myEdgeCont, myTLLCont);
  91. if (oc.getBool("junctions.join")) {
  92. PROGRESS_BEGIN_MESSAGE("Joining junction clusters");
  93. numJoined += myNodeCont.joinJunctions(oc.getFloat("junctions.join-dist"), myDistrictCont, myEdgeCont, myTLLCont);
  94. PROGRESS_DONE_MESSAGE();
  95. }
  96. if (numJoined > 0) {
  97. // bit of a misnomer since we're already done
  98. WRITE_MESSAGE(" Joined " + toString(numJoined) + " junction cluster(s).");
  99. }
  100. // ADAPTING THE INPUT
  101. // Removes edges that are connecting the same node
  102. PROGRESS_BEGIN_MESSAGE("Removing dummy edges");
  103. myNodeCont.removeDummyEdges(myDistrictCont, myEdgeCont, myTLLCont);
  104. PROGRESS_DONE_MESSAGE();
  105. //
  106. PROGRESS_BEGIN_MESSAGE("Joining double connections");
  107. myJoinedEdges.init(myEdgeCont);
  108. myNodeCont.joinDoubleNodeConnections(myDistrictCont, myEdgeCont, myTLLCont);
  109. PROGRESS_DONE_MESSAGE();
  110. //
  111. if (oc.exists("remove-edges.isolated") && oc.getBool("remove-edges.isolated")) {
  112. PROGRESS_BEGIN_MESSAGE("Finding isolated roads");
  113. myNodeCont.removeIsolatedRoads(myDistrictCont, myEdgeCont, myTLLCont);
  114. PROGRESS_DONE_MESSAGE();
  115. }
  116. //
  117. if (oc.exists("keep-edges.postload") && oc.getBool("keep-edges.postload")) {
  118. if (oc.isSet("keep-edges.explicit")) {
  119. PROGRESS_BEGIN_MESSAGE("Removing unwished edges");
  120. myEdgeCont.removeUnwishedEdges(myDistrictCont);
  121. PROGRESS_DONE_MESSAGE();
  122. }
  123. }
  124. //
  125. if (removeUnwishedNodes) {
  126. unsigned int no = 0;
  127. if (oc.exists("geometry.remove")&&oc.getBool("geometry.remove")) {
  128. PROGRESS_BEGIN_MESSAGE("Removing empty nodes and geometry nodes");
  129. no = myNodeCont.removeUnwishedNodes(myDistrictCont, myEdgeCont, myJoinedEdges, myTLLCont, true);
  130. } else {
  131. PROGRESS_BEGIN_MESSAGE("Removing empty nodes");
  132. no = myNodeCont.removeUnwishedNodes(myDistrictCont, myEdgeCont, myJoinedEdges, myTLLCont, false);
  133. }
  134. PROGRESS_DONE_MESSAGE();
  135. WRITE_MESSAGE(" " + toString(no) + " nodes removed.");
  136. }
  137. //
  138. if (oc.exists("geometry.split") && oc.getBool("geometry.split")) {
  139. PROGRESS_BEGIN_MESSAGE("Splitting geometry edges");
  140. myEdgeCont.splitGeometry(myNodeCont);
  141. PROGRESS_DONE_MESSAGE();
  142. }
  143. // MOVE TO ORIGIN
  144. //
  145. if (!oc.getBool("offset.disable-normalization") && oc.isDefault("offset.x") && oc.isDefault("offset.y")) {
  146. PROGRESS_BEGIN_MESSAGE("Moving network to origin");
  147. const SUMOReal x = -geoConvHelper.getConvBoundary().xmin();
  148. const SUMOReal y = -geoConvHelper.getConvBoundary().ymin();
  149. for (std::map<std::string, NBNode*>::const_iterator i=myNodeCont.begin(); i!=myNodeCont.end(); ++i) {
  150. (*i).second->reshiftPosition(x, y);
  151. }
  152. for (std::map<std::string, NBEdge*>::const_iterator i=myEdgeCont.begin(); i!=myEdgeCont.end(); ++i) {
  153. (*i).second->reshiftPosition(x, y);
  154. }
  155. for (std::map<std::string, NBDistrict*>::const_iterator i=myDistrictCont.begin(); i!=myDistrictCont.end(); ++i) {
  156. (*i).second->reshiftPosition(x, y);
  157. }
  158. geoConvHelper.moveConvertedBy(x, y);
  159. PROGRESS_DONE_MESSAGE();
  160. }
  161. // @todo Why?
  162. myEdgeCont.recomputeLaneShapes();
  163. // GUESS RAMPS
  164. if ((oc.exists("ramps.guess")&&oc.getBool("ramps.guess"))||(oc.exists("ramps.set")&&oc.isSet("ramps.set"))) {
  165. PROGRESS_BEGIN_MESSAGE("Guessing and setting on-/off-ramps");
  166. myNodeCont.guessRamps(oc, myEdgeCont, myDistrictCont);
  167. PROGRESS_DONE_MESSAGE();
  168. }
  169. // GUESS TLS POSITIONS
  170. PROGRESS_BEGIN_MESSAGE("Assigning nodes to traffic lights");
  171. if (oc.isSet("tls.set")) {
  172. std::vector<std::string> tlControlledNodes = oc.getStringVector("tls.set");
  173. for (std::vector<std::string>::const_iterator i=tlControlledNodes.begin(); i!=tlControlledNodes.end(); ++i) {
  174. NBNode* node = myNodeCont.retrieve(*i);
  175. if (node==0) {
  176. WRITE_WARNING("Building a tl-logic for node '" + *i + "' is not possible." + "\n The node '" + *i + "' is not known.");
  177. } else {
  178. myNodeCont.setAsTLControlled(node, myTLLCont);
  179. }
  180. }
  181. }
  182. myNodeCont.guessTLs(oc, myTLLCont);
  183. PROGRESS_DONE_MESSAGE();
  184. //
  185. if (oc.getBool("tls.join")) {
  186. PROGRESS_BEGIN_MESSAGE("Joining traffic light nodes");
  187. myNodeCont.joinTLS(myTLLCont);
  188. PROGRESS_DONE_MESSAGE();
  189. }
  190. //
  191. PROGRESS_BEGIN_MESSAGE("Computing turning directions");
  192. myEdgeCont.computeTurningDirections();
  193. PROGRESS_DONE_MESSAGE();
  194. //
  195. PROGRESS_BEGIN_MESSAGE("Sorting nodes' edges");
  196. myNodeCont.sortNodesEdges(oc.getBool("lefthand"));
  197. PROGRESS_DONE_MESSAGE();
  198. //
  199. PROGRESS_BEGIN_MESSAGE("Computing node types");
  200. myNodeCont.computeNodeTypes(myTypeCont);
  201. PROGRESS_DONE_MESSAGE();
  202. //
  203. PROGRESS_BEGIN_MESSAGE("Computing priorities");
  204. myNodeCont.computePriorities();
  205. PROGRESS_DONE_MESSAGE();
  206. //
  207. if (oc.getBool("roundabouts.guess")) {
  208. PROGRESS_BEGIN_MESSAGE("Guessing and setting roundabouts");
  209. myEdgeCont.guessRoundabouts(myRoundabouts);
  210. PROGRESS_DONE_MESSAGE();
  211. }
  212. //
  213. PROGRESS_BEGIN_MESSAGE("Computing approached edges");
  214. myEdgeCont.computeEdge2Edges(oc.getBool("no-left-connections"));
  215. PROGRESS_DONE_MESSAGE();
  216. //
  217. PROGRESS_BEGIN_MESSAGE("Computing approaching lanes");
  218. myEdgeCont.computeLanes2Edges();
  219. PROGRESS_DONE_MESSAGE();
  220. //
  221. PROGRESS_BEGIN_MESSAGE("Dividing of lanes on approached lanes");
  222. myNodeCont.computeLanes2Lanes();
  223. myEdgeCont.sortOutgoingLanesConnections();
  224. PROGRESS_DONE_MESSAGE();
  225. //
  226. PROGRESS_BEGIN_MESSAGE("Processing turnarounds");
  227. if (!oc.getBool("no-turnarounds")) {
  228. myEdgeCont.appendTurnarounds(oc.getBool("no-turnarounds.tls"));
  229. } else {
  230. myEdgeCont.appendTurnarounds(explicitTurnarounds, oc.getBool("no-turnarounds.tls"));
  231. }
  232. PROGRESS_DONE_MESSAGE();
  233. //
  234. PROGRESS_BEGIN_MESSAGE("Rechecking of lane endings");
  235. myEdgeCont.recheckLanes();
  236. PROGRESS_DONE_MESSAGE();
  237. //
  238. PROGRESS_BEGIN_MESSAGE("Computing node shapes");
  239. myNodeCont.computeNodeShapes(oc.getBool("lefthand"));
  240. PROGRESS_DONE_MESSAGE();
  241. //
  242. PROGRESS_BEGIN_MESSAGE("Computing edge shapes");
  243. myEdgeCont.computeEdgeShapes();
  244. PROGRESS_DONE_MESSAGE();
  245. //
  246. PROGRESS_BEGIN_MESSAGE("Computing traffic light control information");
  247. myTLLCont.setTLControllingInformation(myEdgeCont);
  248. PROGRESS_DONE_MESSAGE();
  249. //
  250. PROGRESS_BEGIN_MESSAGE("Computing node logics");
  251. myNodeCont.computeLogics(myEdgeCont, oc);
  252. PROGRESS_DONE_MESSAGE();
  253. //
  254. PROGRESS_BEGIN_MESSAGE("Computing traffic light logics");
  255. std::pair<unsigned int, unsigned int> numbers = myTLLCont.computeLogics(myEdgeCont, oc);
  256. PROGRESS_DONE_MESSAGE();
  257. std::string progCount = "";
  258. if (numbers.first != numbers.second) {
  259. progCount = "(" + toString(numbers.second) + " programs) ";
  260. }
  261. WRITE_MESSAGE(" " + toString(numbers.first) + " traffic light(s) " + progCount + "computed.");
  262. if (!oc.getBool("no-internal-links")) {
  263. PROGRESS_BEGIN_MESSAGE("Building inner edges");
  264. for (std::map<std::string, NBEdge*>::const_iterator i=myEdgeCont.begin(); i!=myEdgeCont.end(); ++i) {
  265. (*i).second->sortOutgoingConnectionsByIndex();
  266. }
  267. for (std::map<std::string, NBNode*>::const_iterator i=myNodeCont.begin(); i!=myNodeCont.end(); ++i) {
  268. (*i).second->buildInnerEdges();
  269. }
  270. PROGRESS_DONE_MESSAGE();
  271. }
  272. // report
  273. WRITE_MESSAGE("-----------------------------------------------------");
  274. WRITE_MESSAGE("Summary:");
  275. if (!gSuppressMessages) {
  276. myNodeCont.printBuiltNodesStatistics();
  277. }
  278. WRITE_MESSAGE(" Network boundaries:");
  279. WRITE_MESSAGE(" Original boundary : " + toString(geoConvHelper.getOrigBoundary()));
  280. WRITE_MESSAGE(" Applied offset : " + toString(geoConvHelper.getOffsetBase()));
  281. WRITE_MESSAGE(" Converted boundary : " + toString(geoConvHelper.getConvBoundary()));
  282. WRITE_MESSAGE("-----------------------------------------------------");
  283. NBRequest::reportWarnings();
  284. }
  285. /****************************************************************************/