/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2002-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file GawronCalculator.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @author Jakob Erdmann17/// @date Sept 200218///19// Calculators for route costs and probabilities20/****************************************************************************/21#pragma once22#include <config.h>2324#include <vector>25#include <map>262728// ===========================================================================29// class definitions30// ===========================================================================31/**32* @class GawronCalculator33* @brief Cost calculation with Gawron's method.34*/35template<class R, class E, class V>36class GawronCalculator : public RouteCostCalculator<R, E, V> {37public:38/// Constructor39GawronCalculator(const double beta, const double a) : myBeta(beta), myA(a) {}4041/// Destructor42virtual ~GawronCalculator() {}4344void setCosts(R* route, const double costs, const bool isActive = false) const {45if (isActive) {46route->setCosts(costs);47} else {48route->setCosts(myBeta * costs + ((double) 1.0 - myBeta) * route->getCosts());49}50}5152/** @brief calculate the probabilities */53void calculateProbabilities(std::vector<R*> alternatives, const V* const /* veh */, const SUMOTime /* time */) {54for (typename std::vector<R*>::iterator i = alternatives.begin(); i != alternatives.end() - 1; i++) {55R* pR = *i;56for (typename std::vector<R*>::iterator j = i + 1; j != alternatives.end(); j++) {57R* pS = *j;58// see [Gawron, 1998] (4.2)59const double delta =60(pS->getCosts() - pR->getCosts()) /61(pS->getCosts() + pR->getCosts());62// see [Gawron, 1998] (4.3a, 4.3b)63double newPR = gawronF(pR->getProbability(), pS->getProbability(), delta);64double newPS = pR->getProbability() + pS->getProbability() - newPR;65if (std::isnan(newPR) || std::isnan(newPS)) {66newPR = pS->getCosts() > pR->getCosts()67? (double) 1. : 0;68newPS = pS->getCosts() > pR->getCosts()69? 0 : (double) 1.;70}71newPR = MIN2((double) MAX2(newPR, (double) 0), (double) 1);72newPS = MIN2((double) MAX2(newPS, (double) 0), (double) 1);73pR->setProbability(newPR);74pS->setProbability(newPS);75}76}77}7879private:80/** @brief Performs the gawron - f() function81From "Dynamic User Equilibria..." */82double gawronF(const double pdr, const double pds, const double x) const {83if (pdr * gawronG(myA, x) + pds == 0) {84return std::numeric_limits<double>::max();85}86return (pdr * (pdr + pds) * gawronG(myA, x)) /87(pdr * gawronG(myA, x) + pds);88}8990/** @brief Performs the gawron - g() function91From "Dynamic User Equilibria..." */92double gawronG(const double a, const double x) const {93if (((1.0 - (x * x)) == 0)) {94return std::numeric_limits<double>::max();95}96return (double) exp((a * x) / (1.0 - (x * x)));97}9899private:100/// @brief gawron beta - value101const double myBeta;102103/// @brief gawron a - value104const double myA;105106private:107/** @brief invalidated assignment operator */108GawronCalculator& operator=(const GawronCalculator& s);109110};111112113