Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GawronCalculator.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2026 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// Calculators for route costs and probabilities
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <vector>
26#include <map>
27
28#include "RouteCostCalculator.h"
29
30
31// ===========================================================================
32// class definitions
33// ===========================================================================
38template<class R, class E, class V>
39class GawronCalculator : public RouteCostCalculator<R, E, V> {
40public:
42 GawronCalculator(const double beta, const double a) : myBeta(beta), myA(a) {}
43
45 virtual ~GawronCalculator() {}
46
47 void setCosts(std::shared_ptr<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(const std::vector<std::shared_ptr<R> >& alternatives, const V* const /* veh */, const SUMOTime /* time */) {
57 for (typename std::vector<std::shared_ptr<R> >::const_iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) {
58 std::shared_ptr<R> pR = *i;
59 for (typename std::vector<std::shared_ptr<R> >::const_iterator j = i + 1; j != alternatives.end(); j++) {
60 std::shared_ptr<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 (std::isnan(newPR) || std::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
82private:
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
102private:
104 const double myBeta;
105
107 const double myA;
108
109private:
112
113};
long long int SUMOTime
Definition GUI.h:36
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
Cost calculation with Gawron's method.
virtual ~GawronCalculator()
Destructor.
GawronCalculator(const double beta, const double a)
Constructor.
const double myA
gawron a - value
double gawronF(const double pdr, const double pds, const double x) const
Performs the gawron - f() function From "Dynamic User Equilibria...".
GawronCalculator & operator=(const GawronCalculator &s)
invalidated assignment operator
double gawronG(const double a, const double x) const
Performs the gawron - g() function From "Dynamic User Equilibria...".
const double myBeta
gawron beta - value
void calculateProbabilities(const std::vector< std::shared_ptr< R > > &alternatives, const V *const, const SUMOTime)
calculate the probabilities
void setCosts(std::shared_ptr< R > route, const double costs, const bool isActive=false) const
Abstract base class providing static factory method.