LCOV - code coverage report
Current view: top level - src/utils/router - RouteCostCalculator.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 23 23
Test Date: 2024-10-24 15:46:30 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-2024 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              : /****************************************************************************/
      14              : /// @file    RouteCostCalculator.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    Sept 2002
      19              : ///
      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>
      30              : #include <utils/common/RandHelper.h>
      31              : #include <utils/options/OptionsCont.h>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class definitions
      36              : // ===========================================================================
      37              : /**
      38              :  * @class RouteCostCalculator
      39              :  * @brief Abstract base class providing static factory method.
      40              :  */
      41              : template<class R, class E, class V>
      42              : class RouteCostCalculator {
      43              : public:
      44              :     static RouteCostCalculator<R, E, V>& getCalculator();
      45              : 
      46              :     static void cleanup() {
      47         6138 :         delete myInstance;
      48         6138 :         myInstance = 0;
      49              :     }
      50              : 
      51              :     virtual void setCosts(R* route, const double costs, const bool isActive = false) const = 0;
      52              : 
      53              :     /** @brief calculate the probabilities in the logit model */
      54              :     virtual void calculateProbabilities(std::vector<R*> alternatives, const V* const veh, const SUMOTime time) = 0;
      55              : 
      56              :     int getMaxRouteNumber() const {
      57        96866 :         return myMaxRouteNumber;
      58              :     }
      59              : 
      60              :     bool keepAllRoutes() const {
      61        96866 :         return myKeepRoutes;
      62              :     }
      63              : 
      64              :     bool skipRouteCalculation() const {
      65       108199 :         return mySkipNewRoutes;
      66              :     }
      67              : 
      68              :     bool keepRoute() const {
      69        96866 :         if (myKeepRouteProb == 1) {
      70              :             return true;
      71        96848 :         } else if (myKeepRouteProb == 0) {
      72              :             return false;
      73              :         } else {
      74        10060 :             return RandHelper::rand() < myKeepRouteProb;
      75              :         }
      76              :     }
      77              : 
      78              : protected:
      79              :     /// @brief Constructor
      80         3602 :     RouteCostCalculator() {
      81         3602 :         OptionsCont& oc = OptionsCont::getOptions();
      82         3602 :         myMaxRouteNumber = oc.getInt("max-alternatives");
      83         3602 :         myKeepRoutes = oc.getBool("keep-all-routes");
      84         3602 :         mySkipNewRoutes = oc.getBool("skip-new-routes");
      85         7200 :         myKeepRouteProb = oc.exists("keep-route-probability") ? oc.getFloat("keep-route-probability") : 0;
      86         3602 :     }
      87              : 
      88              :     /// @brief Destructor
      89              :     virtual ~RouteCostCalculator() {}
      90              : 
      91              : private:
      92              :     static RouteCostCalculator* myInstance;
      93              : 
      94              :     /// @brief The maximum route alternatives number
      95              :     int myMaxRouteNumber;
      96              : 
      97              :     /// @brief Information whether all routes should be saved
      98              :     bool myKeepRoutes;
      99              : 
     100              :     /// @brief Information whether new routes shall be computed
     101              :     bool mySkipNewRoutes;
     102              : 
     103              :     /// @brief Information whether the old route shall be kept
     104              :     double myKeepRouteProb;
     105              : 
     106              : };
     107              : 
     108              : 
     109              : // ===========================================================================
     110              : // static member definitions
     111              : // ===========================================================================
     112              : template<class R, class E, class V>
     113              : RouteCostCalculator<R, E, V>* RouteCostCalculator<R, E, V>::myInstance = 0;
     114              : 
     115              : 
     116              : #include "GawronCalculator.h"
     117              : #include "LogitCalculator.h"
     118              : 
     119              : template<class R, class E, class V>
     120       749330 : RouteCostCalculator<R, E, V>& RouteCostCalculator<R, E, V>::getCalculator() {
     121       749330 :     if (myInstance == 0) {
     122         3602 :         OptionsCont& oc = OptionsCont::getOptions();
     123         7204 :         if (oc.getString("route-choice-method") == "logit") {
     124           98 :             myInstance = new LogitCalculator<R, E, V>(oc.getFloat("logit.beta"), oc.getFloat("logit.gamma"), oc.getFloat("logit.theta"));
     125         7106 :         } else if (oc.getString("route-choice-method") == "gawron") {
     126         7106 :             myInstance = new GawronCalculator<R, E, V>(oc.getFloat("gawron.beta"), oc.getFloat("gawron.a"));
     127              :         }
     128              :     }
     129       749330 :     return *myInstance;
     130              : }
        

Generated by: LCOV version 2.0-1