SUMO - Simulation of Urban MObility
GawronCalculator.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // Calculators for route costs and probabilities
20 /****************************************************************************/
21 #ifndef GawronCalculator_h
22 #define GawronCalculator_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <map>
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
45 template<class R, class E, class V>
46 class GawronCalculator : public RouteCostCalculator<R, E, V> {
47 public:
49  GawronCalculator(const double beta, const double a) : myBeta(beta), myA(a) {}
50 
52  virtual ~GawronCalculator() {}
53 
54  void setCosts(R* route, const double costs, const bool isActive = false) const {
55  if (isActive) {
56  route->setCosts(costs);
57  } else {
58  route->setCosts(myBeta * costs + ((double) 1.0 - myBeta) * route->getCosts());
59  }
60  }
61 
63  void calculateProbabilities(std::vector<R*> alternatives, const V* const /* veh */, const SUMOTime /* time */) {
64  for (typename std::vector<R*>::iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) {
65  R* pR = *i;
66  for (typename std::vector<R*>::iterator j = i + 1; j != alternatives.end(); j++) {
67  R* pS = *j;
68  // see [Gawron, 1998] (4.2)
69  const double delta =
70  (pS->getCosts() - pR->getCosts()) /
71  (pS->getCosts() + pR->getCosts());
72  // see [Gawron, 1998] (4.3a, 4.3b)
73  double newPR = gawronF(pR->getProbability(), pS->getProbability(), delta);
74  double newPS = pR->getProbability() + pS->getProbability() - newPR;
75  if (ISNAN(newPR) || ISNAN(newPS)) {
76  newPR = pS->getCosts() > pR->getCosts()
77  ? (double) 1. : 0;
78  newPS = pS->getCosts() > pR->getCosts()
79  ? 0 : (double) 1.;
80  }
81  newPR = MIN2((double) MAX2(newPR, (double) 0), (double) 1);
82  newPS = MIN2((double) MAX2(newPS, (double) 0), (double) 1);
83  pR->setProbability(newPR);
84  pS->setProbability(newPS);
85  }
86  }
87  }
88 
89 private:
92  double gawronF(const double pdr, const double pds, const double x) const {
93  if (pdr * gawronG(myA, x) + pds == 0) {
94  return std::numeric_limits<double>::max();
95  }
96  return (pdr * (pdr + pds) * gawronG(myA, x)) /
97  (pdr * gawronG(myA, x) + pds);
98  }
99 
102  double gawronG(const double a, const double x) const {
103  if (((1.0 - (x * x)) == 0)) {
104  return std::numeric_limits<double>::max();
105  }
106  return (double) exp((a * x) / (1.0 - (x * x)));
107  }
108 
109 private:
111  const double myBeta;
112 
114  const double myA;
115 
116 private:
119 
120 };
121 #endif
122 
123 /****************************************************************************/
124 
void calculateProbabilities(std::vector< R *> alternatives, const V *const, const SUMOTime)
calculate the probabilities
double gawronG(const double a, const double x) const
Performs the gawron - g() function From "Dynamic User Equilibria...".
const double myA
gawron a - value
T MAX2(T a, T b)
Definition: StdDefs.h:73
double gawronF(const double pdr, const double pds, const double x) const
Performs the gawron - f() function From "Dynamic User Equilibria...".
Cost calculation with Gawron&#39;s method.
T MIN2(T a, T b)
Definition: StdDefs.h:67
Abstract base class providing static factory method.
T ISNAN(T a)
Definition: StdDefs.h:108
GawronCalculator(const double beta, const double a)
Constructor.
GawronCalculator & operator=(const GawronCalculator &s)
invalidated assignment operator
const double myBeta
gawron beta - value
long long int SUMOTime
Definition: TraCIDefs.h:51
void setCosts(R *route, const double costs, const bool isActive=false) const
virtual ~GawronCalculator()
Destructor.