MSTrafficLightLogic.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The parent class for traffic light logics
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef MSTrafficLightLogic_h
00020 #define MSTrafficLightLogic_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <map>
00033 #include <string>
00034 #include <bitset>
00035 #include <utils/common/Command.h>
00036 #include <microsim/MSLogicJunction.h>
00037 #include <microsim/MSLink.h>
00038 #include "MSPhaseDefinition.h"
00039 
00040 
00041 // ===========================================================================
00042 // class declarations
00043 // ===========================================================================
00044 class MSNet;
00045 class MSLink;
00046 class MSTLLogicControl;
00047 class NLDetectorBuilder;
00048 
00049 
00050 // ===========================================================================
00051 // class definitions
00052 // ===========================================================================
00057 class MSTrafficLightLogic {
00058 public:
00061 
00063     typedef std::vector<MSPhaseDefinition*> Phases;
00064 
00066     typedef std::vector<MSLink*> LinkVector;
00067 
00069     typedef std::vector<LinkVector> LinkVectorVector;
00070 
00072     typedef std::vector<MSLane*> LaneVector;
00073 
00075     typedef std::vector<LaneVector> LaneVectorVector;
00077 
00078 
00079 public:
00086     MSTrafficLightLogic(MSTLLogicControl &tlcontrol,
00087                         const std::string &id, const std::string &subid, SUMOTime delay) throw();
00088 
00089 
00095     virtual void init(NLDetectorBuilder &nb) throw(ProcessError);
00096 
00097 
00099     virtual ~MSTrafficLightLogic() throw();
00100 
00101 
00102 
00105 
00111     void addLink(MSLink *link, MSLane *lane, unsigned int pos) throw();
00112 
00113 
00121     virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic) throw();
00122 
00123 
00127     std::map<MSLink*, std::pair<MSLink::LinkState, bool> > collectLinkStates() const throw();
00128 
00129 
00133     void resetLinkStates(const std::map<MSLink*, std::pair<MSLink::LinkState, bool> > &vals) const throw();
00135 
00136 
00137 
00140 
00145     virtual SUMOTime trySwitch(bool isActive) throw() = 0;
00146 
00147 
00151     virtual void setLinkPriorities() const throw() = 0;
00152 
00153 
00157     virtual bool setTrafficLightSignals() const throw() = 0;
00159 
00160 
00161 
00164 
00168     const std::string &getID() const throw() {
00169         return myID;
00170     }
00171 
00172 
00176     const std::string &getSubID() const throw() {
00177         return mySubID;
00178     }
00179 
00180 
00184     const LaneVectorVector &getLanes() const throw() {
00185         return myLanes;
00186     }
00187 
00188 
00193     const LaneVector &getLanesAt(unsigned int i) const throw() {
00194         return myLanes[i];
00195     }
00196 
00197 
00201     const LinkVectorVector &getLinks() const throw() {
00202         return myLinks;
00203     }
00204 
00205 
00210     const LinkVector &getLinksAt(unsigned int i) const throw() {
00211         return myLinks[i];
00212     }
00213 
00214 
00219     int getLinkIndex(const MSLink * const link) const throw();
00220 
00221 
00225     virtual unsigned int getPhaseNumber() const throw() = 0;
00226 
00227 
00231     virtual const Phases &getPhases() const throw() = 0;
00232 
00233 
00238     virtual const MSPhaseDefinition &getPhase(unsigned int givenstep) const throw() = 0;
00240 
00241 
00242 
00245 
00249     virtual unsigned int getCurrentPhaseIndex() const throw() = 0;
00250 
00251 
00255     virtual const MSPhaseDefinition &getCurrentPhaseDef() const throw() = 0;
00256 
00257 
00261     unsigned int getDefaultCycleTime() const throw() {
00262         return myDefaultCycleTime;
00263     }
00264 
00265 
00272     SUMOTime getNextSwitchTime() const throw();
00274 
00275 
00276 
00279 
00283     virtual unsigned int getPhaseIndexAtTime(SUMOTime simStep) const throw() = 0;
00284 
00285 
00290     virtual unsigned int getOffsetFromIndex(unsigned int index) const throw() = 0;
00291 
00292 
00297     virtual unsigned int getIndexFromOffset(unsigned int offset) const throw() = 0;
00299 
00300 
00301 
00304 
00308     void addOverridingDuration(SUMOTime duration) throw();
00309 
00310 
00314     void setCurrentDurationIncrement(SUMOTime delay) throw();
00315 
00316 
00323     virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol,
00324                                        SUMOTime simStep, unsigned int step, SUMOTime stepDuration) throw() = 0;
00325 
00327 
00328 
00329 
00332 
00336     void setParameter(const std::map<std::string, std::string> &params) throw();
00337 
00338 
00343     std::string getParameterValue(const std::string &key) const throw();
00345 
00346 
00347 protected:
00352     class SwitchCommand : public Command {
00353     public:
00359         SwitchCommand(MSTLLogicControl &tlcontrol,
00360                       MSTrafficLightLogic *tlLogic,
00361                       SUMOTime nextSwitch) throw();
00362 
00364         ~SwitchCommand() throw();
00365 
00371         SUMOTime execute(SUMOTime currentTime) throw(ProcessError);
00372 
00373 
00377         void deschedule(MSTrafficLightLogic *tlLogic) throw();
00378 
00379 
00383         SUMOTime getNextSwitchTime() const throw() {
00384             return myAssumedNextSwitch;
00385         }
00386 
00387 
00388     private:
00390         MSTLLogicControl &myTLControl;
00391 
00393         MSTrafficLightLogic *myTLLogic;
00394 
00396         SUMOTime myAssumedNextSwitch;
00397 
00399         bool myAmValid;
00400 
00401     private:
00403         SwitchCommand(const SwitchCommand&);
00404 
00406         SwitchCommand& operator=(const SwitchCommand&);
00407 
00408     };
00409 
00410 protected:
00412     std::map<std::string, std::string> myParameter;
00413 
00415     std::string myID, mySubID;
00416 
00418     LinkVectorVector myLinks;
00419 
00421     LaneVectorVector myLanes;
00422 
00424     std::vector<SUMOTime> myOverridingTimes;
00425 
00427     SUMOTime myCurrentDurationIncrement;
00428 
00430     SwitchCommand *mySwitchCommand;
00431 
00433     unsigned int myDefaultCycleTime;
00434 
00435 
00436 private:
00438     MSTrafficLightLogic(const MSTrafficLightLogic &s);
00439 
00441     MSTrafficLightLogic& operator=(const MSTrafficLightLogic &s);
00442 
00443 };
00444 
00445 
00446 #endif
00447 
00448 /****************************************************************************/
00449 

Generated on Wed May 5 00:06:32 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6