MSEdgeWeightsStorage.cpp

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

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6