Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netimport/NIVisumTL.cpp
169666 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2003-2025 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
NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
37
SUMOTime intermediateTime, bool phaseDefined)
38
: myName(name), myCycleTime(cycleTime), myOffset(offset),
39
myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined) {
40
}
41
42
43
NIVisumTL::~NIVisumTL() {
44
for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
45
delete i->second;
46
}
47
for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
48
delete i->second;
49
}
50
}
51
52
53
void
54
NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
55
mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
56
}
57
58
59
void
60
NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
61
myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
62
}
63
64
65
NIVisumTL::SignalGroup&
66
NIVisumTL::getSignalGroup(const std::string& name) {
67
return *mySignalGroups.find(name)->second;
68
}
69
70
71
void
72
NIVisumTL::build(NBEdgeCont& ec, NBTrafficLightLogicCont& tlc) {
73
for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
74
NBNode* node = (*ni);
75
if (node == nullptr) {
76
WRITE_WARNINGF(TL("invalid node for traffic light '%'"), myName);
77
continue;
78
}
79
TrafficLightType type = SUMOXMLDefinitions::TrafficLightTypes.get(OptionsCont::getOptions().getString("tls.default-type"));
80
NBLoadedTLDef* def = new NBLoadedTLDef(ec, node->getID(), node, myOffset, type);
81
tlc.insert(def);
82
def->setCycleDuration(myCycleTime);
83
// signalgroups
84
for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
85
std::string groupName = (*gi).first;
86
NIVisumTL::SignalGroup& SG = *(*gi).second;
87
def->addSignalGroup(groupName);
88
def->addToSignalGroup(groupName, SG.connections());
89
// phases
90
SUMOTime yellowTime = -1;
91
if (myPhaseDefined) {
92
for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
93
NIVisumTL::Phase& PH = *(*pi).second;
94
def->addSignalGroupPhaseBegin(groupName, PH.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
95
def->addSignalGroupPhaseBegin(groupName, PH.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
96
yellowTime = MAX2(PH.getYellowTime(), yellowTime);
97
}
98
} else {
99
def->addSignalGroupPhaseBegin(groupName, SG.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
100
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
def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
105
}
106
}
107
}
108
109
110
/****************************************************************************/
111
112