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