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 node_with_incoming_finder
00107  * ----------------------------------------------------------------------- */
00108 NBContHelper::node_with_incoming_finder::node_with_incoming_finder(const NBEdge* const e)
00109     : myEdge(e) {}
00110 
00111 
00112 bool
00113 NBContHelper::node_with_incoming_finder::operator()(const NBNode* const n) const {
00114     const EdgeVector& incoming = n->getIncomingEdges();
00115     return std::find(incoming.begin(), incoming.end(), myEdge) != incoming.end();
00116 }
00117 
00118 
00119 
00120 /* -------------------------------------------------------------------------
00121  * methods from node_with_outgoing_finder
00122  * ----------------------------------------------------------------------- */
00123 NBContHelper::node_with_outgoing_finder::node_with_outgoing_finder(const NBEdge* const e)
00124     : myEdge(e) {}
00125 
00126 
00127 bool
00128 NBContHelper::node_with_outgoing_finder::operator()(const NBNode* const n) const {
00129     const EdgeVector& outgoing = n->getOutgoingEdges();
00130     return std::find(outgoing.begin(), outgoing.end(), myEdge) != outgoing.end();
00131 }
00132 
00133 
00134 
00135 /* -------------------------------------------------------------------------
00136  * methods from !!!
00137  * ----------------------------------------------------------------------- */
00138 NBContHelper::edge_with_destination_finder::edge_with_destination_finder(NBNode* dest)
00139     : myDestinationNode(dest) {}
00140 
00141 
00142 bool
00143 NBContHelper::edge_with_destination_finder::operator()(NBEdge* e) const {
00144     return e->getToNode() == myDestinationNode;
00145 }
00146 
00147 
00148 std::ostream&
00149 operator<<(std::ostream& os, const EdgeVector& ev) {
00150     for (EdgeVector::const_iterator i = ev.begin(); i != ev.end(); i++) {
00151         if (i != ev.begin()) {
00152             os << ", ";
00153         }
00154         os << (*i)->getID();
00155     }
00156     return os;
00157 }
00158 
00159 
00160 
00161 
00162 SUMOReal
00163 NBContHelper::getMaxSpeed(const EdgeVector& edges) {
00164     if (edges.size() == 0) {
00165         return -1;
00166     }
00167     SUMOReal ret = (*(edges.begin()))->getSpeed();
00168     for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
00169         if ((*i)->getSpeed() > ret) {
00170             ret = (*i)->getSpeed();
00171         }
00172     }
00173     return ret;
00174 }
00175 
00176 
00177 SUMOReal
00178 NBContHelper::getMinSpeed(const EdgeVector& edges) {
00179     if (edges.size() == 0) {
00180         return -1;
00181     }
00182     SUMOReal ret = (*(edges.begin()))->getSpeed();
00183     for (EdgeVector::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
00184         if ((*i)->getSpeed() < ret) {
00185             ret = (*i)->getSpeed();
00186         }
00187     }
00188     return ret;
00189 }
00190 
00191 
00192 
00193 /****************************************************************************/
00194 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines