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