Eclipse SUMO - Simulation of Urban MObility
RouteCostCalculator.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2020 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 <cmath>
28 #include <utils/common/StdDefs.h>
29 #include <utils/common/SUMOTime.h>
31 
32 
33 // ===========================================================================
34 // class definitions
35 // ===========================================================================
40 template<class R, class E, class V>
42 public:
44 
45  static void cleanup() {
46  delete myInstance;
47  myInstance = 0;
48  }
49 
50  virtual void setCosts(R* route, const double costs, const bool isActive = false) const = 0;
51 
53  virtual void calculateProbabilities(std::vector<R*> alternatives, const V* const veh, const SUMOTime time) = 0;
54 
55  int getMaxRouteNumber() const {
56  return myMaxRouteNumber;
57  }
58 
59  bool keepRoutes() const {
60  return myKeepRoutes;
61  }
62 
63  bool skipRouteCalculation() const {
65  }
66 
67 protected:
71  myMaxRouteNumber = oc.getInt("max-alternatives");
72  myKeepRoutes = oc.getBool("keep-all-routes");
73  mySkipRouteCalculation = oc.getBool("skip-new-routes");
74  }
75 
77  virtual ~RouteCostCalculator() {}
78 
79 private:
81 
84 
87 
90 
91 };
92 
93 
94 // ===========================================================================
95 // static member definitions
96 // ===========================================================================
97 template<class R, class E, class V>
99 
100 
101 #include "GawronCalculator.h"
102 #include "LogitCalculator.h"
103 
104 template<class R, class E, class V>
106  if (myInstance == 0) {
108  if (oc.getString("route-choice-method") == "logit") {
109  myInstance = new LogitCalculator<R, E, V>(oc.getFloat("logit.beta"), oc.getFloat("logit.gamma"), oc.getFloat("logit.theta"));
110  } else if (oc.getString("route-choice-method") == "gawron") {
111  myInstance = new GawronCalculator<R, E, V>(oc.getFloat("gawron.beta"), oc.getFloat("gawron.a"));
112  }
113  }
114  return *myInstance;
115 }
long long int SUMOTime
Definition: SUMOTime.h:31
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 getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Abstract base class providing static factory method.
bool myKeepRoutes
Information whether all routes should be saved.
virtual void calculateProbabilities(std::vector< R * > alternatives, const V *const veh, const SUMOTime time)=0
calculate the probabilities in the logit model
virtual ~RouteCostCalculator()
Destructor.
int myMaxRouteNumber
The maximum route alternatives number.
virtual void setCosts(R *route, const double costs, const bool isActive=false) const =0
bool mySkipRouteCalculation
Information whether new routes should be calculated.
static RouteCostCalculator< R, E, V > & getCalculator()
bool skipRouteCalculation() const
static RouteCostCalculator * myInstance
RouteCostCalculator()
Constructor.