SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NIVisumTL.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Intermediate class for storing visum traffic lights during their import
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2003-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
35 #include <netbuild/NBLoadedTLDef.h>
37 #include "NIVisumTL.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
48  SUMOTime intermediateTime, bool phaseDefined)
49  : myName(name), myCycleTime(cycleTime), myOffset(offset),
50  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined)
51 {}
52 
53 
55  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
56  delete i->second;
57  }
58  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
59  delete i->second;
60  }
61 }
62 
63 
64 void
65 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
66  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
67 }
68 
69 
70 void
71 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
72  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
73 }
74 
75 
77 NIVisumTL::getSignalGroup(const std::string& name) {
78  return *mySignalGroups.find(name)->second;
79 }
80 
81 
82 void
84  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
85  NBNode* node = (*ni);
87  NBLoadedTLDef* def = new NBLoadedTLDef(node->getID(), node, myOffset, type);
88  tlc.insert(def);
89  def->setCycleDuration((unsigned int) myCycleTime);
90  // signalgroups
91  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
92  std::string groupName = (*gi).first;
93  NIVisumTL::SignalGroup& SG = *(*gi).second;
94  def->addSignalGroup(groupName);
95  def->addToSignalGroup(groupName, SG.connections());
96  // phases
97  SUMOTime yellowTime = -1;
98  if (myPhaseDefined) {
99  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
100  NIVisumTL::Phase& PH = *(*pi).second;
103  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
104  };
105  } else {
108  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
109  }
110  // yellowTime can be -1 if not given in the input; it will be "patched" later
111  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
112  }
113  }
114 }
115 
116 
117 
118 /****************************************************************************/
119