ROHelper.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Some helping methods for router
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 // included modules
00022 // ===========================================================================
00023 #ifdef _MSC_VER
00024 #include <windows_config.h>
00025 #else
00026 #include <config.h>
00027 #endif
00028 
00029 #include <functional>
00030 #include <vector>
00031 #include "ROEdge.h"
00032 #include "ROVehicle.h"
00033 
00034 
00035 // ===========================================================================
00036 // class definitions
00037 // ===========================================================================
00038 
00039 
00040 namespace ROHelper {
00041 /*
00042 SUMOReal
00043 recomputeCosts(SUMOAbstractRouter<ROEdge,ROVehicle> &router,
00044                const std::vector<const ROEdge*> &edges,
00045                const ROVehicle * const v, SUMOTime time) throw() {
00046     SUMOReal costs = 0;
00047     for (std::vector<const ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); i++) {
00048         costs += router.getEffort(v, time + costs, *i);
00049         if ((*i)->prohibits(v)) {
00050             return -1;
00051         }
00052     }
00053     return costs;
00054 }
00055 */
00056 
00057 void
00058 recheckForLoops(std::vector<const ROEdge*> &edges) throw() {
00059     RONode* start = edges[0]->getFromNode();
00060     unsigned lastStart = 0;
00061     for (unsigned i=1; i<edges.size(); i++) {
00062         if (edges[i]->getFromNode() == start) {
00063             lastStart = i;
00064         }
00065     }
00066     if (lastStart > 0) {
00067         edges.erase(edges.begin(), edges.begin() + lastStart - 1);
00068     }
00069     RONode* end = edges.back()->getToNode();
00070     size_t firstEnd = edges.size()-1;
00071     for (unsigned i=0; i<firstEnd; i++) {
00072         if (edges[i]->getToNode() == end) {
00073             firstEnd = i;
00074         }
00075     }
00076     if (firstEnd < edges.size()-1) {
00077         edges.erase(edges.begin() + firstEnd + 2, edges.end());
00078     }
00079 }
00080 
00081 
00082 }
00083 
00084 std::ostream &operator<<(std::ostream &os, const std::vector<const ROEdge*> &ev) {
00085     bool hadFirst = false;
00086     for (std::vector<const ROEdge*>::const_iterator j=ev.begin(); j!=ev.end(); j++) {
00087         if ((*j)->getType() != ROEdge::ET_DISTRICT) {
00088             if (hadFirst) {
00089                 os << ' ';
00090             }
00091             os << (*j)->getID();
00092             hadFirst = true;
00093         }
00094     }
00095     return os;
00096 }
00097 
00098 
00099 /****************************************************************************/
00100 

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