Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RouteCostCalculator.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#include <memory>
28#include <cmath>
33
34
35// ===========================================================================
36// class definitions
37// ===========================================================================
42template<class R, class E, class V>
44public:
46
47 static void cleanup() {
48 delete myInstance;
49 myInstance = 0;
50 }
51
52 virtual void setCosts(std::shared_ptr<R> route, const double costs, const bool isActive = false) const = 0;
53
55 virtual void calculateProbabilities(const std::vector<std::shared_ptr<R> >& alternatives, const V* const veh, const SUMOTime time) = 0;
56
57 int getMaxRouteNumber() const {
58 return myMaxRouteNumber;
59 }
60
61 bool keepAllRoutes() const {
62 return myKeepRoutes;
63 }
64
65 bool skipRouteCalculation() const {
66 return mySkipNewRoutes;
67 }
68
69 bool keepRoute() const {
70 if (myKeepRouteProb == 1) {
71 return true;
72 } else if (myKeepRouteProb == 0) {
73 return false;
74 } else {
76 }
77 }
78
79protected:
83 myMaxRouteNumber = oc.getInt("max-alternatives");
84 myKeepRoutes = oc.getBool("keep-all-routes");
85 mySkipNewRoutes = oc.getBool("skip-new-routes");
86 myKeepRouteProb = oc.exists("keep-route-probability") ? oc.getFloat("keep-route-probability") : 0;
87 }
88
91
92private:
94
97
100
103
106
107};
108
109
110// ===========================================================================
111// static member definitions
112// ===========================================================================
113template<class R, class E, class V>
115
116
117#include "GawronCalculator.h"
118#include "LogitCalculator.h"
119
120template<class R, class E, class V>
122 if (myInstance == 0) {
124 if (oc.getString("route-choice-method") == "logit") {
125 myInstance = new LogitCalculator<R, E, V>(oc.getFloat("logit.beta"), oc.getFloat("logit.gamma"), oc.getFloat("logit.theta"));
126 } else if (oc.getString("route-choice-method") == "gawron") {
127 myInstance = new GawronCalculator<R, E, V>(oc.getFloat("gawron.beta"), oc.getFloat("gawron.a"));
128 }
129 }
130 return *myInstance;
131}
long long int SUMOTime
Definition GUI.h:36
Cost calculation with Gawron's method.
Cost calculation with c-logit or logit method.
A storage for options typed value containers)
Definition OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Abstract base class providing static factory method.
bool mySkipNewRoutes
Information whether new routes shall be computed.
bool myKeepRoutes
Information whether all routes should be saved.
virtual ~RouteCostCalculator()
Destructor.
int myMaxRouteNumber
The maximum route alternatives number.
virtual void calculateProbabilities(const std::vector< std::shared_ptr< R > > &alternatives, const V *const veh, const SUMOTime time)=0
calculate the probabilities in the logit model
static RouteCostCalculator< R, E, V > & getCalculator()
virtual void setCosts(std::shared_ptr< R > route, const double costs, const bool isActive=false) const =0
bool skipRouteCalculation() const
static RouteCostCalculator * myInstance
RouteCostCalculator()
Constructor.
double myKeepRouteProb
Information whether the old route shall be kept.