SUMO - Simulation of Urban MObility

NBContHelper.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Some methods for traversing lists of edges
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
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 <vector>
00034 #include <map>
00035 #include <cassert>
00036 #include "NBContHelper.h"
00037 #include <utils/geom/GeomHelper.h>
00038 
00039 #ifdef CHECK_MEMORY_LEAKS
00040 #include <foreign/nvwa/debug_new.h>
00041 #endif // CHECK_MEMORY_LEAKS
00042 
00043 
00044 // ===========================================================================
00045 // method definitions
00046 // ===========================================================================
00047 /* -------------------------------------------------------------------------
00048  * utility methods
00049  * ----------------------------------------------------------------------- */
00050 void
00051 NBContHelper::nextCW(const EdgeVector& edges, EdgeVector::const_iterator& from) {
00052     from++;
00053     if (from == edges.end()) {
00054         from = edges.begin();
00055     }
00056 }
00057 
00058 
00059 void
00060 NBContHelper::nextCCW(const EdgeVector& edges, EdgeVector::const_iterator& from) {
00061     if (from == edges.begin()) {
00062         from = edges.end() - 1;
00063     } else {
00064         --from;
00065     }
00066 }
00067 
00068 
00069 std::ostream&
00070 NBContHelper::out(std::ostream& os, const std::vector<bool> &v) {
00071     for (std::vector<bool>::const_iterator i = v.begin(); i != v.end(); i++) {
00072         os << *i;
00073     }
00074     return os;
00075 }
00076 
00077 
00078 NBEdge*
00079 NBContHelper::findConnectingEdge(const EdgeVector& edges,
00080                                  NBNode* from, NBNode* to) {
00081     for (EdgeVector::const_iterator i = edges.begin(); i != edges.end(); i++) {
00082         if ((*i)->getToNode() == to && (*i)->getFromNode() == from) {
00083             return *i;
00084         }
00085     }
00086     return 0;
00087 }
00088 
00089 
00090 
00091 SUMOReal
00092 NBContHelper::maxSpeed(const EdgeVector& ev) {
00093     assert(ev.size() > 0);
00094     SUMOReal max = (*(ev.begin()))->getSpeed();
00095     for (EdgeVector::const_iterator i = ev.begin() + 1; i != ev.end(); i++) {
00096         max =
00097             max > (*i)->getSpeed()
00098             ? max : (*i)->getSpeed();
00099     }
00100     return max;
00101 }
00102 
00103 
00104 
00105 /* -------------------------------------------------------------------------
00106  * methods from edge_by_junction_angle_sorter
00107  * ----------------------------------------------------------------------- */
00108 int
00109 NBContHelper::edge_by_junction_angle_sorter::operator()(NBEdge* e1, NBEdge* e2) const {
00110     return getConvAngle(e1) < getConvAngle(e2);
00111 }
00112 
00113 
00114 
00115 SUMOReal
00116 NBContHelper::edge_by_junction_angle_sorter::getConvAngle(NBEdge* e) const {
00117 
00118     SUMOReal angle;
00119     // convert angle if the edge is an outgoing edge
00120     if (e->getFromNode() == myNode) {
00121         angle = e->getNormedAngle(*myNode);
00122         angle += (SUMOReal) 180.;
00123         if (angle >= (SUMOReal) 360.) {
00124             angle -= (SUMOReal) 360.;
00125         }
00126     } else {
00127         angle = e->getNormedAngle(*myNode);
00128     }
00129     if (angle < 0.1 || angle > 359.9) {
00130         angle = (SUMOReal) 0.;
00131     }
00132     assert(angle >= (SUMOReal)0 && angle < (SUMOReal)360);
00133     return angle;
00134 }
00135 
00136 
00137 
00138 /* -------------------------------------------------------------------------
00139  * methods from node_with_incoming_finder
00140  * ----------------------------------------------------------------------- */
00141 NBContHelper::node_with_incoming_finder::node_with_incoming_finder(const NBEdge* const e)
00142     : myEdge(e) {}
00143 
00144 
00145 bool
00146 NBContHelper::node_with_incoming_finder::operator()(const NBNode* const n) const {
00147     const EdgeVector& incoming = n->getIncomingEdges();
00148     return std::find(incoming.begin(), incoming.end(), myEdge) != incoming.end();
00149 }
00150 
00151 
00152 
00153 /* -------------------------------------------------------------------------
00154  * methods from node_with_outgoing_finder
00155  * ----------------------------------------------------------------------- */
00156 NBContHelper::node_with_outgoing_finder::node_with_outgoing_finder(const NBEdge* const e)
00157     : myEdge(e) {}
00158 
00159 
00160 bool
00161 NBContHelper::node_with_outgoing_finder::operator()(const NBNode* const n) const {
00162     const EdgeVector& outgoing = n->getOutgoingEdges();
00163     return std::find(outgoing.begin(), outgoing.end(), myEdge) != outgoing.end();
00164 }
00165 
00166 
00167 
00168 /* -------------------------------------------------------------------------
00169  * methods from !!!
00170  * ----------------------------------------------------------------------- */
00171 NBContHelper::edge_with_destination_finder::edge_with_destination_finder(NBNode* dest)
00172     : myDestinationNode(dest) {}
00173 
00174 
00175 bool
00176 NBContHelper::edge_with_destination_finder::operator()(NBEdge* e) const {
00177     return e->getToNode() == myDestinationNode;
00178 }
00179 
00180 
00181 std::ostream&
00182 operator<<(std::ostream& os, const EdgeVector& ev) {
00183     for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); i++) {
00184         if (i != ev.begin()) {
00185             os << ", ";
00186         }
00187         os << (*i)->getID();
00188     }
00189     return os;
00190 }
00191 
00192 
00193 
00194 
00195 SUMOReal
00196 NBContHelper::getMaxSpeed(const EdgeVector& edges) {
00197     if (edges.size() == 0) {
00198         return -1;
00199     }
00200     SUMOReal ret = (*(edges.begin()))->getSpeed();
00201     for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
00202         if ((*i)->getSpeed() > ret) {
00203             ret = (*i)->getSpeed();
00204         }
00205     }
00206     return ret;
00207 }
00208 
00209 
00210 SUMOReal
00211 NBContHelper::getMinSpeed(const EdgeVector& edges) {
00212     if (edges.size() == 0) {
00213         return -1;
00214     }
00215     SUMOReal ret = (*(edges.begin()))->getSpeed();
00216     for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
00217         if ((*i)->getSpeed() < ret) {
00218             ret = (*i)->getSpeed();
00219         }
00220     }
00221     return ret;
00222 }
00223 
00224 
00225 
00226 /****************************************************************************/
00227 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines