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 /****************************************************************************/
17 // Calculators for route costs and probabilities
18 /****************************************************************************/
19 #ifndef GawronCalculator_h
20 #define GawronCalculator_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <map>
30 
31 
32 // ===========================================================================
33 // class definitions
34 // ===========================================================================
39 template<class R, class E, class V>
40 class GawronCalculator : public RouteCostCalculator<R, E, V> {
41 public:
43  GawronCalculator(const double beta, const double a) : myBeta(beta), myA(a) {}
44 
46  virtual ~GawronCalculator() {}
47 
48  void setCosts(R* route, const double costs, const bool isActive = false) const {
49  if (isActive) {
50  route->setCosts(costs);
51  } else {
52  route->setCosts(myBeta * costs + ((double) 1.0 - myBeta) * route->getCosts());
53  }
54  }
55 
57  void calculateProbabilities(std::vector<R*> alternatives, const V* const /* veh */, const SUMOTime /* time */) {
58  for (typename std::vector<R*>::iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) {
59  R* pR = *i;
60  for (typename std::vector<R*>::iterator j = i + 1; j != alternatives.end(); j++) {
61  R* pS = *j;
62  // see [Gawron, 1998] (4.2)
63  const double delta =
64  (pS->getCosts() - pR->getCosts()) /
65  (pS->getCosts() + pR->getCosts());
66  // see [Gawron, 1998] (4.3a, 4.3b)
67  double newPR = gawronF(pR->getProbability(), pS->getProbability(), delta);
68  double newPS = pR->getProbability() + pS->getProbability() - newPR;
69  if (ISNAN(newPR) || ISNAN(newPS)) {
70  newPR = pS->getCosts() > pR->getCosts()
71  ? (double) 1. : 0;
72  newPS = pS->getCosts() > pR->getCosts()
73  ? 0 : (double) 1.;
74  }
75  newPR = MIN2((double) MAX2(newPR, (double) 0), (double) 1);
76  newPS = MIN2((double) MAX2(newPS, (double) 0), (double) 1);
77  pR->setProbability(newPR);
78  pS->setProbability(newPS);
79  }
80  }
81  }
82 
83 private:
86  double gawronF(const double pdr, const double pds, const double x) const {
87  if (pdr * gawronG(myA, x) + pds == 0) {
88  return std::numeric_limits<double>::max();
89  }
90  return (pdr * (pdr + pds) * gawronG(myA, x)) /
91  (pdr * gawronG(myA, x) + pds);
92  }
93 
96  double gawronG(const double a, const double x) const {
97  if (((1.0 - (x * x)) == 0)) {
98  return std::numeric_limits<double>::max();
99  }
100  return (double) exp((a * x) / (1.0 - (x * x)));
101  }
102 
103 private:
105  const double myBeta;
106 
108  const double myA;
109 
110 private:
113 
114 };
115 #endif
116 
117 /****************************************************************************/
118 
long long int SUMOTime
Definition: SUMOTime.h:35
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:80
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:74
Abstract base class providing static factory method.
T ISNAN(T a)
Definition: StdDefs.h:115
GawronCalculator(const double beta, const double a)
Constructor.
GawronCalculator & operator=(const GawronCalculator &s)
invalidated assignment operator
const double myBeta
gawron beta - value
void setCosts(R *route, const double costs, const bool isActive=false) const
virtual ~GawronCalculator()
Destructor.