SUMO - Simulation of Urban MObility
ROHelper.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // Some helping methods for router
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #ifdef _MSC_VER
00026 #include <windows_config.h>
00027 #else
00028 #include <config.h>
00029 #endif
00030 
00031 #include <functional>
00032 #include <vector>
00033 #include "ROEdge.h"
00034 #include "ROVehicle.h"
00035 
00036 
00037 // ===========================================================================
00038 // class definitions
00039 // ===========================================================================
00040 
00041 
00042 namespace ROHelper {
00043 /*
00044 SUMOReal
00045 recomputeCosts(SUMOAbstractRouter<ROEdge,ROVehicle> &router,
00046                const std::vector<const ROEdge*> &edges,
00047                const ROVehicle * const v, SUMOTime time) {
00048     SUMOReal costs = 0;
00049     for (std::vector<const ROEdge*>::const_iterator i=edges.begin(); i!=edges.end(); i++) {
00050         costs += router.getEffort(v, time + costs, *i);
00051         if ((*i)->prohibits(v)) {
00052             return -1;
00053         }
00054     }
00055     return costs;
00056 }
00057 */
00058 
00059 void
00060 recheckForLoops(std::vector<const ROEdge*> &edges) {
00061     // remove loops at the route's begin
00062     //  (vehicle makes a turnaround to get into the right direction at an already passed node)
00063     RONode* start = edges[0]->getFromNode();
00064     unsigned lastStart = 0;
00065     for (unsigned i = 1; i < edges.size(); i++) {
00066         if (edges[i]->getFromNode() == start) {
00067             lastStart = i;
00068         }
00069     }
00070     if (lastStart > 0) {
00071         edges.erase(edges.begin(), edges.begin() + lastStart - 1);
00072     }
00073     // remove loops at the route's end
00074     //  (vehicle makes a turnaround to get into the right direction at an already passed node)
00075     RONode* end = edges.back()->getToNode();
00076     size_t firstEnd = edges.size() - 1;
00077     for (unsigned i = 0; i < firstEnd; i++) {
00078         if (edges[i]->getToNode() == end) {
00079             firstEnd = i;
00080         }
00081     }
00082     if (firstEnd < edges.size() - 1) {
00083         edges.erase(edges.begin() + firstEnd + 2, edges.end());
00084     }
00085     // remove loops within the route
00086     std::vector<RONode*> nodes;
00087     for (std::vector<const ROEdge*>::iterator i = edges.begin(); i != edges.end(); ++i) {
00088         nodes.push_back((*i)->getFromNode());
00089     }
00090     nodes.push_back(edges.back()->getToNode());
00091     bool changed = false;
00092     do {
00093         changed = false;
00094         for (unsigned int b = 0; b < nodes.size() && !changed; ++b) {
00095             RONode* bn = nodes[b];
00096             for (unsigned int e = b + 1; e < nodes.size() && !changed; ++e) {
00097                 if (bn == nodes[e]) {
00098                     changed = true;
00099                     nodes.erase(nodes.begin() + b, nodes.begin() + e);
00100                     edges.erase(edges.begin() + b, edges.begin() + e);
00101                 }
00102             }
00103         }
00104     } while (changed);
00105     /*
00106     */
00107 }
00108 
00109 
00110 }
00111 
00112 std::ostream& operator<<(std::ostream& os, const std::vector<const ROEdge*> &ev) {
00113     bool hadFirst = false;
00114     for (std::vector<const ROEdge*>::const_iterator j = ev.begin(); j != ev.end(); j++) {
00115         if ((*j)->getType() != ROEdge::ET_DISTRICT) {
00116             if (hadFirst) {
00117                 os << ' ';
00118             }
00119             os << (*j)->getID();
00120             hadFirst = true;
00121         }
00122     }
00123     return os;
00124 }
00125 
00126 
00127 /****************************************************************************/
00128 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines