LCOV - code coverage report
Current view: top level - src/netimport - NIVisumTL.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 76.2 % 42 32
Test Date: 2024-11-20 15:55:46 Functions: 83.3 % 6 5

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2003-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.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thr, 08 May 2003
      19              : ///
      20              : // Intermediate class for storing visum traffic lights during their import
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include <utils/options/OptionsCont.h>
      26              : #include <utils/common/MsgHandler.h>
      27              : #include <netbuild/NBLoadedTLDef.h>
      28              : #include <netbuild/NBTrafficLightLogicCont.h>
      29              : #include <netbuild/NBEdgeCont.h>
      30              : #include "NIVisumTL.h"
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // method definitions
      35              : // ===========================================================================
      36           17 : NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
      37           17 :                      SUMOTime intermediateTime, bool phaseDefined)
      38           17 :     : myName(name), myCycleTime(cycleTime), myOffset(offset),
      39           17 :       myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
      40           17 : }
      41              : 
      42              : 
      43           17 : NIVisumTL::~NIVisumTL() {
      44           17 :     for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
      45            0 :         delete i->second;
      46              :     }
      47           89 :     for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
      48           72 :         delete i->second;
      49              :     }
      50           17 : }
      51              : 
      52              : 
      53              : void
      54           72 : NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
      55           72 :     mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
      56           72 : }
      57              : 
      58              : 
      59              : void
      60            0 : NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
      61            0 :     myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
      62            0 : }
      63              : 
      64              : 
      65              : NIVisumTL::SignalGroup&
      66          184 : NIVisumTL::getSignalGroup(const std::string& name) {
      67          184 :     return *mySignalGroups.find(name)->second;
      68              : }
      69              : 
      70              : 
      71              : void
      72           17 : NIVisumTL::build(NBEdgeCont& ec, NBTrafficLightLogicCont& tlc) {
      73           34 :     for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
      74           17 :         NBNode* node = (*ni);
      75           17 :         if (node == nullptr) {
      76            0 :             WRITE_WARNINGF(TL("invalid node for traffic light '%'"), myName);
      77            0 :             continue;
      78              :         }
      79           17 :         TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
      80           17 :         NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
      81           17 :         tlc.insert(def);
      82           17 :         def->setCycleDuration(myCycleTime);
      83              :         // signalgroups
      84           89 :         for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
      85              :             std::string groupName = (*gi).first;
      86           72 :             NIVisumTL::SignalGroup& SG = *(*gi).second;
      87           72 :             def->addSignalGroup(groupName);
      88           72 :             def->addToSignalGroup(groupName, SG.connections());
      89              :             // phases
      90              :             SUMOTime yellowTime = -1;
      91           72 :             if (myPhaseDefined) {
      92            0 :                 for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
      93            0 :                     NIVisumTL::Phase& PH = *(*pi).second;
      94            0 :                     def->addSignalGroupPhaseBegin(groupName, PH.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
      95            0 :                     def->addSignalGroupPhaseBegin(groupName, PH.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
      96              :                     yellowTime = MAX2(PH.getYellowTime(), yellowTime);
      97              :                 }
      98              :             } else {
      99           72 :                 def->addSignalGroupPhaseBegin(groupName, SG.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
     100           72 :                 def->addSignalGroupPhaseBegin(groupName, SG.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
     101              :                 yellowTime = MAX2(SG.getYellowTime(), yellowTime);
     102              :             }
     103              :             // yellowTime can be -1 if not given in the input; it will be "patched" later
     104           72 :             def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
     105              :         }
     106              :     }
     107           17 : }
     108              : 
     109              : 
     110              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1