NBContHelper.cpp

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

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6