SUMO - Simulation of Urban MObility
Distribution_Points.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The description of a distribution by a curve
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <cassert>
33 #include "Distribution.h"
35 #include "Distribution_Points.h"
36 #include <utils/common/StdDefs.h>
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  const PositionVector& points,
48  bool interpolating)
49  : Distribution(id), myPoints(points), myProbabilitiesAreComputed(false),
50  myInterpolateDist(interpolating) {}
51 
52 
54 
55 
58  assert(myPoints.size() > 0);
59  const Position& p = myPoints[-1];
60  return p.x();
61 }
62 
63 
64 int
66  return (int)myPoints.size() - 1;
67 }
68 
69 
72  return myPoints[index].x();
73 }
74 
75 
78  return myPoints[index + 1].x();
79 }
80 
81 
85  SUMOReal sum = 0;
86  if (myInterpolateDist) {
87  for (int i = 0; i < (int)myPoints.size() - 1; i++) {
88  SUMOReal width = getAreaEnd(i) - getAreaBegin(i);
89  SUMOReal minval = MIN2(myPoints[i].y(), myPoints[i].y());
90  SUMOReal maxval = MAX2(myPoints[i].y(), myPoints[i].y());
91  SUMOReal amount = minval * width + (maxval - minval) * width / (SUMOReal) 2.;
92  myProbabilities.push_back(amount);
93  sum += amount;
94  }
95  } else {
96  for (int i = 0; i < (int)myPoints.size() - 1; i++) {
97  myProbabilities.push_back(myPoints[i].y());
98  sum += myPoints[i].y();
99  }
100  }
101  // normalize
102  if (myInterpolateDist) {
103  for (int i = 0; i < (int)myPoints.size() - 1; i++) {
104  myProbabilities[i] = myProbabilities[i] / sum;
105  }
106  } else {
107  for (int i = 0; i < (int)myPoints.size() - 1; i++) {
108  myProbabilities[i] = myProbabilities[i] / sum;
109  }
110  }
112  }
113  return myProbabilities[index];
114 }
115 
116 
117 
118 /****************************************************************************/
119 
T MAX2(T a, T b)
Definition: StdDefs.h:75
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal getAreaPerc(int index) const
A list of positions.
virtual ~Distribution_Points()
Destructor.
T MIN2(T a, T b)
Definition: StdDefs.h:69
PositionVector myPoints
The list of points that describe the distribution.
Distribution_Points(const std::string &id, const PositionVector &points, bool interpolating=false)
Constructor.
SUMOReal getMax() const
Returns the maximum value of this distribution.
SUMOReal getAreaEnd(int index) const
#define SUMOReal
Definition: config.h:213
SUMOReal getAreaBegin(int index) const
std::vector< SUMOReal > myProbabilities