SUMO - Simulation of Urban MObility
GawronCalculator.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // Calculators for route costs and probabilities
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef GawronCalculator_h
23 #define GawronCalculator_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <map>
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
46 template<class R, class E, class V>
47 class GawronCalculator : public RouteCostCalculator<R, E, V> {
48 public:
50  GawronCalculator(const SUMOReal beta, const SUMOReal a) : myBeta(beta), myA(a) {}
51 
53  virtual ~GawronCalculator() {}
54 
55  void setCosts(R* route, const SUMOReal costs, const bool isActive = false) const {
56  if (isActive) {
57  route->setCosts(costs);
58  } else {
59  route->setCosts(myBeta * costs + ((SUMOReal) 1.0 - myBeta) * route->getCosts());
60  }
61  }
62 
64  void calculateProbabilities(std::vector<R*> alternatives, const V* const /* veh */, const SUMOTime /* time */) {
65  for (typename std::vector<R*>::iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) {
66  R* pR = *i;
67  for (typename std::vector<R*>::iterator j = i + 1; j != alternatives.end(); j++) {
68  R* pS = *j;
69  // see [Gawron, 1998] (4.2)
70  const SUMOReal delta =
71  (pS->getCosts() - pR->getCosts()) /
72  (pS->getCosts() + pR->getCosts());
73  // see [Gawron, 1998] (4.3a, 4.3b)
74  SUMOReal newPR = gawronF(pR->getProbability(), pS->getProbability(), delta);
75  SUMOReal newPS = pR->getProbability() + pS->getProbability() - newPR;
76  if (ISNAN(newPR) || ISNAN(newPS)) {
77  newPR = pS->getCosts() > pR->getCosts()
78  ? (SUMOReal) 1. : 0;
79  newPS = pS->getCosts() > pR->getCosts()
80  ? 0 : (SUMOReal) 1.;
81  }
82  newPR = MIN2((SUMOReal) MAX2(newPR, (SUMOReal) 0), (SUMOReal) 1);
83  newPS = MIN2((SUMOReal) MAX2(newPS, (SUMOReal) 0), (SUMOReal) 1);
84  pR->setProbability(newPR);
85  pS->setProbability(newPS);
86  }
87  }
88  }
89 
90 private:
93  SUMOReal gawronF(const SUMOReal pdr, const SUMOReal pds, const SUMOReal x) const {
94  if (pdr * gawronG(myA, x) + pds == 0) {
96  }
97  return (pdr * (pdr + pds) * gawronG(myA, x)) /
98  (pdr * gawronG(myA, x) + pds);
99  }
100 
103  SUMOReal gawronG(const SUMOReal a, const SUMOReal x) const {
104  if (((1.0 - (x * x)) == 0)) {
106  }
107  return (SUMOReal) exp((a * x) / (1.0 - (x * x)));
108  }
109 
110 private:
113 
115  const SUMOReal myA;
116 
117 private:
120 
121 };
122 #endif
123 
124 /****************************************************************************/
125 
const SUMOReal myBeta
gawron beta - value
SUMOReal gawronG(const SUMOReal a, const SUMOReal x) const
Performs the gawron - g() function From "Dynamic User Equilibria...".
T MAX2(T a, T b)
Definition: StdDefs.h:74
#define max(a, b)
Definition: polyfonts.c:65
Cost calculation with Gawron's method.
T MIN2(T a, T b)
Definition: StdDefs.h:68
SUMOReal gawronF(const SUMOReal pdr, const SUMOReal pds, const SUMOReal x) const
Performs the gawron - f() function From "Dynamic User Equilibria...".
Abstract base class providing static factory method.
T ISNAN(T a)
Definition: StdDefs.h:109
void setCosts(R *route, const SUMOReal costs, const bool isActive=false) const
GawronCalculator & operator=(const GawronCalculator &s)
invalidated assignment operator
void calculateProbabilities(std::vector< R * > alternatives, const V *const , const SUMOTime)
calculate the probabilities
int SUMOTime
Definition: SUMOTime.h:43
#define SUMOReal
Definition: config.h:218
GawronCalculator(const SUMOReal beta, const SUMOReal a)
Constructor.
const SUMOReal myA
gawron a - value
virtual ~GawronCalculator()
Destructor.