/****************************************************************************/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 RouteCostCalculator.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>26#include <cmath>27#include <utils/common/StdDefs.h>28#include <utils/common/SUMOTime.h>29#include <utils/common/RandHelper.h>30#include <utils/options/OptionsCont.h>313233// ===========================================================================34// class definitions35// ===========================================================================36/**37* @class RouteCostCalculator38* @brief Abstract base class providing static factory method.39*/40template<class R, class E, class V>41class RouteCostCalculator {42public:43static RouteCostCalculator<R, E, V>& getCalculator();4445static void cleanup() {46delete myInstance;47myInstance = 0;48}4950virtual void setCosts(R* route, const double costs, const bool isActive = false) const = 0;5152/** @brief calculate the probabilities in the logit model */53virtual void calculateProbabilities(std::vector<R*> alternatives, const V* const veh, const SUMOTime time) = 0;5455int getMaxRouteNumber() const {56return myMaxRouteNumber;57}5859bool keepAllRoutes() const {60return myKeepRoutes;61}6263bool skipRouteCalculation() const {64return mySkipNewRoutes;65}6667bool keepRoute() const {68if (myKeepRouteProb == 1) {69return true;70} else if (myKeepRouteProb == 0) {71return false;72} else {73return RandHelper::rand() < myKeepRouteProb;74}75}7677protected:78/// @brief Constructor79RouteCostCalculator() {80OptionsCont& oc = OptionsCont::getOptions();81myMaxRouteNumber = oc.getInt("max-alternatives");82myKeepRoutes = oc.getBool("keep-all-routes");83mySkipNewRoutes = oc.getBool("skip-new-routes");84myKeepRouteProb = oc.exists("keep-route-probability") ? oc.getFloat("keep-route-probability") : 0;85}8687/// @brief Destructor88virtual ~RouteCostCalculator() {}8990private:91static RouteCostCalculator* myInstance;9293/// @brief The maximum route alternatives number94int myMaxRouteNumber;9596/// @brief Information whether all routes should be saved97bool myKeepRoutes;9899/// @brief Information whether new routes shall be computed100bool mySkipNewRoutes;101102/// @brief Information whether the old route shall be kept103double myKeepRouteProb;104105};106107108// ===========================================================================109// static member definitions110// ===========================================================================111template<class R, class E, class V>112RouteCostCalculator<R, E, V>* RouteCostCalculator<R, E, V>::myInstance = 0;113114115#include "GawronCalculator.h"116#include "LogitCalculator.h"117118template<class R, class E, class V>119RouteCostCalculator<R, E, V>& RouteCostCalculator<R, E, V>::getCalculator() {120if (myInstance == 0) {121OptionsCont& oc = OptionsCont::getOptions();122if (oc.getString("route-choice-method") == "logit") {123myInstance = new LogitCalculator<R, E, V>(oc.getFloat("logit.beta"), oc.getFloat("logit.gamma"), oc.getFloat("logit.theta"));124} else if (oc.getString("route-choice-method") == "gawron") {125myInstance = new GawronCalculator<R, E, V>(oc.getFloat("gawron.beta"), oc.getFloat("gawron.a"));126}127}128return *myInstance;129}130131132