LCOV - code coverage report
Current view: top level - src/netimport - NIVisumTL.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 75.0 % 12 9
Test Date: 2024-11-20 15:55:46 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) 2001-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    NIVisumTL.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @date    Wed, 07 May 2003
      17              : ///
      18              : // Intermediate class for storing visum traffic lights during their import
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <vector>
      24              : #include <map>
      25              : #include <string>
      26              : #include <netbuild/NBConnectionDefs.h>
      27              : #include <netbuild/NBNodeCont.h>
      28              : #include <utils/common/SUMOTime.h>
      29              : 
      30              : class NBTrafficLightLogicCont;
      31              : class NBEdgeCont;
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class declaration
      36              : // ===========================================================================
      37              : /**
      38              :  * @class NIVisumTL
      39              :  * @brief Intermediate class for storing visum traffic lights during their import
      40              :  */
      41              : class NIVisumTL {
      42              : public:
      43              :     /** @class TimePeriod
      44              :      * @brief A time period with a start and an end time
      45              :      */
      46              :     class TimePeriod {
      47              :     public:
      48              :         /// @brief Constructor
      49              :         TimePeriod(SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
      50            0 :             : myStartTime(startTime), myEndTime(endTime), myYellowTime(yellowTime) {}
      51              : 
      52              :         /// @brief Destructor
      53              :         ~TimePeriod() {}
      54              : 
      55              :         /// @brief Returns the stored start time
      56              :         SUMOTime getStartTime() {
      57           72 :             return myStartTime;
      58              :         }
      59              : 
      60              :         /// @brief Returns the stored end time
      61              :         SUMOTime getEndTime() {
      62           72 :             return myEndTime;
      63              :         }
      64              : 
      65              :         /// @brief Returns the stored yellow time
      66              :         SUMOTime getYellowTime() {
      67           72 :             return myYellowTime;
      68              :         }
      69              : 
      70              :     private:
      71              :         /// @brief Start time
      72              :         const SUMOTime myStartTime;
      73              :         /// @brief End time
      74              :         const SUMOTime myEndTime;
      75              :         /// @brief Yellow time
      76              :         const SUMOTime myYellowTime;
      77              : 
      78              :     private:
      79              :         /// @brief Invalidated assignment operator
      80              :         TimePeriod& operator=(const TimePeriod& s) = delete;
      81              :     };
      82              : 
      83              : 
      84              : 
      85              :     /** @class Phase
      86              :      * @brief A phase
      87              :      */
      88              :     class Phase : public TimePeriod {
      89              :     public:
      90              :         /// @brief Constructor
      91              :         Phase(SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) : NIVisumTL::TimePeriod(startTime, endTime, yellowTime) {}
      92              : 
      93              :         /// @brief Destructor
      94            0 :         ~Phase() {}
      95              : 
      96              :     };
      97              : 
      98              : 
      99              : 
     100              :     /** @class SignalGroup
     101              :      * @brief A signal group can be defined either by a time period or by phases
     102              :      */
     103              :     class SignalGroup : public TimePeriod {
     104              :     public:
     105              :         /// @brief constructor
     106           72 :         SignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime)
     107          144 :             : NIVisumTL::TimePeriod(startTime, endTime, yellowTime), myName(name) {}
     108              : 
     109              :         /// @brief destructor
     110          144 :         ~SignalGroup() {}
     111              : 
     112              :         /// @brief Returns the connections vector
     113              :         NBConnectionVector& connections() {
     114          256 :             return myConnections;
     115              :         }
     116              : 
     117              :         /// @brief Returns the phases map
     118              :         std::map<std::string, Phase*>& phases() {
     119            0 :             return myPhases;
     120              :         }
     121              : 
     122              :     private:
     123              :         /// @brief Connections
     124              :         NBConnectionVector myConnections;
     125              :         /// @brief phases
     126              :         std::map<std::string, Phase*> myPhases;
     127              :         /// @brief name
     128              :         std::string myName;
     129              :     };
     130              : 
     131              : 
     132              : 
     133              : public:
     134              :     /** @brief Constructor
     135              :      * @param[in] name The name of the TLS
     136              :      * @param[in] cycleTime The cycle time of the TLS
     137              :      * @param[in] offset Seconds to skip
     138              :      * @param[in] intermediateTime The name of the TLS
     139              :      * @param[in] phaseDefined Whether phases are defined
     140              :      */
     141              :     NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset, SUMOTime intermediateTime,
     142              :               bool phaseDefined);
     143              : 
     144              :     /// @brief Destructor
     145              :     ~NIVisumTL();
     146              : 
     147              :     /// @brief Adds a node to control
     148              :     void addNode(NBNode* n) {
     149           17 :         myNodes.push_back(n);
     150           17 :     }
     151              : 
     152              :     /// @brief Adds a signal group
     153              :     void addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime);
     154              : 
     155              :     /// @brief Adds a phase
     156              :     void addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime);
     157              : 
     158              :     /// @brief Returns the map of named phases
     159              :     std::map<std::string, Phase*>& getPhases() {
     160              :         return myPhases;
     161              :     }
     162              : 
     163              :     /// @brief Returns the named signal group
     164              :     SignalGroup& getSignalGroup(const std::string& name);
     165              : 
     166              :     /// @brief build the traffic light and add it to the given container
     167              :     void build(NBEdgeCont& ec, NBTrafficLightLogicCont& tlc);
     168              : 
     169              : private:
     170              :     /// @brief The name of traffic light
     171              :     std::string myName;
     172              : 
     173              :     /// @brief The cycle time of traffic light in seconds
     174              :     SUMOTime myCycleTime;
     175              : 
     176              :     /// @brief The offset in the plan
     177              :     SUMOTime myOffset;
     178              : 
     179              :     /// @brief The all-red time (unused here)
     180              :     SUMOTime myIntermediateTime;
     181              : 
     182              :     /// @brief Toggles the usage either of phases or of time periods in signal groups
     183              :     bool myPhaseDefined;
     184              : 
     185              :     /// @brief Vector of nodes belonging to this traffic light
     186              :     std::vector<NBNode*> myNodes;
     187              : 
     188              :     /// @brief Map of used phases if phases defined
     189              :     std::map<std::string, Phase*> myPhases;
     190              : 
     191              :     /// @brief Map of used signal groups
     192              :     std::map<std::string, SignalGroup*> mySignalGroups;
     193              : 
     194              : 
     195              : };
        

Generated by: LCOV version 2.0-1