|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A container for routes 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 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 <fstream> 00031 #include <cassert> 00032 #include "RODFRouteDesc.h" 00033 #include "RODFRouteCont.h" 00034 #include "RODFNet.h" 00035 #include <router/ROEdge.h> 00036 #include <utils/common/ToString.h> 00037 #include <utils/iodevices/OutputDevice.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 RODFRouteCont::RODFRouteCont() throw() {} 00048 00049 00050 RODFRouteCont::~RODFRouteCont() throw() { 00051 } 00052 00053 00054 void 00055 RODFRouteCont::addRouteDesc(RODFRouteDesc& desc) throw() { 00056 // routes may be duplicate as in-between routes may have different starting points 00057 if (find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc))==myRoutes.end()) { 00058 // compute route id 00059 setID(desc); 00060 myRoutes.push_back(desc); 00061 } else { 00062 RODFRouteDesc& prev = *find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc)); 00063 prev.overallProb += desc.overallProb; 00064 } 00065 } 00066 00067 00068 bool 00069 RODFRouteCont::removeRouteDesc(RODFRouteDesc& desc) throw() { 00070 std::vector<RODFRouteDesc>::const_iterator j = find_if(myRoutes.begin(), myRoutes.end(), route_finder(desc)); 00071 if (j==myRoutes.end()) { 00072 return false; 00073 } 00074 return true; 00075 } 00076 00077 00078 bool 00079 RODFRouteCont::save(std::vector<std::string> &saved, 00080 const std::string& prependix, OutputDevice& out) throw(IOError) { 00081 bool haveSavedOneAtLeast = false; 00082 for (std::vector<RODFRouteDesc>::const_iterator j=myRoutes.begin(); j!=myRoutes.end(); ++j) { 00083 const RODFRouteDesc& desc = (*j); 00084 if (find(saved.begin(), saved.end(), desc.routename)!=saved.end()) { 00085 continue; 00086 } 00087 saved.push_back((*j).routename); 00088 assert(desc.edges2Pass.size()>=1); 00089 out << " <route id=\"" << prependix << desc.routename << "\" edges=\""; 00090 for (std::vector<ROEdge*>::const_iterator k=desc.edges2Pass.begin(); k!=desc.edges2Pass.end(); k++) { 00091 if (k!=desc.edges2Pass.begin()) { 00092 out << ' '; 00093 } 00094 out << (*k)->getID(); 00095 } 00096 out << "\"/>\n"; 00097 haveSavedOneAtLeast = true; 00098 } 00099 return haveSavedOneAtLeast; 00100 } 00101 00102 00103 void 00104 RODFRouteCont::sortByDistance() throw() { 00105 sort(myRoutes.begin(), myRoutes.end(), by_distance_sorter()); 00106 } 00107 00108 00109 void 00110 RODFRouteCont::removeIllegal(const std::vector<std::vector<ROEdge*> > &illegals) throw() { 00111 for (std::vector<RODFRouteDesc>::iterator i=myRoutes.begin(); i!=myRoutes.end();) { 00112 RODFRouteDesc& desc = *i; 00113 bool remove = false; 00114 for (std::vector<std::vector<ROEdge*> >::const_iterator j=illegals.begin(); !remove&&j!=illegals.end(); ++j) { 00115 int noFound = 0; 00116 for (std::vector<ROEdge*>::const_iterator k=(*j).begin(); !remove&&k!=(*j).end(); ++k) { 00117 if (find(desc.edges2Pass.begin(), desc.edges2Pass.end(), *k)!=desc.edges2Pass.end()) { 00118 noFound++; 00119 if (noFound>1) { 00120 remove = true; 00121 } 00122 } 00123 } 00124 } 00125 if (remove) { 00126 i = myRoutes.erase(i); 00127 } else { 00128 ++i; 00129 } 00130 } 00131 } 00132 00133 00134 void 00135 RODFRouteCont::addAllEndFollower() throw() { 00136 std::vector<RODFRouteDesc> newRoutes; 00137 for (std::vector<RODFRouteDesc>::iterator i=myRoutes.begin(); i!=myRoutes.end(); ++i) { 00138 RODFRouteDesc& desc = *i; 00139 ROEdge* last = *(desc.edges2Pass.end()-1); 00140 if (last->getNoFollowing()==0) { 00141 newRoutes.push_back(desc); 00142 continue; 00143 } 00144 for (unsigned int j=0; j<last->getNoFollowing(); ++j) { 00145 RODFRouteDesc ndesc(desc); 00146 ndesc.edges2Pass.push_back(last->getFollower(j)); 00147 setID(ndesc); 00148 newRoutes.push_back(ndesc); 00149 } 00150 } 00151 myRoutes = newRoutes; 00152 } 00153 00154 00155 void 00156 RODFRouteCont::setID(RODFRouteDesc& desc) const throw() { 00157 std::pair<ROEdge*, ROEdge*> c(desc.edges2Pass[0], desc.edges2Pass.back()); 00158 desc.routename = c.first->getID() + "_to_" + c.second->getID(); 00159 if (myConnectionOccurences.find(c)==myConnectionOccurences.end()) { 00160 myConnectionOccurences[c] = 0; 00161 } else { 00162 myConnectionOccurences[c] = myConnectionOccurences[c] + 1; 00163 desc.routename = desc.routename + "_" + toString(myConnectionOccurences[c]); 00164 } 00165 } 00166 00167 00168 00169 /****************************************************************************/ 00170