SUMO - Simulation of Urban MObility
Distribution_Points.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // The description of a distribution by a curve
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
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 <cassert>
00033 #include "Distribution.h"
00034 #include <utils/geom/PositionVector.h>
00035 #include "Distribution_Points.h"
00036 #include <utils/common/StdDefs.h>
00037 
00038 #ifdef CHECK_MEMORY_LEAKS
00039 #include <foreign/nvwa/debug_new.h>
00040 #endif // CHECK_MEMORY_LEAKS
00041 
00042 
00043 // ===========================================================================
00044 // method definitions
00045 // ===========================================================================
00046 Distribution_Points::Distribution_Points(const std::string& id,
00047         const PositionVector& points,
00048         bool interpolating)
00049     : Distribution(id), myPoints(points), myProbabilitiesAreComputed(false),
00050       myInterpolateDist(interpolating) {}
00051 
00052 
00053 Distribution_Points::~Distribution_Points() {}
00054 
00055 
00056 SUMOReal
00057 Distribution_Points::getMax() const {
00058     assert(myPoints.size() > 0);
00059     const Position& p = myPoints[-1];
00060     return p.x();
00061 }
00062 
00063 
00064 size_t
00065 Distribution_Points::getAreaNo() const {
00066     return myPoints.size() - 1;
00067 }
00068 
00069 
00070 SUMOReal
00071 Distribution_Points::getAreaBegin(size_t index) const {
00072     return myPoints[(int) index].x();
00073 }
00074 
00075 
00076 SUMOReal
00077 Distribution_Points::getAreaEnd(size_t index) const {
00078     return myPoints[(int) index + 1].x();
00079 }
00080 
00081 
00082 SUMOReal
00083 Distribution_Points::getAreaPerc(size_t index) const {
00084     if (!myProbabilitiesAreComputed) {
00085         SUMOReal sum = 0;
00086         size_t i;
00087         if (myInterpolateDist) {
00088             for (i = 0; i < myPoints.size() - 1; i++) {
00089                 SUMOReal width = getAreaEnd(i) - getAreaBegin(i);
00090                 SUMOReal minval = MIN2(myPoints[(int) i].y(), myPoints[(int) i].y());
00091                 SUMOReal maxval = MAX2(myPoints[(int) i].y(), myPoints[(int) i].y());
00092                 SUMOReal amount = minval * width + (maxval - minval) * width / (SUMOReal) 2.;
00093                 myProbabilities.push_back(amount);
00094                 sum += amount;
00095             }
00096         } else {
00097             for (i = 0; i < myPoints.size() - 1; i++) {
00098                 myProbabilities.push_back(myPoints[(int) i].y());
00099                 sum += myPoints[(int) i].y();
00100             }
00101         }
00102         // normalize
00103         if (myInterpolateDist) {
00104             for (i = 0; i < myPoints.size() - 1; i++) {
00105                 myProbabilities[i] = myProbabilities[i] / sum;
00106             }
00107         } else {
00108             for (i = 0; i < myPoints.size() - 1; i++) {
00109                 myProbabilities[i] = myProbabilities[i] / sum;
00110             }
00111         }
00112         myProbabilitiesAreComputed = true;
00113     }
00114     return myProbabilities[index];
00115 }
00116 
00117 
00118 
00119 /****************************************************************************/
00120 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines