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-2012 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>
32 #include <netbuild/NBLoadedTLDef.h>
34 #include "NIVisumTL.h"
35 
36 #ifdef CHECK_MEMORY_LEAKS
37 #include <foreign/nvwa/debug_new.h>
38 #endif // CHECK_MEMORY_LEAKS
39 
40 // ===========================================================================
41 // used namespaces
42 // ===========================================================================
43 using namespace std;
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime, SUMOTime offset,
50  SUMOTime intermediateTime, bool phaseDefined)
51  : myName(name), myCycleTime(cycleTime), myOffset(offset),
52  myIntermediateTime(intermediateTime), myPhaseDefined(phaseDefined)
53 {}
54 
55 
57  for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
58  delete i->second;
59  }
60  for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
61  delete i->second;
62  }
63 }
64 
65 
66 void
67 NIVisumTL::addSignalGroup(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
68  mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime, yellowTime);
69 }
70 
71 
72 void
73 NIVisumTL::addPhase(const std::string& name, SUMOTime startTime, SUMOTime endTime, SUMOTime yellowTime) {
74  myPhases[name] = new NIVisumTL::Phase(startTime, endTime, yellowTime);
75 }
76 
77 
79 NIVisumTL::getSignalGroup(const std::string& name) {
80  return *mySignalGroups.find(name)->second;
81 }
82 
83 
84 void
86  for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
87  NBNode* node = (*ni);
88  NBLoadedTLDef* def = new NBLoadedTLDef(node->getID(), node, myOffset);
89  tlc.insert(def);
90  def->setCycleDuration((unsigned int) myCycleTime);
91  // signalgroups
92  for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
93  std::string groupName = (*gi).first;
94  NIVisumTL::SignalGroup& SG = *(*gi).second;
95  def->addSignalGroup(groupName);
96  def->addToSignalGroup(groupName, SG.connections());
97  // phases
98  SUMOTime yellowTime = -1;
99  if (myPhaseDefined) {
100  for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
101  NIVisumTL::Phase& PH = *(*pi).second;
104  yellowTime = MAX2(PH.getYellowTime(), yellowTime);
105  };
106  } else {
109  yellowTime = MAX2(SG.getYellowTime(), yellowTime);
110  }
111  // yellowTime can be -1 if not given in the input; it will be "patched" later
112  def->setSignalYellowTimes(groupName, myIntermediateTime, yellowTime);
113  }
114  }
115 }
116 
117 
118 
119 /****************************************************************************/
120