 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
55 : myTLControl(tlcontrol), myTLLogic(tlLogic),
56 myAssumedNextSwitch(nextSwitch), myAmValid(true) {}
70 const bool isActive = myTLControl.isActive(myTLLogic);
71 int step1 = myTLLogic->getCurrentPhaseIndex();
72 SUMOTime next = myTLLogic->trySwitch();
73 int step2 = myTLLogic->getCurrentPhaseIndex();
79 myTLLogic->setTrafficLightSignals(t);
84 myAssumedNextSwitch += next;
91 if (tlLogic == myTLLogic) {
93 myAssumedNextSwitch = -1;
103 const std::map<std::string, std::string>& parameters) :
120 if (phases.size() > 1) {
121 bool haveWarnedAboutUnusedStates =
false;
122 std::vector<bool> foundGreen(phases.front()->getState().size(),
false);
123 for (
int i = 0; i < (int)phases.size(); ++i) {
125 std::vector<int> nextPhases;
126 nextPhases.push_back((i + 1) % phases.size());
127 bool iNextDefault =
true;
128 if (phases[i]->nextPhases.size() > 0) {
129 nextPhases = phases[i]->nextPhases;
130 iNextDefault =
false;
132 for (
int iNext : nextPhases) {
133 if (iNext < 0 || iNext >= (
int)phases.size()) {
137 const std::string optionalFrom = iNextDefault ?
"" :
" from phase " +
toString(i);
138 const std::string& state1 = phases[i]->getState();
139 const std::string& state2 = phases[iNext]->getState();
140 assert(state1.size() == state2.size());
145 haveWarnedAboutUnusedStates =
true;
149 if (std::string::npos != illegal) {
154 for (
int j = 0; j < (int)
MIN3(state1.size(), state2.size(),
myLanes.size()); ++j) {
158 for (LaneVector::const_iterator it =
myLanes[j].begin(); it !=
myLanes[j].end(); ++it) {
162 +
" when switching" + optionalFrom +
" to phase " +
toString(iNext));
169 for (
int j = 0; j < (int)state1.size(); ++j) {
172 foundGreen[j] =
true;
177 for (
int j = 0; j < (int)foundGreen.size(); ++j) {
178 if (!foundGreen[j]) {
199 while ((
int)
myLinks.size() <= pos) {
205 while ((
int)
myLanes.size() <= pos) {
221 std::map<MSLink*, LinkState>
223 std::map<MSLink*, LinkState> ret;
224 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1) {
226 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
227 ret[*i2] = (*i2)->getState();
239 for (
int i = 0; i < (int)
myLinks.size(); i++) {
242 for (LinkVector::const_iterator j = currGroup.begin(); j != currGroup.end(); j++) {
243 (*j)->setTLState(ls, t);
252 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1) {
254 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
255 assert(vals.find(*i2) != vals.end());
266 for (LinkVectorVector::const_iterator i1 =
myLinks.begin(); i1 !=
myLinks.end(); ++i1, ++index) {
268 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
289 if (nextSwitch == -1) {
314 const int numLinks = (int)
myLinks.size();
316 assert(numLinks <= (
int)phases.front()->getState().size());
318 std::vector<double> redDuration(numLinks, 0);
319 std::vector<double> totalRedDuration(numLinks, 0);
320 std::vector<double> penalty(numLinks, 0);
321 for (
int i = 0; i < (int)phases.size(); ++i) {
322 const std::string& state = phases[i]->getState();
323 duration += phases[i]->duration;
325 for (
int j = 0; j < numLinks; ++j) {
328 redDuration[j] +=
STEPS2TIME(phases[i]->duration);
329 totalRedDuration[j] +=
STEPS2TIME(phases[i]->duration);
330 }
else if (redDuration[j] > 0) {
331 penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
337 for (
int j = 0; j < numLinks; ++j) {
338 if (redDuration[j] > 0) {
339 penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
343 const double durationSeconds =
STEPS2TIME(duration);
344 std::set<const MSJunction*> controlledJunctions;
345 for (
int j = 0; j < numLinks; ++j) {
346 for (
int k = 0; k < (int)
myLinks[j].size(); ++k) {
349 controlledJunctions.insert(
myLinks[j][k]->getLane()->getEdge().getFromJunction());
355 for (std::set<const MSJunction*>::iterator it = controlledJunctions.begin(); it != controlledJunctions.end(); ++it) {
357 for (ConstMSEdgeVector::const_iterator it_e = incoming.begin(); it_e != incoming.end(); ++it_e) {
358 const_cast<MSEdge*>(*it_e)->recalcCache();
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
std::vector< SUMOTime > myOverridingTimes
A list of duration overrides.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define WRITE_WARNING(msg)
An upper class for objects with additional parameters.
Representation of a lane in the micro simulation.
Base class for objects which have an id.
const std::string & getProgramID() const
Returns this tl-logic's id.
void ignoreLinkIndex(int pos)
ignore pedestrian crossing index in mesosim
Class realising the switch between the traffic light phases.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
SUMOTime getSpentDuration() const
Returns the duration spent in the current phase.
std::vector< const MSEdge * > ConstMSEdgeVector
void addOverridingDuration(SUMOTime duration)
Changes the duration of the next phase.
The link has green light, has to brake.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
The link has green light, may pass.
virtual void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
SwitchCommand * mySwitchCommand
The current switch command.
SwitchCommand(MSTLLogicControl &tlcontrol, MSTrafficLightLogic *tlLogic, SUMOTime nextSwitch)
Constructor.
~SwitchCommand()
Destructor.
SUMOTime myCurrentDurationIncrement
A value for enlarge the current duration.
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
SUMOTime duration
The duration of the phase.
static double gMesoTLSPenalty
MSTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const SUMOTime delay, const std::map< std::string, std::string > ¶meters)
Constructor.
The link has red light (must brake) but indicates upcoming green.
void setCurrentDurationIncrement(SUMOTime delay)
Delays current phase by the given delay.
const std::string & getState() const
Returns the state within this phase.
SUMOTime execute(SUMOTime currentTime)
Executes the regarded junction's "trySwitch"- method.
void setTLState(LinkState state, SUMOTime t)
Sets the current tl-state.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
int getLinkIndex(const MSLink *const link) const
Returns the index of the given link.
The parent class for traffic light logics.
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
std::map< MSLink *, LinkState > collectLinkStates() const
Returns the (uncontrolled) states of the controlled links.
const std::string myProgramID
The id of the logic.
const TrafficLightType myLogicType
The type of the logic.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual bool isSelected(const MSTrafficLightLogic *) const
return wheter the given logic (or rather it's wrapper) is selected in the GUI
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
std::set< int > myIgnoredIndices
list of indices that are ignored in mesoscopic simulatino
void initMesoTLSPenalties()
initialize optional meso penalties
static const LaneVector myEmptyLaneVector
An empty lane vector.
Storage for all programs of a single tls.
SUMOTime myDefaultCycleTime
The cycle time (without changes)
virtual ~MSTrafficLightLogic()
Destructor.
bool isSelected() const
whether this logic is selected in the GUI
A class that stores and controls tls and switching of their programs.
void resetLinkStates(const std::map< MSLink *, LinkState > &vals) const
Resets the states of controlled links.
void executeOnSwitchActions() const
The link has red light (must brake)
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
const std::string & getID() const
Returns the id.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
Builds detectors for microsim.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.