|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A class representing a single district 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 <cassert> 00031 #include <vector> 00032 #include <string> 00033 #include <utility> 00034 #include <iostream> 00035 #include <algorithm> 00036 #include <utils/common/Named.h> 00037 #include <utils/common/StringUtils.h> 00038 #include <utils/iodevices/OutputDevice.h> 00039 #include "NBEdge.h" 00040 #include "NBDistrict.h" 00041 00042 #ifdef CHECK_MEMORY_LEAKS 00043 #include <foreign/nvwa/debug_new.h> 00044 #endif // CHECK_MEMORY_LEAKS 00045 00046 00047 // =========================================================================== 00048 // member method definitions 00049 // =========================================================================== 00050 NBDistrict::NBDistrict(const std::string& id, const Position& pos) 00051 : Named(StringUtils::convertUmlaute(id)), 00052 myPosition(pos) {} 00053 00054 00055 NBDistrict::NBDistrict(const std::string& id) 00056 : Named(id), myPosition(0, 0) {} 00057 00058 00059 NBDistrict::~NBDistrict() {} 00060 00061 00062 // ----------- Applying offset 00063 void 00064 NBDistrict::reshiftPosition(SUMOReal xoff, SUMOReal yoff) { 00065 myPosition.reshiftRotate(xoff, yoff, 0); 00066 myShape.reshiftRotate(xoff, yoff, 0); 00067 } 00068 00069 00070 bool 00071 NBDistrict::addSource(NBEdge* const source, SUMOReal weight) { 00072 EdgeVector::iterator i = find(mySources.begin(), mySources.end(), source); 00073 if (i!=mySources.end()) { 00074 return false; 00075 } 00076 mySources.push_back(source); 00077 mySourceWeights.push_back(weight); 00078 assert(source->getID()!=""); 00079 return true; 00080 } 00081 00082 00083 bool 00084 NBDistrict::addSink(NBEdge* const sink, SUMOReal weight) { 00085 EdgeVector::iterator i = find(mySinks.begin(), mySinks.end(), sink); 00086 if (i!=mySinks.end()) { 00087 return false; 00088 } 00089 mySinks.push_back(sink); 00090 mySinkWeights.push_back(weight); 00091 assert(sink->getID()!=""); 00092 return true; 00093 } 00094 00095 00096 void 00097 NBDistrict::setCenter(const Position& pos) { 00098 myPosition = pos; 00099 } 00100 00101 00102 void 00103 NBDistrict::replaceIncoming(const EdgeVector& which, NBEdge* const by) { 00104 // temporary structures 00105 EdgeVector newList; 00106 WeightsCont newWeights; 00107 SUMOReal joinedVal = 0; 00108 // go through the list of sinks 00109 EdgeVector::iterator i=mySinks.begin(); 00110 WeightsCont::iterator j=mySinkWeights.begin(); 00111 for (; i!=mySinks.end(); i++, j++) { 00112 NBEdge* tmp = (*i); 00113 SUMOReal val = (*j); 00114 if (find(which.begin(), which.end(), tmp)==which.end()) { 00115 // if the current edge shall not be replaced, add to the 00116 // temporary list 00117 newList.push_back(tmp); 00118 newWeights.push_back(val); 00119 } else { 00120 // otherwise, skip it and add its weight to the one to be inserted 00121 // instead 00122 joinedVal += val; 00123 } 00124 } 00125 // add the one to be inserted instead 00126 newList.push_back(by); 00127 newWeights.push_back(joinedVal); 00128 // assign to values 00129 mySinks = newList; 00130 mySinkWeights = newWeights; 00131 } 00132 00133 00134 void 00135 NBDistrict::replaceOutgoing(const EdgeVector& which, NBEdge* const by) { 00136 // temporary structures 00137 EdgeVector newList; 00138 WeightsCont newWeights; 00139 SUMOReal joinedVal = 0; 00140 // go through the list of sinks 00141 EdgeVector::iterator i=mySources.begin(); 00142 WeightsCont::iterator j=mySourceWeights.begin(); 00143 for (; i!=mySources.end(); i++, j++) { 00144 NBEdge* tmp = (*i); 00145 SUMOReal val = (*j); 00146 if (find(which.begin(), which.end(), tmp)==which.end()) { 00147 // if the current edge shall not be replaced, add to the 00148 // temporary list 00149 newList.push_back(tmp); 00150 newWeights.push_back(val); 00151 } else { 00152 // otherwise, skip it and add its weight to the one to be inserted 00153 // instead 00154 joinedVal += val; 00155 } 00156 } 00157 // add the one to be inserted instead 00158 newList.push_back(by); 00159 newWeights.push_back(joinedVal); 00160 // assign to values 00161 mySources = newList; 00162 mySourceWeights = newWeights; 00163 } 00164 00165 00166 void 00167 NBDistrict::removeFromSinksAndSources(NBEdge* const e) { 00168 size_t i; 00169 for (i=0; i<mySinks.size(); ++i) { 00170 if (mySinks[i]==e) { 00171 mySinks.erase(mySinks.begin()+i); 00172 mySinkWeights.erase(mySinkWeights.begin()+i); 00173 } 00174 } 00175 for (i=0; i<mySources.size(); ++i) { 00176 if (mySources[i]==e) { 00177 mySources.erase(mySources.begin()+i); 00178 mySourceWeights.erase(mySourceWeights.begin()+i); 00179 } 00180 } 00181 } 00182 00183 00184 void 00185 NBDistrict::addShape(const PositionVector& p) { 00186 myShape = p; 00187 } 00188 00189 00190 00191 /****************************************************************************/ 00192