SUMO - Simulation of Urban MObility
MSEdgeWeightsStorage.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // A storage for edge travel times and efforts
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 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include "MSEdgeWeightsStorage.h"
00033 
00034 #ifdef CHECK_MEMORY_LEAKS
00035 #include <foreign/nvwa/debug_new.h>
00036 #endif // CHECK_MEMORY_LEAKS
00037 
00038 
00039 // ===========================================================================
00040 // method definitions
00041 // ===========================================================================
00042 MSEdgeWeightsStorage::MSEdgeWeightsStorage() {
00043 }
00044 
00045 
00046 MSEdgeWeightsStorage::~MSEdgeWeightsStorage() {
00047 }
00048 
00049 
00050 bool
00051 MSEdgeWeightsStorage::retrieveExistingTravelTime(const MSEdge* const e, const SUMOVehicle* const /*v*/,
00052         SUMOReal t, SUMOReal& value) const {
00053     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::const_iterator i = myTravelTimes.find((MSEdge*) e);
00054     if (i == myTravelTimes.end()) {
00055         return false;
00056     }
00057     const ValueTimeLine<SUMOReal> &tl = (*i).second;
00058     if (!tl.describesTime(t)) {
00059         return false;
00060     }
00061     value = tl.getValue(t);
00062     return true;
00063 }
00064 
00065 
00066 bool
00067 MSEdgeWeightsStorage::retrieveExistingEffort(const MSEdge* const e, const SUMOVehicle* const /*v*/,
00068         SUMOReal t, SUMOReal& value) const {
00069     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::const_iterator i = myEfforts.find((MSEdge*) e);
00070     if (i == myEfforts.end()) {
00071         return false;
00072     }
00073     const ValueTimeLine<SUMOReal> &tl = (*i).second;
00074     if (!tl.describesTime(t)) {
00075         return false;
00076     }
00077     value = tl.getValue(t);
00078     return true;
00079 }
00080 
00081 
00082 void
00083 MSEdgeWeightsStorage::addTravelTime(const MSEdge* const e,
00084                                     SUMOReal begin, SUMOReal end,
00085                                     SUMOReal value) {
00086     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myTravelTimes.find((MSEdge*) e);
00087     if (i == myTravelTimes.end()) {
00088         myTravelTimes[(MSEdge*)e] = ValueTimeLine<SUMOReal>();
00089         i = myTravelTimes.find((MSEdge*) e);
00090     }
00091     (*i).second.add(begin, end, value);
00092 }
00093 
00094 
00095 void
00096 MSEdgeWeightsStorage::addEffort(const MSEdge* const e,
00097                                 SUMOReal begin, SUMOReal end,
00098                                 SUMOReal value) {
00099     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myEfforts.find((MSEdge*) e);
00100     if (i == myEfforts.end()) {
00101         myEfforts[(MSEdge*)e] = ValueTimeLine<SUMOReal>();
00102         i = myEfforts.find((MSEdge*) e);
00103     }
00104     (*i).second.add(begin, end, value);
00105 }
00106 
00107 
00108 void
00109 MSEdgeWeightsStorage::removeTravelTime(const MSEdge* const e) {
00110     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myTravelTimes.find((MSEdge*) e);
00111     if (i != myTravelTimes.end()) {
00112         myTravelTimes.erase(i);
00113     }
00114 }
00115 
00116 
00117 void
00118 MSEdgeWeightsStorage::removeEffort(const MSEdge* const e) {
00119     std::map<MSEdge*, ValueTimeLine<SUMOReal> >::iterator i = myEfforts.find((MSEdge*) e);
00120     if (i != myEfforts.end()) {
00121         myEfforts.erase(i);
00122     }
00123 }
00124 
00125 
00126 bool
00127 MSEdgeWeightsStorage::knowsTravelTime(const MSEdge* const e) const {
00128     return myTravelTimes.find((MSEdge*) e) != myTravelTimes.end();
00129 }
00130 
00131 
00132 bool
00133 MSEdgeWeightsStorage::knowsEffort(const MSEdge* const e) const {
00134     return myEfforts.find((MSEdge*) e) != myEfforts.end();
00135 }
00136 
00137 
00138 
00139 /****************************************************************************/
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines