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