SUMO - Simulation of Urban MObility
NBAlgorithms.h
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Algorithms for network computation
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 #ifndef NBAlgorithms_h
00021 #define NBAlgorithms_h
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include <map>
00034 
00035 
00036 // ===========================================================================
00037 // class declarations
00038 // ===========================================================================
00039 class NBEdge;
00040 class NBNodeCont;
00041 class NBTypeCont;
00042 
00043 // ===========================================================================
00044 // class definitions
00045 // ===========================================================================
00046 // ---------------------------------------------------------------------------
00047 // NBTurningDirectionsComputer
00048 // ---------------------------------------------------------------------------
00049 /* @class NBTurningDirectionsComputer
00050  * @brief Computes turnaround destinations for all edges (if exist)
00051  */
00052 class NBTurningDirectionsComputer {
00053 public:
00057     static void computeTurnDirections(NBNodeCont &nc);
00058 
00063     static void computeTurnDirectionsForNode(NBNode* node);
00064 
00065 private:
00072     struct Combination {
00073         NBEdge *from;
00074         NBEdge *to;
00075         SUMOReal angle;
00076     };
00077 
00078 
00082     class combination_by_angle_sorter {
00083     public:
00084         explicit combination_by_angle_sorter() { }
00085         int operator()(const Combination& c1, const Combination& c2) const {
00086             if (c1.angle!=c2.angle) {
00087                 return c1.angle > c2.angle;
00088             }
00089             if (c1.from!=c2.from) {
00090                 return c1.from->getID() < c2.from->getID();
00091             }
00092             return c1.to->getID() < c2.to->getID();
00093         }
00094     };
00095 };
00096 
00097 
00098 
00099 // ---------------------------------------------------------------------------
00100 // NBNodesEdgesSorter
00101 // ---------------------------------------------------------------------------
00102 /* @class NBNodesEdgesSorter
00103  * @brief Sorts a node's edges clockwise regarding driving direction
00104  */
00105 class NBNodesEdgesSorter {
00106 public:
00111     static void sortNodesEdges(NBNodeCont &nc, bool leftHand);
00112 
00113 private:
00120     static void swapWhenReversed(const NBNode * const n, bool leftHand,
00121                           const std::vector<NBEdge*>::iterator& i1,
00122                           const std::vector<NBEdge*>::iterator& i2);
00123 
00124 
00128     class edge_by_junction_angle_sorter {
00129     public:
00130         explicit edge_by_junction_angle_sorter(NBNode* n) : myNode(n) {}
00131         int operator()(NBEdge* e1, NBEdge* e2) const {
00132             return getConvAngle(e1) < getConvAngle(e2);
00133         }
00134 
00135     private:
00137         SUMOReal getConvAngle(NBEdge* e) const {
00138             SUMOReal angle = e->getAngleAtNode(myNode);
00139             if (angle < 0.) {
00140                 angle = 360. + angle;
00141             }
00142             // convert angle if the edge is an outgoing edge
00143             if (e->getFromNode() == myNode) {
00144                 angle += (SUMOReal) 180.;
00145                 if (angle >= (SUMOReal) 360.) {
00146                     angle -= (SUMOReal) 360.;
00147                 }
00148             }
00149             if (angle < 0.1 || angle > 359.9) {
00150                 angle = (SUMOReal) 0.;
00151             }
00152             assert(angle >= (SUMOReal)0 && angle < (SUMOReal)360);
00153             return angle;
00154         }
00155 
00156     private:
00158         NBNode* myNode;
00159 
00160     };
00161 };
00162 
00163 
00164 
00165 // ---------------------------------------------------------------------------
00166 // NBNodeTypeComputer
00167 // ---------------------------------------------------------------------------
00168 /* @class NBNodeTypeComputer
00169  * @brief Computes node types
00170  */
00171 class NBNodeTypeComputer {
00172 public:
00176     static void computeNodeTypes(NBNodeCont &nc);
00177 
00178 };
00179 
00180 
00181 
00182 // ---------------------------------------------------------------------------
00183 // NBEdgePriorityComputer
00184 // ---------------------------------------------------------------------------
00185 /* @class NBEdgePriorityComputer
00186  * @brief Computes edge priorities within a node
00187  */
00188 class NBEdgePriorityComputer {
00189 public:
00193     static void computeEdgePriorities(NBNodeCont &nc);
00194 
00195 private:
00199     static void setPriorityJunctionPriorities(NBNode &n);
00200 
00206     static NBEdge* extractAndMarkFirst(NBNode &n, std::vector<NBEdge*>& s);
00207 
00213     static bool samePriority(const NBEdge*const e1, const NBEdge*const e2);
00214 
00215 };
00216 
00217 #endif
00218 
00219 /****************************************************************************/
00220 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines