SUMO - Simulation of Urban MObility
NIVisumTL.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Intermediate class for storing visum traffic lights during their import
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This file is part of SUMO.
00014 //   SUMO is free software: you can redistribute it and/or modify
00015 //   it under the terms of the GNU General Public License as published by
00016 //   the Free Software Foundation, either version 3 of the License, or
00017 //   (at your option) any later version.
00018 //
00019 /****************************************************************************/
00020 
00021 
00022 // ===========================================================================
00023 // included modules
00024 // ===========================================================================
00025 #ifdef _MSC_VER
00026 #include <windows_config.h>
00027 #else
00028 #include <config.h>
00029 #endif
00030 
00031 #include <string>
00032 #include <netbuild/NBLoadedTLDef.h>
00033 #include <netbuild/NBTrafficLightLogicCont.h>
00034 #include "NIVisumTL.h"
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 // ===========================================================================
00041 // used namespaces
00042 // ===========================================================================
00043 using namespace std;
00044 
00045 
00046 // ===========================================================================
00047 // method definitions
00048 // ===========================================================================
00049 NIVisumTL::NIVisumTL(const std::string& name, SUMOTime cycleTime,
00050                      SUMOTime intermediateTime, bool phaseDefined)
00051     : myName(name), myCycleTime(cycleTime), myIntermediateTime(intermediateTime),
00052       myPhaseDefined(phaseDefined) 
00053 {}
00054 
00055 
00056 NIVisumTL::~NIVisumTL() {
00057     for (std::map<std::string, Phase*>::iterator i = myPhases.begin(); i != myPhases.end(); ++i) {
00058         delete i->second;
00059     }
00060     for (std::map<std::string, SignalGroup*>::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
00061         delete i->second;
00062     }
00063 }
00064 
00065 
00066 void 
00067 NIVisumTL::addSignalGroup(const std::string &name, SUMOTime startTime, SUMOTime endTime) {
00068     mySignalGroups[name] = new NIVisumTL::SignalGroup(name, startTime, endTime);
00069 }
00070 
00071 
00072 void 
00073 NIVisumTL::addPhase(const std::string &name, SUMOTime startTime, SUMOTime endTime) {
00074     myPhases[name] = new NIVisumTL::Phase(startTime, endTime);
00075 }
00076 
00077 
00078 NIVisumTL::SignalGroup& 
00079 NIVisumTL::getSignalGroup(const std::string &name) {
00080     return *mySignalGroups.find(name)->second;
00081 }
00082 
00083 
00084 void
00085 NIVisumTL::build(NBTrafficLightLogicCont& tlc) {
00086     for (std::vector<NBNode*>::iterator ni = myNodes.begin(); ni != myNodes.end(); ni++) {
00087         NBNode* node = (*ni);
00088         NBLoadedTLDef* def = new NBLoadedTLDef(node->getID(), node);
00089         tlc.insert(def);
00090         def->setCycleDuration((unsigned int) myCycleTime);
00091         // signalgroups
00092         for (std::map<std::string, SignalGroup*>::iterator gi = mySignalGroups.begin(); gi != mySignalGroups.end(); gi++) {
00093             std::string groupName = (*gi).first;
00094             NIVisumTL::SignalGroup& SG = *(*gi).second;
00095             def->addSignalGroup(groupName);
00096             def->addToSignalGroup(groupName, SG.connections());
00097             def->setSignalYellowTimes(groupName, myIntermediateTime, myIntermediateTime);
00098             // phases
00099             if (myPhaseDefined) {
00100                 for (std::map<std::string, Phase*>::iterator pi = SG.phases().begin(); pi != SG.phases().end(); pi++) {
00101                     NIVisumTL::Phase& PH = *(*pi).second;
00102                     def->addSignalGroupPhaseBegin(groupName, PH.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
00103                     def->addSignalGroupPhaseBegin(groupName, PH.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
00104                 };
00105             } else {
00106                 def->addSignalGroupPhaseBegin(groupName, SG.getStartTime(), NBTrafficLightDefinition::TLCOLOR_GREEN);
00107                 def->addSignalGroupPhaseBegin(groupName, SG.getEndTime(), NBTrafficLightDefinition::TLCOLOR_RED);
00108             }
00109         }
00110     }
00111 }
00112 
00113 
00114 
00115 /****************************************************************************/
00116 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines