00001 /****************************************************************************/ 00007 // The description of a distribution by a curve 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 // =========================================================================== 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 "Distribution.h" 00032 #include <utils/geom/Position2DVector.h> 00033 #include "Distribution_Points.h" 00034 #include <utils/common/StdDefs.h> 00035 00036 #ifdef CHECK_MEMORY_LEAKS 00037 #include <foreign/nvwa/debug_new.h> 00038 #endif // CHECK_MEMORY_LEAKS 00039 00040 00041 // =========================================================================== 00042 // method definitions 00043 // =========================================================================== 00044 Distribution_Points::Distribution_Points(const std::string &id, 00045 const Position2DVector &points, 00046 bool interpolating) throw() 00047 : Distribution(id), myPoints(points), myProbabilitiesAreComputed(false), 00048 myInterpolateDist(interpolating) {} 00049 00050 00051 Distribution_Points::~Distribution_Points() throw() {} 00052 00053 00054 SUMOReal 00055 Distribution_Points::getMax() const { 00056 assert(myPoints.size()>0); 00057 const Position2D &p = myPoints[-1]; 00058 return p.x(); 00059 } 00060 00061 00062 size_t 00063 Distribution_Points::getAreaNo() const { 00064 return myPoints.size()-1; 00065 } 00066 00067 00068 SUMOReal 00069 Distribution_Points::getAreaBegin(size_t index) const { 00070 return myPoints[(int) index].x(); 00071 } 00072 00073 00074 SUMOReal 00075 Distribution_Points::getAreaEnd(size_t index) const { 00076 return myPoints[(int) index+1].x(); 00077 } 00078 00079 00080 SUMOReal 00081 Distribution_Points::getAreaPerc(size_t index) const { 00082 if (!myProbabilitiesAreComputed) { 00083 SUMOReal sum = 0; 00084 size_t i; 00085 if (myInterpolateDist) { 00086 for (i=0; i<myPoints.size()-1; i++) { 00087 SUMOReal width = getAreaEnd(i) - getAreaBegin(i); 00088 SUMOReal minval = MIN2(myPoints[(int) i].y(), myPoints[(int) i].y()); 00089 SUMOReal maxval = MAX2(myPoints[(int) i].y(), myPoints[(int) i].y()); 00090 SUMOReal amount = minval * width + (maxval-minval) * width / (SUMOReal) 2.; 00091 myProbabilities.push_back(amount); 00092 sum += amount; 00093 } 00094 } else { 00095 for (i=0; i<myPoints.size()-1; i++) { 00096 myProbabilities.push_back(myPoints[(int) i].y()); 00097 sum += myPoints[(int) i].y(); 00098 } 00099 } 00100 // normalize 00101 if (myInterpolateDist) { 00102 for (i=0; i<myPoints.size()-1; i++) { 00103 myProbabilities[i] = myProbabilities[i] / sum; 00104 } 00105 } else { 00106 for (i=0; i<myPoints.size()-1; i++) { 00107 myProbabilities[i] = myProbabilities[i] / sum; 00108 } 00109 } 00110 myProbabilitiesAreComputed = true; 00111 } 00112 return myProbabilities[index]; 00113 } 00114 00115 00116 00117 /****************************************************************************/ 00118
1.5.6