Eclipse SUMO - Simulation of Urban MObility
MSSwarmTrafficLightLogic.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The class for Swarm-based logics
16 /****************************************************************************/
17 
19 #include "../MSEdge.h"
20 
21 #if 1
22 #define ANALYSIS_DBG(X) {X}
23 #else
24 #define ANALYSIS_DBG(X) DBG(X)
25 #endif
26 
28  const std::string& programID, const Phases& phases, int step, SUMOTime delay,
29  const std::map<std::string, std::string>& parameters) :
30  MSSOTLHiLevelTrafficLightLogic(tlcontrol, id, programID, TLTYPE_SWARM_BASED, phases, step, delay, parameters) {
31 
32  std::string pols = getPoliciesParam();
33  std::transform(pols.begin(), pols.end(), pols.begin(), ::tolower);
34  DBG(std::ostringstream str; str << "policies: " << pols; WRITE_MESSAGE(str.str());)
35 
36  if (pols.find("platoon") != std::string::npos) {
37  addPolicy(new MSSOTLPlatoonPolicy(new MSSOTLPolicy5DFamilyStimulus("PLATOON", parameters), parameters));
38  }
39  if (pols.find("phase") != std::string::npos) {
40  addPolicy(new MSSOTLPhasePolicy(new MSSOTLPolicy5DFamilyStimulus("PHASE", parameters), parameters));
41  }
42  if (pols.find("marching") != std::string::npos) {
43  addPolicy(new MSSOTLMarchingPolicy(new MSSOTLPolicy5DFamilyStimulus("MARCHING", parameters), parameters));
44  }
45  if (pols.find("congestion") != std::string::npos) {
46  addPolicy(new MSSOTLCongestionPolicy(new MSSOTLPolicy5DFamilyStimulus("CONGESTION", parameters), parameters));
47  }
48 
49  if (getPolicies().empty()) {
50  WRITE_ERROR("NO VALID POLICY LIST READ");
51  }
52 
53  mustChange = false;
54  skipEta = false;
55  gotTargetLane = false;
56 
57  DBG(
58  std::ostringstream d_str; d_str << getMaxCongestionDuration(); vector<MSSOTLPolicy*> policies = getPolicies();
59 
60  WRITE_MESSAGE("getMaxCongestionDuration " + d_str.str()); for (int i = 0; i < policies.size(); i++) {
61  MSSOTLPolicy* policy = policies[i];
63  std::ostringstream _str;
64  _str << policy->getName() << stim->getMessage() << " getThetaSensitivity " << policy->getThetaSensitivity() << " .";
65  WRITE_MESSAGE(_str.str());
66  })
67  congestion_steps = 0;
68  m_useVehicleTypesWeights = getParameter("USE_VEHICLE_TYPES_WEIGHTS", "0") == "1";
69  if (m_useVehicleTypesWeights && pols.find("phase") == std::string::npos) {
70  WRITE_ERROR("VEHICLE TYPES WEIGHT only works with phase policy, which is missing");
71  }
72 }
73 
75  if (logData && swarmLogFile.is_open()) {
76  swarmLogFile.close();
77  }
78  for (std::map<std::string, CircularBuffer<double>*>::iterator it = m_meanSpeedHistory.begin();
79  it != m_meanSpeedHistory.end(); ++it) {
80  delete it->second;
81  }
82  m_meanSpeedHistory.clear();
83  for (std::map<std::string, CircularBuffer<double>*>::iterator it = m_derivativeHistory.begin();
84  it != m_derivativeHistory.end(); ++it) {
85  delete it->second;
86  }
87  m_derivativeHistory.clear();
88 }
89 
91  //No walking areas
92  if (lane->getEdge().isWalkingArea()) {
93  return false;
94  }
95  //No pedestrian crossing
96  if (lane->getEdge().isCrossing()) {
97  return false;
98  }
99  //No pedestrian only lanes
100  if (lane->getPermissions() == SVC_PEDESTRIAN) {
101  return false;
102  }
103  //No bicycle only lanes
104  if (lane->getPermissions() == SVC_BICYCLE) {
105  return false;
106  }
107  //No pedestrian and bicycle only lanes
108  if (lane->getPermissions() == (SVC_PEDESTRIAN | SVC_BICYCLE)) {
109  return false;
110  }
111  return true;
112 }
113 
116  //Setting the startup policy
117  choosePolicy(0, 0, 0, 0);
118  //Initializing the random number generator to a time-dependent seed
119  srand((int) time(nullptr));
120  //Initializing pheromone maps according to input lanes
121  //For each lane insert a pair into maps
122  MSLane* currentLane = nullptr;
123 
124 // Derivative
125  const int derivativeHistorySize = StringUtils::toInt(getParameter("PHERO_DERIVATIVE_HISTORY_SIZE", "3"));
126  const int meanSpeedHistorySize = StringUtils::toInt(getParameter("PHERO_MEAN_SPEED_HISTORY_SIZE", "3"));
127  m_derivativeAlpha = StringUtils::toDouble(getParameter("PHERO_DERIVATIVE_ALPHA", "1"));
128  m_losCounter = 0;
129  m_losMaxLimit = StringUtils::toInt(getParameter("LOSS_OF_SIGNAL_LIMIT", "10"));
130 
131  int index = 0;
132  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector = myLanes.begin();
133  laneVector != myLanes.end(); laneVector++) {
134  for (MSTrafficLightLogic::LaneVector::const_iterator lane = laneVector->begin(); lane != laneVector->end();
135  lane++) {
136  currentLane = (*lane);
137  if (pheromoneInputLanes.find(currentLane->getID()) == pheromoneInputLanes.end()) {
138  laneCheck[currentLane] = false;
139  if (allowLine(currentLane)) {
140  pheromoneInputLanes.insert(MSLaneId_Pheromone(currentLane->getID(), 0.0));
141 // Consider the derivative only for the input lane
142  m_meanSpeedHistory.insert(std::make_pair(currentLane->getID(), new CircularBuffer<double>(meanSpeedHistorySize)));
143  m_derivativeHistory.insert(std::make_pair(currentLane->getID(), new CircularBuffer<double>(derivativeHistorySize)));
144  ANALYSIS_DBG(
145  WRITE_MESSAGE("MSSwarmTrafficLightLogic::init Intersection " + getID() + " pheromoneInputLanes adding " + currentLane->getID());)
146  } else {
147  ANALYSIS_DBG(
148  WRITE_MESSAGE("MSSwarmTrafficLightLogic::init Intersection " + getID() + " pheromoneInputLanes: lane " + currentLane->getID() + " not allowed");)
149  }
150  }
151  m_laneIndexMap[currentLane->getID()].push_back(index++);
152  }
153  }
154 
156  for (int i = 0; i < (int)myLinks.size(); i++) {
157  LinkVector oneLink = getLinksAt(i);
158  for (int j = 0; j < (int)oneLink.size(); j++) {
159  currentLane = oneLink[j]->getLane();
160  if (pheromoneOutputLanes.find(currentLane->getID()) == pheromoneOutputLanes.end()) {
161  laneCheck[currentLane] = false;
162  if (allowLine(currentLane)) {
163  pheromoneOutputLanes.insert(MSLaneId_Pheromone(currentLane->getID(), 0.0));
164  ANALYSIS_DBG(
165  WRITE_MESSAGE("MSSwarmTrafficLightLogic::init Intersection " + getID() + " pheromoneOutputLanes adding " + currentLane->getID());)
166  } else {
167  ANALYSIS_DBG(
168  WRITE_MESSAGE("MSSwarmTrafficLightLogic::init Intersection " + getID() + " pheromoneOutputLanes lane " + currentLane->getID() + " not allowed");)
169  }
170  }
171  }
172  }
173 
176  //Initializing thresholds for theta evaluations
178 
179  WRITE_MESSAGE("*** Intersection " + getID() + " will run using MSSwarmTrafficLightLogic ***");
180  std::string logFileName = getParameter("SWARMLOG", "");
181  logData = logFileName.compare("") != 0;
182  if (logData) {
183  swarmLogFile.open(logFileName.c_str(), std::ios::out | std::ios::binary);
184  }
185 // Log the initial state
186  ANALYSIS_DBG(
187  WRITE_MESSAGE("TL " + getID() + " time 0 Policy: " + getCurrentPolicy()->getName() + " (pheroIn= 0 ,pheroOut= 0 ) OldPolicy: " + getCurrentPolicy()->getName() + " .");
188 // ostringstream maplog;
189 // for(map<string, vector<int> >::const_iterator mIt = m_laneIndexMap.begin();mIt != m_laneIndexMap.end();++mIt)
190 // {
191 // maplog << mIt->first <<'[';
192 // for(vector<int>::const_iterator vIt = mIt->second.begin();vIt != mIt->second.end();++vIt)
193 // maplog<<*vIt<<", ";
194 // maplog << "] ";
195 // }
196 // WRITE_MESSAGE("Map content " + maplog.str());
197  );
198 }
199 
201  //input
202  for (MSLaneId_PheromoneMap::iterator laneIterator = pheromoneInputLanes.begin();
203  laneIterator != pheromoneInputLanes.end(); laneIterator++) {
204  std::string laneId = laneIterator->first;
205  pheromoneInputLanes[laneId] = 0;
206  }
207  //output
208  for (MSLaneId_PheromoneMap::iterator laneIterator = pheromoneOutputLanes.begin();
209  laneIterator != pheromoneOutputLanes.end(); laneIterator++) {
210  std::string laneId = laneIterator->first;
211  pheromoneOutputLanes[laneId] = 0;
212  }
213 }
214 
216 
217  DBG(
218  MsgHandler::getMessageInstance()->inform("\n" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic decideNextPhase()"); std::ostringstream dnp; dnp << (MSNet::getInstance()->getCurrentTimeStep()) << " MSSwarmTrafficLightLogic::decideNextPhase:: " << "tlsid=" << getID() << " getCurrentPhaseDef().getState()=" << getCurrentPhaseDef().getState() << " is commit?" << getCurrentPhaseDef().isCommit(); MsgHandler::getMessageInstance()->inform(dnp.str());)
219  // if we're congested, it should be wise to reset and recalculate the pheromone levels after X steps
220 
221  if (getCurrentPhaseDef().isTarget()) {
223  }
224 
225  if (getCurrentPolicy()->getName().compare("Congestion") == 0 && getCurrentPhaseDef().isCommit()) {
226  congestion_steps += 1; //STEPS2TIME(getCurrentPhaseDef().duration);
227  DBG(
228  WRITE_MESSAGE("\n" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic decideNextPhase()"); std: ostringstream dnp; dnp << (MSNet::getInstance()->getCurrentTimeStep()) << " MSSwarmTrafficLightLogic::decideNextPhase:: " << "tlsid=" << getID() << " congestion_steps=" << congestion_steps; WRITE_MESSAGE(dnp.str());)
230  resetPheromone();
231  congestion_steps = 0;
232  mustChange = true;
233  if (getReinforcementMode() != 0) {
234  skipEta = true;
235  }
236  DBG(
237  WRITE_MESSAGE("\n" + time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic decideNextPhase()"); std::ostringstream dnp; dnp << (MSNet::getInstance()->getCurrentTimeStep()) << " MSSwarmTrafficLightLogic::decideNextPhase:: " << "tlsid=" << getID() << " max congestion reached, congestion_steps=" << congestion_steps; WRITE_MESSAGE(dnp.str());)
238  }
239  }
240 
241  //Update pheromone levels
243 
244  /* Since we changed the behaviour of computeReturnTime() in order to update pheromone levels every step
245  * it is now mandatory to check if the duration of a transient phase is elapsed or not*/
246  if (getCurrentPhaseDef().isTransient() && getCurrentPhaseElapsed() < getCurrentPhaseDef().duration) {
247  return getCurrentPhaseIndex();
248  }
249 
250  //Decide the current policy according to pheromone levels. this should be done only at the end of a chain, before selecting the new one
251  if (getCurrentPhaseDef().isCommit()) {
252  //Update learning and forgetting thresholds
254  decidePolicy();
255  gotTargetLane = false;
256  }
257 
258 // double phero =0;
259 // if(getCurrentPhaseDef().isDecisional())
260 // {
261 // for(LaneIdVector::const_iterator it = targetLanes.begin(); it != targetLanes.end(); ++it)
262 // {
263 // string name = (*it);
264 // phero +=pheromoneInputLanes[name];
265 // }
266 // phero /= targetLanes.size() == 0 ? 1 : targetLanes.size();
267 // if(getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration)
268 // if(abs(phero-pheroBegin) <= 2)
269 // return getCurrentPhaseIndex() + 1;
270 // }
271  DBG(
272  std::ostringstream str; str << "tlsID=" << getID() << " currentPolicyname=" + getCurrentPolicy()->getName(); WRITE_MESSAGE(str.str());)
273 
274  //Execute current policy. congestion "policy" must maintain the commit phase, and that must be an all-red one
277 // int newStep =getCurrentPolicy()->decideNextPhase(getCurrentPhaseElapsed(), &getCurrentPhaseDef(), getCurrentPhaseIndex(),
278 // getPhaseIndexWithMaxCTS(), isThresholdPassed(), isPushButtonPressed(), countVehicles(getCurrentPhaseDef()));
279 // if(newStep != myStep)
280 // pheroBegin = phero;
281 // return newStep;
282 }
283 
285  //Updating input lanes pheromone: all input lanes without distinction
286  //BETA_NO, GAMMA_NO
288 
289  //BETA_SP, GAMMA_SP
290  //Updating output lanes pheromone: only input lanes currently having green light. Pheromone for non green lanes is "freezed"
291 // if (getCurrentPhaseDef().isDecisional()) {
293 // }
294 }
295 
297  const double beta, const double gamma) {
298  // ANALYSIS_DBG(
299  DBG(
300  std::ostringstream _str; _str << logString << " Lanes " << pheroMap.size() << " TL " << getID() << " ."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::updatePheromoneLevels:: " + _str.str());)
301 
302  for (MSLaneId_PheromoneMap::iterator laneIterator = pheroMap.begin(); laneIterator != pheroMap.end();
303  ++laneIterator) {
304  std::string laneId = laneIterator->first;
305  double oldPhero = laneIterator->second;
306  double maxSpeed = getSensors()->getMaxSpeed(laneId);
307  double meanVehiclesSpeed = getSensors()->meanVehiclesSpeed(laneId);
308  bool updatePheromone = (meanVehiclesSpeed > -1);
309  // double pheroAdd = getSensors()->countVehicles(laneId);
310 
311  //derivative
312  double derivative = 0;
313  //If i need to use the derivative for the lane
314  if (m_meanSpeedHistory.find(laneId) != m_meanSpeedHistory.end()) {
315  //Update the derivative
316  if (updatePheromone) {
317  double currentDerivative = 0;
318  m_losCounter = 0;
319  if (m_meanSpeedHistory[laneId]->size() > 0) {
320  //Calculate the current derivative mean with the old speed points
321  for (int i = 0; i < m_meanSpeedHistory[laneId]->size(); ++i)
322  if (i == 0) {
323  currentDerivative += fabs(meanVehiclesSpeed - m_meanSpeedHistory[laneId]->at(i));
324  } else {
325  currentDerivative += fabs(m_meanSpeedHistory[laneId]->at(i - 1) - m_meanSpeedHistory[laneId]->at(i));
326  }
327  currentDerivative /= m_meanSpeedHistory[laneId]->size(); //Non weighted mean
328  }
329  m_meanSpeedHistory[laneId]->push_front(meanVehiclesSpeed);
330  //Check if the current value of the derivative is above the set alpha
331  if (currentDerivative >= m_derivativeAlpha) {
332  m_derivativeHistory[laneId]->push_front(currentDerivative);
333  }
334  if (m_derivativeHistory[laneId]->size() > 0) {
335  //Calculate the mean derivative with the old derivative
336  for (int i = 0; i < m_derivativeHistory[laneId]->size(); ++i) {
337  derivative += m_derivativeHistory[laneId]->at(i);
338  }
339  derivative /= m_derivativeHistory[laneId]->size();
340  }
341  } else {
342  //Reset the values if no information is received after a timeout
343  ++m_losCounter;
344  if (m_losCounter >= m_losMaxLimit) {
345  m_derivativeHistory[laneId]->clear();
346  m_meanSpeedHistory[laneId]->clear();
347  m_meanSpeedHistory[laneId]->push_front(maxSpeed);
348  }
349  }
350  }
351  double pheroAdd = MAX2((maxSpeed - meanVehiclesSpeed) * 10 / maxSpeed, 0.0);
352 // Use the derivative only if it has a value
353  if (derivative > 0)
354 // Correct the pheromone value by dividing it for the derivative.
355  {
356  pheroAdd /= MAX2(derivative, m_derivativeAlpha);
357  }
358 // pheroAdd /= max(derivative, 1.0);
359  ANALYSIS_DBG(
360  if (updatePheromone) {
361  std::ostringstream oss;
362  oss << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " l " << laneId;
363  oss << " der " << derivative << " phero " << pheroAdd << " maxS " << maxSpeed << " meanS " << meanVehiclesSpeed;
364  WRITE_MESSAGE(oss.str())
365  }
366  )
367 
368  // Evaporation + current contribute
369  double phero = beta * oldPhero + gamma * pheroAdd * updatePheromone;
370  ANALYSIS_DBG(
371  if (phero > 10) {
372  std::ostringstream i_str;
373  i_str << "MSSwarmTrafficLightLogic::updatePheromoneLevels " << logString << " > 10. Value: " << phero;
374  WRITE_MESSAGE(i_str.str())
375  });
376 
377  phero = MIN2(MAX2(phero, 0.0), getPheroMaxVal());
378  pheroMap[laneId] = phero;
379  ANALYSIS_DBG(
380  // DBG(
381  std::ostringstream i_str;
382  // i_str << " oldPheroIn " << oldPheroIn
383  // << " inMeanVehiclesSpeed " << meanVehiclesSpeed
384  // << " pheroInAdd " << pheroAdd * updatePheromoneIn
385  // << " pheroInEvaporated " << oldPheroIn-oldPheroIn*getBetaNo()
386  // << " pheroInDeposited " << getGammaNo() * pheroAdd * updatePheromoneIn
387  // <<" newPheroIn "<<pheromoneInputLanes[laneId]
388  // << " inLane "<< laneId<<" ID "<< getID() <<" .";
389  i_str << " op " << oldPhero << " ms " << meanVehiclesSpeed << " p " << pheroAdd * updatePheromone <<
390  " pe " << oldPhero - oldPhero * beta << " pd " << gamma * pheroAdd * updatePheromone << " np " <<
391  pheroMap[laneId] << " l " << laneId << " ID " << getID() << " c " << getSensors()->countVehicles(laneId) << " s " << getLaneLightState(laneId) << " ."; if (m_pheroLevelLog[laneId] != i_str.str()) {
392  m_pheroLevelLog[laneId] = i_str.str();
393  WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::updatePheromoneLevels:: " + logString + i_str.str());
394  })
395 
396  DBG(
397  std::ostringstream str; str << time2string(MSNet::getInstance()->getCurrentTimeStep()) << " MSSwarmTrafficLightLogic::countSensors:: lane " << laneId << " passedVeh " << getCountSensors()->getPassedVeh(laneId, false); WRITE_MESSAGE(str.str());)
398 
399 // int vehicles = getSensors()->countVehicles(laneId);
400 // double pheroIn = getBetaNo() * oldPheroIn + // Evaporation
401 // getGammaNo() * vehicles;
402 // DBG(
403 // std::ostringstream i_str;
404 // i_str << " vehicles " << getSensors()->countVehicles(laneId)<<" pheromoneInputLanes "<<pheromoneInputLanes[laneId] << " lane "<< laneId<<" ID "<< getID() <<" .";
405 // MsgHandler::getMessageInstance()->inform(time2string(MSNet::getInstance()->getCurrentTimeStep()) +" MSSwarmTrafficLightLogic::updatePheromoneLevels:: PheroIn"+i_str.str());
406 // )
407 //
408 // pheroIn = MIN2(MAX2(pheroIn, 0.0), getPheroMaxVal());
409 // pheromoneInputLanes[laneId] = pheroIn;
410  }
411 }
413  double elapsedTime = STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - lastThetaSensitivityUpdate);
415 
417  std::vector<MSSOTLPolicy*> policies = getPolicies();
418 
419  //reset of the sensitivity thresholds in case of 0 pheromone on the input lanes
420  if (getPheromoneForInputLanes() == 0) {
421  for (int i = 0; i < (int)policies.size(); i++) {
422  policies[i]->setThetaSensitivity(getThetaInit());
423 // ANALYSIS_DBG(
424  DBG(
425  std::ostringstream phero_str; phero_str << "Policy " << policies[i]->getName() << " sensitivity reset to " << policies[i]->getThetaSensitivity() << " due to evaporated input pheromone."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::updateSensitivities::" + phero_str.str());)
426  }
427  return;
428  }
429 
430  double eta = -1.;
431  // If skipEta it means that we've had Congestion for too much time. Forcing forgetting.
432  if (!skipEta || currentPolicy->getName().compare("Congestion") != 0) {
433  switch (getReinforcementMode()) {
434  case 0:
435  if (elapsedTime == STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep())) {
436  return; //we don't want to reinforce the policy selected at the beginning of the simulation since it's time-based
437  }
438  eta = elapsedTime;
439  break;
440  case 1:
441  eta = calculateEtaDiff();
442  break;
443  case 2:
444  eta = calculateEtaRatio();
445  break;
446  }
447  }
448  for (int i = 0; i < (int)policies.size(); i++) {
449  MSSOTLPolicy* policy = policies[i];
450  double newSensitivity;
451  if (eta < 0) { //bad performance
452  if (policy == currentPolicy) { // punish the current policy
453  newSensitivity = policy->getThetaSensitivity() + getForgettingCox() * (-eta);
454  } else
455  // reward the other ones
456  {
457  newSensitivity = policy->getThetaSensitivity() - getLearningCox() * (-eta);
458  }
459  } else { //good performance
460  if (policy == currentPolicy) { //reward the current policy
461  newSensitivity = policy->getThetaSensitivity() - getLearningCox() * eta;
462  } else
463  // punish the other ones
464  {
465  newSensitivity = policy->getThetaSensitivity() + getForgettingCox() * eta;
466  }
467  }
468 // ANALYSIS_DBG(
469  DBG(
470  std::ostringstream lf; std::ostringstream phero_str; if (getReinforcementMode() == 0) {
471  if (policy == currentPolicy) {
472  lf << " ,LearningCox " << getLearningCox() << " ,LCox*Time " << getLearningCox() * elapsedTime;
473  } else {
474  lf << " ,ForgettingCox " << getForgettingCox() << " ,FCox*Time " << getForgettingCox() * elapsedTime;
475  }
476 
477  phero_str << " policy " << policy->getName() << " newSensitivity " << newSensitivity << " ,pol.Sensitivity " << policy->getThetaSensitivity() << " ,elapsedTime " << elapsedTime << lf.str() << " NEWERSensitivity= " << max(min(newSensitivity, getThetaMax()), getThetaMin()) << " ID " << getID() << " .";
478  } else {
479  if (policy == currentPolicy && eta > 0) {
480  lf << " ,LearningCox " << getLearningCox() << " ,LCox*Eta " << getLearningCox() * eta;
481  } else if (policy == currentPolicy && eta < 0) {
482  lf << " ,ForgettingCox " << getForgettingCox() << " ,FCox*Eta " << getForgettingCox() * eta;
483  } else if (eta > 0) {
484  lf << " ,ForgettingCox " << getForgettingCox() << " ,FCox*Eta " << getForgettingCox() * eta;
485  } else if (eta < 0) {
486  lf << " ,LearningCox " << getLearningCox() << " ,LCox*Eta " << getLearningCox() * eta;
487  }
488  phero_str << " policy " << policy->getName() << " newSensitivity " << newSensitivity << " ,pol.Sensitivity " << policy->getThetaSensitivity() << " ,eta " << eta << " ,carsIn " << carsIn << " ,inTarget " << inTarget << " ,notTarget " << notTarget << " ,carsOut " << carsOut << lf.str() << " NEWERSensitivity= " << max(min(newSensitivity, getThetaMax()), getThetaMin()) << " ID " << getID() << " .";
489  }
490  WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::updateSensitivities::" + phero_str.str());)
491 
492  newSensitivity = MAX2(MIN2(newSensitivity, getThetaMax()), getThetaMin());
493  policy->setThetaSensitivity(newSensitivity);
494  }
495 }
496 
498  if (pheromoneInputLanes.size() == 0) {
499  return 0;
500  }
501  double pheroIn = 0;
502  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneInputLanes.begin();
503  iterator != pheromoneInputLanes.end(); iterator++) {
504  std::string laneId = iterator->first;
505  pheroIn += iterator->second;
506  DBG(
507  std::ostringstream phero_str; phero_str << " lane " << iterator->first << " pheromoneIN " << iterator->second << " id " << getID() << " ."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::getPheromoneForInputLanes::" + phero_str.str());)
508  }
509 
510  DBG(
511  std::ostringstream o_str; o_str << " TOTpheromoneIN " << pheroIn << " return " << pheroIn / pheromoneInputLanes.size() << getID() << " ."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::getPheromoneForInputLanes::" + o_str.str());)
512  return pheroIn / pheromoneInputLanes.size();
513 }
514 
516  if (pheromoneOutputLanes.size() == 0) {
517  return 0;
518  }
519  double pheroOut = 0;
520  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneOutputLanes.begin();
521  iterator != pheromoneOutputLanes.end(); iterator++) {
522  DBG(
523  std::ostringstream phero_str; phero_str << " lane " << iterator->first << " pheromoneOUT " << iterator->second << " id " << getID() << " ."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::getPheromoneForOutputLanes::" + phero_str.str());)
524  pheroOut += iterator->second;
525  }
526  DBG(
527  std::ostringstream o_str; o_str << " TOTpheromoneOUT " << pheroOut << " return " << pheroOut / pheromoneOutputLanes.size() << " id " << getID() << " ."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::getPheromoneForOutputLanes::" + o_str.str());)
528  return pheroOut / pheromoneOutputLanes.size();
529 }
530 
532  if (pheromoneInputLanes.size() == 0) {
533  return 0;
534  }
535  double sum = 0;
536  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneInputLanes.begin();
537  iterator != pheromoneInputLanes.end(); iterator++) {
538  std::string laneId = iterator->first;
539  sum += pow(iterator->second - average_phero_in, 2);
540  }
541 
542  double result = sqrt(sum / pheromoneInputLanes.size()) * getScaleFactorDispersionIn();
543  DBG(
544  ostringstream so_str; so_str << " dispersionIn " << result; WRITE_MESSAGE("MSSwarmTrafficLightLogic::getDispersionForInputLanes::" + so_str.str());)
545  return result;
546 }
547 
549  if (pheromoneOutputLanes.size() == 0) {
550  return 0;
551  }
552  double sum = 0;
553  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneOutputLanes.begin();
554  iterator != pheromoneOutputLanes.end(); iterator++) {
555  sum += pow(iterator->second - average_phero_out, 2);
556  }
557 
558  double result = sqrt(sum / pheromoneOutputLanes.size()) * getScaleFactorDispersionOut();
559  DBG(
560  ostringstream so_str; so_str << " dispersionOut " << result; WRITE_MESSAGE("MSSwarmTrafficLightLogic::getDispersionForOutputLanes::" + so_str.str());)
561  return result;
562 }
564  if (pheromoneInputLanes.size() == 0) {
565  return 0;
566  }
567  double max_phero_val_current = 0;
568  double max_phero_val_old = 0;
569  double temp_avg_other_lanes = 0;
570  std::string laneId_max;
571  int counter = 0;
572  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneInputLanes.begin();
573  iterator != pheromoneInputLanes.end(); iterator++) {
574  std::string laneId = iterator->first;
575  double lanePhero = iterator->second;
576  if (counter == 0) {
577  max_phero_val_current = lanePhero;
578  counter++;
579  continue;
580  }
581  if (lanePhero > max_phero_val_current) {
582  max_phero_val_old = max_phero_val_current;
583  max_phero_val_current = lanePhero;
584  temp_avg_other_lanes = (temp_avg_other_lanes * (counter - 1) + max_phero_val_old) / counter;
585  } else {
586  temp_avg_other_lanes = (temp_avg_other_lanes * (counter - 1) + lanePhero) / counter;
587  }
588 
589  counter++;
590  }
591 
592  double result = max_phero_val_current - temp_avg_other_lanes;
593  DBG(
594  ostringstream so_str; so_str << " currentMaxPhero " << max_phero_val_current << " lane " << laneId_max << " avgOtherLanes " << temp_avg_other_lanes << " distance " << result; WRITE_MESSAGE("MSSwarmTrafficLightLogic::getDistanceOfMaxPheroForInputLanes::" + so_str.str());)
595  return result;
596 }
597 
599  if (pheromoneOutputLanes.size() == 0) {
600  return 0;
601  }
602  double max_phero_val_current = 0;
603  double max_phero_val_old = 0;
604  double temp_avg_other_lanes = 0;
605  std::string laneId_max;
606  int counter = 0;
607  for (MSLaneId_PheromoneMap::const_iterator iterator = pheromoneOutputLanes.begin();
608  iterator != pheromoneOutputLanes.end(); iterator++) {
609  std::string laneId = iterator->first;
610  double lanePhero = iterator->second;
611  if (counter == 0) {
612  max_phero_val_current = lanePhero;
613  counter++;
614  continue;
615  }
616  if (lanePhero > max_phero_val_current) {
617  max_phero_val_old = max_phero_val_current;
618  max_phero_val_current = lanePhero;
619  temp_avg_other_lanes = (temp_avg_other_lanes * (counter - 1) + max_phero_val_old) / counter;
620  } else {
621  temp_avg_other_lanes = (temp_avg_other_lanes * (counter - 1) + lanePhero) / counter;
622  }
623 
624  counter++;
625  }
626 
627  double result = max_phero_val_current - temp_avg_other_lanes;
628  DBG(
629  ostringstream so_str; so_str << " currentMaxPhero " << max_phero_val_current << " lane " << laneId_max << " avgOtherLanes " << temp_avg_other_lanes << " distance " << result; WRITE_MESSAGE("MSSwarmTrafficLightLogic::getDistanceOfMaxPheroForOutputLanes::" + so_str.str());)
630  return result;
631 }
633 // MSSOTLPolicy* currentPolicy = getCurrentPolicy();
634  // Decide if it is the case to check for another plan
635 // double sampled = (double) RandHelper::rand(RAND_MAX);
636  double sampled = RandHelper::rand();
637  double changeProb = getChangePlanProbability();
638 // changeProb = changeProb * RAND_MAX;
639 
640  if (sampled <= changeProb || mustChange) { // Check for another plan
641 
642  double pheroIn = getPheromoneForInputLanes();
643  double pheroOut = getPheromoneForOutputLanes();
644  //double dispersionIn = getDispersionForInputLanes(pheroIn);
645  //double dispersionOut = getDispersionForOutputLanes(pheroOut);
646  double distancePheroIn = getDistanceOfMaxPheroForInputLanes();
647  double distancePheroOut = getDistanceOfMaxPheroForOutputLanes();
648  MSSOTLPolicy* oldPolicy = getCurrentPolicy();
649  choosePolicy(pheroIn, pheroOut, distancePheroIn, distancePheroOut);
650  MSSOTLPolicy* newPolicy = getCurrentPolicy();
651 
652  if (newPolicy != oldPolicy) {
653  ANALYSIS_DBG(
654  SUMOTime step = MSNet::getInstance()->getCurrentTimeStep(); std::ostringstream phero_str; phero_str << " (pheroIn= " << pheroIn << " ,pheroOut= " << pheroOut << " )"; WRITE_MESSAGE("TL " + getID() + " time " + time2string(step) + " Policy: " + newPolicy->getName() + phero_str.str() + " OldPolicy: " + oldPolicy->getName() + " id " + getID() + " .");)
655  if (oldPolicy->getName().compare("Congestion") == 0) {
656  congestion_steps = 0;
657  }
658  } else { //debug purpose only
659  ANALYSIS_DBG(
660  std::ostringstream phero_str; phero_str << " (pheroIn= " << pheroIn << " ,pheroOut= " << pheroOut << " )"; SUMOTime step = MSNet::getInstance()->getCurrentTimeStep(); WRITE_MESSAGE("TL " + getID() + " time " + time2string(step) + " Policy: Nochanges" + phero_str.str() + " OldPolicy: " + oldPolicy->getName() + " id " + getID() + " .");)
661  }
662 
663  mustChange = false;
664  skipEta = false;
665  }
666 }
667 
669  if (factor == 0) {
670  return 1;
671  }
672  if (factor == 1) {
673  return 0.2;
674  } else {
675  return 1 - (1 / ((double) factor));
676  }
677 }
678 
680 
681  MSLane* currentLane = nullptr;
682  int count = 0, minIn = 0, minOut = 0, toSub, tmp;
683  bool inInit = true, outInit = true;
684  double eta, normalized, diff, phi, delta;
685  LaneIdVector toReset;
686 
687  carsIn = 0;
688  carsOut = 0;
689  inTarget = 0;
690  notTarget = 0;
691 
693 
694  // Search the incoming lane to get the count of the vehicles passed. [IN]
695  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector = myLanes.begin();
696  laneVector != myLanes.end(); laneVector++) {
697  for (MSTrafficLightLogic::LaneVector::const_iterator lane = laneVector->begin(); lane != laneVector->end();
698  lane++) {
699  currentLane = (*lane);
700 
701  // Map to avoid check the lane for every possible direction
702  if (laneCheck[currentLane] == false) {
703  // Get the vehicles passed from this lane.
704  count = sensors->getPassedVeh(currentLane->getID(), false);
705 
706  DBG(
707  std::ostringstream cars_str; cars_str << "Lane " << currentLane->getID() << ": vehicles entered - " << count; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
708 
709  // Increment the global count of the cars passed through the tl
710  carsIn += count;
711  // Set to true to skip similar lane since there's just one sensor
712  laneCheck[currentLane] = true;
713  }
714  }
715  }
716 
717  // Search the outgoing lane to get the count of the vehicles passed. [OUT]
718  // We use the links to get the respective lane id.
719  for (MSTrafficLightLogic::LinkVectorVector::const_iterator linkVector = myLinks.begin();
720  linkVector != myLinks.end(); linkVector++) {
721  for (MSTrafficLightLogic::LinkVector::const_iterator link = linkVector->begin(); link != linkVector->end();
722  link++) {
723  currentLane = (*link)->getLane();
724 
725  // Map to avoid check the lane for every possible direction
726  if (laneCheck[currentLane] == false) {
727  // Get the vehicles passed from this lane.
728  count = sensors->getPassedVeh(currentLane->getID(), true);
729 
730  DBG(
731  std::ostringstream cars_str; cars_str << "Lane " << currentLane->getID() << ": vehicles gone out- " << count; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
732 
733  // Increment the global count of the cars passed through the tl
734  carsOut += count;
735 
736  // Since there's no output target lanes we check here the minimum number of
737  // cars passed though the tl. This ahs to be done to all the output lanes since cars can go
738  // in any direction from a target lane. If a direction isn't reachable the sensor count will be 0.
739  // This is done to update the sensorCount value in order to don't make it grow too much.
740  if (count != 0) {
741  toReset.push_back(currentLane->getID());
742  if (outInit) {
743  minOut = count;
744  outInit = false;
745  } else if (count <= minOut) {
746  minOut = count;
747  }
748  }
749  // Set to true to skip similar lane since there's just one sensor
750  laneCheck[currentLane] = true;
751  }
752  }
753  }
754  // Reset the map to check again all the lane on the next commit.
755  resetLaneCheck();
756 
757  // We retrieve the minimum number of cars passed from the target lanes.
758  for (LaneIdVector::const_iterator laneId = targetLanes.begin(); laneId < targetLanes.end(); laneId++) {
759  std::string lane = (*laneId);
760  tmp = sensors->getPassedVeh(lane, false);
761  inTarget += tmp;
762  if (inInit && tmp != 0) {
763  minIn = tmp;
764  inInit = false;
765  }
766  if (tmp < minIn && tmp != 0) {
767  minIn = tmp;
768  }
769  if (tmp != 0) {
770  toReset.push_back(lane);
771  }
772  DBG(
773  std::ostringstream cars_str; cars_str << "Lane " << lane << " passed: " << tmp; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
774  }
775 
776  // The cars not on a target lane counted as in.
778 
779  // Calculate the min beetween the min number of cars entered the tl (minIn) and the
780  // ones that have exit the tl (minOut)
781  toSub = std::min(minIn, minOut);
782 
783  // Subtract the value to all the sensor on the target lanes.
784  while (!toReset.empty()) {
785  std::string laneId = toReset.back();
786  toReset.pop_back();
787  sensors->subtractPassedVeh(laneId, toSub);
788  }
789 
790  //Normalized to 1
791  diff = inTarget - carsOut;
792  normalized = diff / inTarget;
793 
794  // Analize difference to return an appropriate eta to reinforce/forget the policies.
795 
796  DBG(
797  std::ostringstream final_str; final_str << "Total cars in lanes: " << carsIn << " Total cars out: " << carsOut << " Difference: " << diff << " Pure eta: " << normalized; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + final_str.str());)
798  DBG(
799  std::ostringstream eta_str; eta_str << "IN:" << inTarget << " OUT:" << carsOut << " R:" << notTarget; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
800  DBG(
801  std::ostringstream eta_str; eta_str << "Min found:" << toSub << " MinIn:" << minIn << " MinOut:" << minOut; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
802 
803  // IN > OUT
804  if (inTarget > carsOut) {
805  if (carsOut == 0) {
806  // We're in Congestion but not for long so we don't do nothing. When we reach max steps for
807  // Congestion the evaluation of eta is skipped and we force a forget of the policy
808  if (getCurrentPolicy()->getName().compare("Congestion") == 0) {
809  eta = 0;
810  }
811  // vehicles aren't going out and we've additional vehicle on a red lane. We set
812  // eta to -1 to forget
813  else {
814  eta = -1;
815  }
816  } else {
817  // Forget - Amplify to R
818  phi = calculatePhi(notTarget);
819  eta = (-normalized * (1 / phi));
820  if (eta < -1.0) {
821  eta = -1.0;
822  }
823  }
824  }
825 
826  // IN = OUT
827  else if (inTarget == carsOut) {
828  // Can't say nothing
829  if (inTarget == 0) {
830  eta = 0;
831  }
832 
833  // Reinforce - Attenuate to R
834  // Normalized = 0 --> use delta = 1-1/IN
835  else {
836  delta = calculatePhi(inTarget);
837  phi = calculatePhi(notTarget);
838  eta = delta * phi;
839  if (eta > 1.0) {
840  eta = 1.0;
841  }
842  }
843  }
844 
845  // IN < OUT
846  else {
847  // Can't say nothing
848  if (inTarget == 0) {
849  eta = 0;
850  }
851 
852  // Reinforce - Attenuate to R
853  else {
854  phi = calculatePhi(notTarget);
855  diff = inTarget - carsOut;
856  normalized = diff / carsOut;
857  eta = normalized * phi;
858  if (eta > 1.0) {
859  eta = 1.0;
860  }
861  }
862  }
863 
864  DBG(
865  std::ostringstream eta_str; eta_str << "Eta Normalized: " << eta; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
866  return eta;
867 }
868 
870  MSLane* currentLane = nullptr;
871  int count = 0, minIn = 0, minOut = 0, toSub, tmp;
872  bool inInit = true, outInit = true;
873  double eta, ratio, phi, normalized, delta;
874  LaneIdVector toReset;
875 
876  carsIn = 0;
877  carsOut = 0;
878  inTarget = 0;
879  notTarget = 0;
880 
882 
883  // Search the incoming lane to get the count of the vehicles passed. [IN]
884  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector = myLanes.begin();
885  laneVector != myLanes.end(); laneVector++) {
886  for (MSTrafficLightLogic::LaneVector::const_iterator lane = laneVector->begin(); lane != laneVector->end();
887  lane++) {
888  currentLane = (*lane);
889 
890  // Map to avoid check the lane for every possible direction
891  if (laneCheck[currentLane] == false) {
892  // Get the vehicles passed from this lane.
893  count = sensors->getPassedVeh(currentLane->getID(), false);
894 
895  DBG(
896  std::ostringstream cars_str; cars_str << "Lane " << currentLane->getID() << ": vehicles entered - " << count; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
897 
898  // Increment the global count of the cars passed through the tl
899  carsIn += count;
900  // Set to true to skip similar lane since there's just one sensor
901  laneCheck[currentLane] = true;
902  }
903  }
904  }
905 
906  // Search the outgoing lane to get the count of the vehicles passed. [OUT]
907  // We use the links to get the respective lane id.
908  for (MSTrafficLightLogic::LinkVectorVector::const_iterator linkVector = myLinks.begin();
909  linkVector != myLinks.end(); linkVector++) {
910  for (MSTrafficLightLogic::LinkVector::const_iterator link = linkVector->begin(); link != linkVector->end();
911  link++) {
912  currentLane = (*link)->getLane();
913 
914  // Map to avoid check the lane for every possible direction
915  if (laneCheck[currentLane] == false) {
916  // Get the vehicles passed from this lane.
917  count = sensors->getPassedVeh(currentLane->getID(), true);
918 
919  DBG(
920  std::ostringstream cars_str; cars_str << "Lane " << currentLane->getID() << ": vehicles gone out- " << count; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
921 
922  // Increment the global count of the cars passed through the tl
923  carsOut += count;
924 
925  // Since there's no output target lanes we check here the minimum number of
926  // cars passed though the tl. This has to be done to all the output lanes since cars can go
927  // in any direction from a target lane. If a direction isn't reachable the sensor count will be 0.
928  // This is done to update the sensorCount value in order to don't make it grow too much.
929  if (count != 0) {
930  toReset.push_back(currentLane->getID());
931  if (outInit) {
932  minOut = count;
933  outInit = false;
934  } else if (count <= minOut) {
935  minOut = count;
936  }
937  }
938 
939  // Set to true to skip similar lane since there's just one sensor
940  laneCheck[currentLane] = true;
941  }
942  }
943  }
944  // Reset the map to check again all the lane on the next commit.
945  resetLaneCheck();
946 
947  // We retrieve the minimum number of cars passed from the target lanes.
948  for (LaneIdVector::const_iterator laneId = targetLanes.begin(); laneId < targetLanes.end(); laneId++) {
949  std::string lane = (*laneId);
950  tmp = sensors->getPassedVeh(lane, false);
951  inTarget += tmp;
952  if (inInit && tmp != 0) {
953  minIn = tmp;
954  inInit = false;
955  }
956  if (tmp < minIn && tmp != 0) {
957  minIn = tmp;
958  }
959  if (tmp != 0) {
960  toReset.push_back(lane);
961  }
962  DBG(
963  std::ostringstream cars_str; cars_str << "Lane " << lane << " passed: " << tmp; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + cars_str.str());)
964  }
965 
966  // The cars not on a target lane counted as in.
968 
969  // Calculate the min beetween the min number of cars entered the tl (minIn) and the
970  // ones that have exit the tl (minOut)
971  toSub = std::min(minIn, minOut);
972 
973  // Subtract the value to all the sensor on the target lanes.
974  while (!toReset.empty()) {
975  std::string laneId = toReset.back();
976  toReset.pop_back();
977  sensors->subtractPassedVeh(laneId, toSub);
978  }
979 
980  //Normalized to 1
981  if (carsOut != 0) {
982  ratio = ((double) inTarget) / carsOut;
983  normalized = ratio / (inTarget + carsOut);
984  } else {
985  ratio = std::numeric_limits<double>::infinity();
986  normalized = std::numeric_limits<double>::infinity();
987  }
988 
989  DBG(
990  std::ostringstream final_str; final_str << "Total cars in lanes: " << carsIn << " Total cars out: " << carsOut << " Ratio: " << ratio << " Pure eta: " << normalized; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + final_str.str());)
991  DBG(
992  std::ostringstream eta_str; eta_str << "IN:" << inTarget << ". OUT:" << carsOut << " R:" << notTarget; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
993  DBG(
994  std::ostringstream eta_str; eta_str << "Min found:" << toSub << ". MinIn:" << minIn << " MinOut:" << minOut; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
995  // Analize ratio to return an appropriate eta to reinforce/forget the policies.
996 
997  // IN > OUT
998  if (inTarget > carsOut) {
999  if (carsOut == 0) {
1000  // we're in Congestion but not for long so we don't do nothing. When we reach max steps for
1001  // Congestion the evaluation of eta is skipped and we force a forget of the policy
1002  if (getCurrentPolicy()->getName().compare("Congestion") == 0) {
1003  eta = 0;
1004  }
1005  // vehicles aren't going out and we've additional vehicle on a red lane. We set
1006  // eta to -1 to forget
1007  else {
1008  eta = -1;
1009  }
1010  } else {
1011  // Forget according to the ratio. Amplify due to the cars in the red lanes
1012  phi = calculatePhi(notTarget);
1013  eta = (-(normalized) * (1 / phi));
1014  if (eta < -1.0) {
1015  eta = -1.0;
1016  }
1017  }
1018  }
1019  // IN = OUT
1020  else if (inTarget == carsOut) {
1021  // We can't say nothing.
1022  if (inTarget == 0) {
1023  eta = 0;
1024  }
1025  // Reinforce - Attenuate to R
1026  // same number of vehicles that are getting IN is getting OUT
1027  // Normalized = 1/TOT ---> change to delta = 1-1/IN
1028  else {
1029  delta = calculatePhi(inTarget);
1030  phi = calculatePhi(notTarget);
1031  eta = delta * phi;
1032  if (eta > 1.0) {
1033  eta = 1.0;
1034  }
1035  }
1036  }
1037  // IN < OUT
1038  else {
1039  // We can't say nothing.
1040  if (inTarget == 0) {
1041  eta = 0;
1042  }
1043 
1044  // There was a queue and now cars are getting over it
1045  // There're vehicles on the red lanes (R)
1046  // We reinforce and attenuate according to R
1047  else {
1048  phi = calculatePhi(notTarget);
1049  eta = (normalized) * phi;
1050  if (eta > 1.0) {
1051  eta = 1.0;
1052  }
1053  }
1054  }
1055 
1056  DBG(
1057  std::ostringstream eta_str; eta_str << "Eta Normalized: " << eta << "."; WRITE_MESSAGE(time2string(MSNet::getInstance()->getCurrentTimeStep()) + " MSSwarmTrafficLightLogic::calculateEta::" + eta_str.str());)
1058  return eta;
1059 
1060 }
1061 
1063 
1064  MSLane* currentLane = nullptr;
1065 
1066  // reset both the input and the output lanes.
1067  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector = myLanes.begin();
1068  laneVector != myLanes.end(); laneVector++) {
1069 
1070  for (MSTrafficLightLogic::LaneVector::const_iterator lane = laneVector->begin(); lane != laneVector->end();
1071  lane++) {
1072  currentLane = (*lane);
1073  laneCheck[currentLane] = false;
1074  }
1075  }
1076 
1077  for (MSTrafficLightLogic::LinkVectorVector::const_iterator linkVector = myLinks.begin();
1078  linkVector != myLinks.end(); linkVector++) {
1079  for (MSTrafficLightLogic::LinkVector::const_iterator link = linkVector->begin(); link != linkVector->end();
1080  link++) {
1081  currentLane = (*link)->getLane();
1082  laneCheck[currentLane] = false;
1083  }
1084  }
1085 }
1086 
1087 void MSSwarmTrafficLightLogic::choosePolicy(double phero_in, double phero_out, double dispersion_in,
1088  double dispersion_out) {
1090  for (std::vector<MSSOTLPolicy*>::iterator it = getPolicies().begin(); it != getPolicies().end(); ++it) {
1091  if (it.operator * ()->getName() == "Phase") {
1092  activate(*it);
1093  return;
1094  }
1095  }
1096  }
1097  std::vector<double> thetaStimuli;
1098  double thetaSum = 0.0;
1099  // Compute stimulus for each policy
1100  for (int i = 0; i < (int)getPolicies().size(); i++) {
1101  double stimulus = getPolicies()[i]->computeDesirability(phero_in, phero_out, dispersion_in, dispersion_out);
1102  double thetaStimulus = pow(stimulus, 2) / (pow(stimulus, 2) + pow(getPolicies()[i]->getThetaSensitivity(), 2));
1103 
1104  thetaStimuli.push_back(thetaStimulus);
1105  thetaSum += thetaStimulus;
1106 
1107 // ANALYSIS_DBG(
1108  DBG(
1109  ostringstream so_str; so_str << " policy " << getPolicies()[i]->getName() << " stimulus " << stimulus << " pow(stimulus,2) " << pow(stimulus, 2) << " pow(Threshold,2) " << pow(getPolicies()[i]->getThetaSensitivity(), 2) << " thetaStimulus " << thetaStimulus << " thetaSum " << thetaSum << " TL " << getID(); WRITE_MESSAGE("MSSwarmTrafficLightLogic::choosePolicy::" + so_str.str());)
1110 
1111  }
1112 
1113  // Compute a random value between 0 and the sum of the thetaSum
1114 // double r = RandHelper::rand(RAND_MAX);
1115 // r = r / RAND_MAX * thetaSum;
1116  double r = RandHelper::rand((double)thetaSum);
1117 
1118  double partialSum = 0;
1119  for (int i = 0; i < (int)getPolicies().size(); i++) {
1120  partialSum += thetaStimuli[i];
1121 
1122 // ANALYSIS_DBG(
1123  DBG(
1124  ostringstream aao_str; aao_str << " policy " << getPolicies()[i]->getName() << " partialSum " << partialSum << " thetaStimuls " << thetaStimuli[i] << " r " << r << " TL " << getID(); WRITE_MESSAGE("MSSwarmTrafficLightLogic::choosePolicy::" + aao_str.str());)
1125 
1126  if (partialSum >= r) {
1127  activate(getPolicies()[i]);
1128  break;
1129  }
1130  }
1131 }
1132 
1133 void MSSwarmTrafficLightLogic::choosePolicy(double phero_in, double phero_out) {
1134  choosePolicy(phero_in, phero_out, 0, 0);
1135 }
1136 
1137 //never called...
1139  DBG(
1140  std::ostringstream phero_str; phero_str << "getCurrentPhaseElapsed()=" << time2string(getCurrentPhaseElapsed()) << " isThresholdPassed()=" << isThresholdPassed() << " currentPhase=" << (&getCurrentPhaseDef())->getState() << " countVehicles()=" << countVehicles(getCurrentPhaseDef()); WRITE_MESSAGE("MSSwamTrafficLightLogic::canRelease(): " + phero_str.str());)
1143 }
1144 
1145 std::string MSSwarmTrafficLightLogic::getLaneLightState(const std::string& laneId) {
1146  std::string laneState = "";
1147  if (m_laneIndexMap.find(laneId) != m_laneIndexMap.end()) {
1148  std::string state = getCurrentPhaseDef().getState();
1149  for (std::vector<int>::const_iterator it = m_laneIndexMap[laneId].begin(); it != m_laneIndexMap[laneId].end(); ++it) {
1150  laneState += state[*it];
1151  }
1152  }
1153  return laneState;
1154 }
MSSOTLPolicy::decideNextPhase
virtual int decideNextPhase(SUMOTime elapsed, const MSPhaseDefinition *stage, int currentPhaseIndex, int phaseMaxCTS, bool thresholdPassed, bool pushButtonPressed, int vehicleCount)
Definition: MSSOTLPolicy.cpp:120
CircularBuffer
Definition: MSSwarmTrafficLightLogic.h:36
SVC_PEDESTRIAN
pedestrian
Definition: SUMOVehicleClass.h:156
TLTYPE_SWARM_BASED
Definition: SUMOXMLDefinitions.h:1208
MSTrafficLightLogic::getLinksAt
const LinkVector & getLinksAt(int i) const
Returns the list of links that are controlled by the signals at the given position.
Definition: MSTrafficLightLogic.h:212
MSTrafficLightLogic::myLinks
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Definition: MSTrafficLightLogic.h:417
MSTrafficLightLogic::myLanes
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
Definition: MSTrafficLightLogic.h:420
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
MSSOTLPolicy
Class for a low-level policy.
Definition: MSSOTLPolicy.h:64
MSSOTLPolicy::getThetaSensitivity
virtual double getThetaSensitivity()
Definition: MSSOTLPolicy.h:111
MSSOTLTrafficLightLogic::getCountSensors
MSSOTLE2Sensors * getCountSensors()
Return the sensors that count the passage of vehicles in and out of the tl.
Definition: MSSOTLTrafficLightLogic.h:182
MSSwarmTrafficLightLogic::getScaleFactorDispersionIn
double getScaleFactorDispersionIn()
Definition: MSSwarmTrafficLightLogic.h:176
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSSOTLMarchingPolicy
Class for low-level marching policy.
Definition: MSSOTLMarchingPolicy.h:33
MSSwarmTrafficLightLogic::calculateEtaRatio
double calculateEtaRatio()
Definition: MSSwarmTrafficLightLogic.cpp:869
MSSwarmTrafficLightLogic::getGammaNo
double getGammaNo()
Definition: MSSwarmTrafficLightLogic.h:140
MSSwarmTrafficLightLogic::skipEta
bool skipEta
When true indicates that we can skip the evaluation of eta since we've a congestion policy that is la...
Definition: MSSwarmTrafficLightLogic.h:415
MSSOTLTrafficLightLogic::isThresholdPassed
bool isThresholdPassed()
Definition: MSSOTLTrafficLightLogic.cpp:305
MSSwarmTrafficLightLogic::carsOut
int carsOut
Definition: MSSwarmTrafficLightLogic.h:423
MSSwarmTrafficLightLogic::initScaleFactorDispersionOut
void initScaleFactorDispersionOut(int lanes_out)
Definition: MSSwarmTrafficLightLogic.h:360
MSSwarmTrafficLightLogic::getBetaNo
double getBetaNo()
Definition: MSSwarmTrafficLightLogic.h:136
MSSwarmTrafficLightLogic::carsIn
int carsIn
Definition: MSSwarmTrafficLightLogic.h:422
MSSOTLE2Sensors::getPassedVeh
int getPassedVeh(std::string laneId, bool out)
Definition: MSSOTLE2Sensors.cpp:207
StringUtils::toDouble
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: StringUtils.cpp:345
MSSOTLPolicy5DFamilyStimulus
Definition: MSSOTLPolicy5DFamilyStimulus.h:42
DBG
#define DBG(X)
Definition: SwarmDebug.h:26
MSPhasedTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSPhasedTrafficLightLogic.cpp:131
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:61
LaneIdVector
std::vector< std::string > LaneIdVector
Definition: MSSOTLDefinitions.h:76
MSSwarmTrafficLightLogic::targetLanes
LaneIdVector targetLanes
A copy of the target lanes of this phase.
Definition: MSSwarmTrafficLightLogic.h:410
MSSwarmTrafficLightLogic::~MSSwarmTrafficLightLogic
~MSSwarmTrafficLightLogic()
Definition: MSSwarmTrafficLightLogic.cpp:74
MSSwarmTrafficLightLogic::m_losMaxLimit
int m_losMaxLimit
Definition: MSSwarmTrafficLightLogic.h:443
MSLane::getPermissions
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:548
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSOTLE2Sensors::subtractPassedVeh
void subtractPassedVeh(std::string laneId, int passed)
Definition: MSSOTLE2Sensors.cpp:227
MSSwarmTrafficLightLogic::decideNextPhase
int decideNextPhase()
Definition: MSSwarmTrafficLightLogic.cpp:215
SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:179
MSSwarmTrafficLightLogic::init
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
Definition: MSSwarmTrafficLightLogic.cpp:114
MSSOTLPolicyDesirability::getMessage
virtual std::string getMessage()=0
MSSwarmTrafficLightLogic::swarmLogFile
std::ofstream swarmLogFile
Definition: MSSwarmTrafficLightLogic.h:395
MSSOTLHiLevelTrafficLightLogic
A self-organizing high-level traffic light logic.
Definition: MSSOTLHiLevelTrafficLightLogic.h:44
MSSwarmTrafficLightLogic::allowLine
bool allowLine(MSLane *)
Check if a lane is allowed to be added to the maps pheromoneInputLanes and pheromoneOutputLanes Contr...
Definition: MSSwarmTrafficLightLogic.cpp:90
MSSOTLSensors::countVehicles
virtual int countVehicles(MSLane *lane)=0
MSSOTLTrafficLightLogic::getSensors
MSSOTLSensors * getSensors()
Definition: MSSOTLTrafficLightLogic.h:175
MSSwarmTrafficLightLogic::getBetaSp
double getBetaSp()
Definition: MSSwarmTrafficLightLogic.h:144
MSSwarmTrafficLightLogic::laneCheck
LaneCheckMap laneCheck
Map to check if a lane was already controlled during the elaboration of eta.
Definition: MSSwarmTrafficLightLogic.h:406
MSSwarmTrafficLightLogic::m_pheroLevelLog
std::map< std::string, std::string > m_pheroLevelLog
Definition: MSSwarmTrafficLightLogic.h:436
MSSwarmTrafficLightLogic::mustChange
bool mustChange
When true, indicates that the current policy MUST be changed. It's used to force the exit from the co...
Definition: MSSwarmTrafficLightLogic.h:400
MSSOTLTrafficLightLogic::isPushButtonPressed
bool isPushButtonPressed()
Definition: MSSOTLTrafficLightLogic.cpp:506
MSSwarmTrafficLightLogic::getLearningCox
double getLearningCox()
Definition: MSSwarmTrafficLightLogic.h:168
Parameterised::getParameter
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Definition: Parameterised.cpp:72
MSSOTLSensors::meanVehiclesSpeed
virtual double meanVehiclesSpeed(MSLane *lane)=0
MSSwarmTrafficLightLogic::getGammaSp
double getGammaSp()
Definition: MSSwarmTrafficLightLogic.h:148
MSSwarmTrafficLightLogic::initScaleFactorDispersionIn
void initScaleFactorDispersionIn(int lanes_in)
Definition: MSSwarmTrafficLightLogic.h:332
MSSOTLPolicy::getDesirabilityAlgorithm
MSSOTLPolicyDesirability * getDesirabilityAlgorithm()
Definition: MSSOTLPolicy.h:120
MSSwarmTrafficLightLogic::getThetaMax
double getThetaMax()
Definition: MSSwarmTrafficLightLogic.h:156
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSSOTLCongestionPolicy
Class for low-level congestion policy.
Definition: MSSOTLCongestionPolicy.h:33
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
MSEdge::isCrossing
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:240
MSSwarmTrafficLightLogic::notTarget
int notTarget
Definition: MSSwarmTrafficLightLogic.h:425
MSSOTLPolicy::getName
std::string getName()
Definition: MSSOTLPolicy.h:117
MSSwarmTrafficLightLogic::getThetaMin
double getThetaMin()
Definition: MSSwarmTrafficLightLogic.h:160
MSSwarmTrafficLightLogic::m_laneIndexMap
std::map< std::string, std::vector< int > > m_laneIndexMap
Definition: MSSwarmTrafficLightLogic.h:433
MSSwarmTrafficLightLogic::getLaneLightState
std::string getLaneLightState(const std::string &laneId)
Definition: MSSwarmTrafficLightLogic.cpp:1145
MSSwarmTrafficLightLogic::resetLaneCheck
void resetLaneCheck()
Definition: MSSwarmTrafficLightLogic.cpp:1062
MSSwarmTrafficLightLogic::m_losCounter
int m_losCounter
Definition: MSSwarmTrafficLightLogic.h:442
MSLaneId_Pheromone
std::pair< std::string, double > MSLaneId_Pheromone
Definition: MSSOTLDefinitions.h:64
MSPhaseDefinition::getState
const std::string & getState() const
Returns the state within this phase.
Definition: MSPhaseDefinition.h:199
MSSwarmTrafficLightLogic::inTarget
int inTarget
Definition: MSSwarmTrafficLightLogic.h:424
MSNet::getCurrentTimeStep
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:283
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MSSwarmTrafficLightLogic::getThetaInit
double getThetaInit()
Definition: MSSwarmTrafficLightLogic.h:164
MSPhaseDefinition::isCommit
bool isCommit() const
Definition: MSPhaseDefinition.h:292
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSPhaseDefinition::getTargetLaneSet
const LaneIdVector & getTargetLaneSet() const
Definition: MSPhaseDefinition.h:207
MSSwarmTrafficLightLogic::getReinforcementMode
int getReinforcementMode()
Definition: MSSwarmTrafficLightLogic.h:328
MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS
int getPhaseIndexWithMaxCTS()
Definition: MSSOTLTrafficLightLogic.cpp:369
MSSwarmTrafficLightLogic::logData
bool logData
Definition: MSSwarmTrafficLightLogic.h:394
MSSwarmTrafficLightLogic::resetPheromone
void resetPheromone()
Resets pheromone levels.
Definition: MSSwarmTrafficLightLogic.cpp:200
MSSOTLHiLevelTrafficLightLogic::getCurrentPolicy
MSSOTLPolicy * getCurrentPolicy()
Returns the low-level policy currently selected by this high-level tll.
Definition: MSSOTLHiLevelTrafficLightLogic.h:90
MSPhasedTrafficLightLogic::getCurrentPhaseIndex
int getCurrentPhaseIndex() const
Returns the current index within the program.
Definition: MSPhasedTrafficLightLogic.cpp:125
MSSwarmTrafficLightLogic.h
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
MSEdge::isWalkingArea
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:254
MSSOTLSensors::getMaxSpeed
virtual double getMaxSpeed(std::string laneId)=0
MSSwarmTrafficLightLogic::getPoliciesParam
std::string getPoliciesParam()
Definition: MSSwarmTrafficLightLogic.h:318
MSSwarmTrafficLightLogic::getDispersionForOutputLanes
double getDispersionForOutputLanes(double average_phero_out)
Definition: MSSwarmTrafficLightLogic.cpp:548
MSSwarmTrafficLightLogic::pheromoneOutputLanes
MSLaneId_PheromoneMap pheromoneOutputLanes
This pheromone is an indicator of congestion on output lanes. Its levels refer to the average speed o...
Definition: MSSwarmTrafficLightLogic.h:207
MSTrafficLightLogic::getLinks
const LinkVectorVector & getLinks() const
Returns the list of lists of all affected links.
Definition: MSTrafficLightLogic.h:203
MSSwarmTrafficLightLogic::gotTargetLane
bool gotTargetLane
When true indicates that we've already acquired the target lanes for this particular phase.
Definition: MSSwarmTrafficLightLogic.h:420
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
MSSwarmTrafficLightLogic::m_useVehicleTypesWeights
bool m_useVehicleTypesWeights
Definition: MSSwarmTrafficLightLogic.h:444
MSSOTLPhasePolicy
Class for low-level phase policy.
Definition: MSSOTLPhasePolicy.h:33
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSSwarmTrafficLightLogic::pheromoneInputLanes
MSLaneId_PheromoneMap pheromoneInputLanes
This pheronome is an indicator of congestion on input lanes. Its levels refer to the average speed of...
Definition: MSSwarmTrafficLightLogic.h:199
MSSOTLE2Sensors
Definition: MSSOTLE2Sensors.h:32
MSSwarmTrafficLightLogic::MSSwarmTrafficLightLogic
MSSwarmTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor without sensors passed.
Definition: MSSwarmTrafficLightLogic.cpp:27
MSSwarmTrafficLightLogic::updatePheromoneLevels
void updatePheromoneLevels()
Update pheromone levels Pheromone on input lanes is costantly updated Pheromone follows a discrete-ti...
Definition: MSSwarmTrafficLightLogic.cpp:284
MSSOTLTrafficLightLogic::countVehicles
int countVehicles(MSPhaseDefinition phase)
Definition: MSSOTLTrafficLightLogic.cpp:264
MSSOTLPolicy::setThetaSensitivity
virtual void setThetaSensitivity(double val)
Definition: MSSOTLPolicy.h:114
MSLaneId_PheromoneMap
std::map< std::string, double > MSLaneId_PheromoneMap
Definition: MSSOTLDefinitions.h:69
MSSOTLHiLevelTrafficLightLogic::currentPolicy
MSSOTLPolicy * currentPolicy
Definition: MSSOTLHiLevelTrafficLightLogic.h:118
MSSwarmTrafficLightLogic::getDistanceOfMaxPheroForInputLanes
double getDistanceOfMaxPheroForInputLanes()
Definition: MSSwarmTrafficLightLogic.cpp:563
MSSOTLHiLevelTrafficLightLogic::getPolicies
std::vector< MSSOTLPolicy * > & getPolicies()
Returns the vector of the low-level policies used by this high-level tll.
Definition: MSSOTLHiLevelTrafficLightLogic.h:84
MSSOTLHiLevelTrafficLightLogic::addPolicy
void addPolicy(MSSOTLPolicy *policy)
Definition: MSSOTLHiLevelTrafficLightLogic.cpp:44
MSSwarmTrafficLightLogic::getMaxCongestionDuration
SUMOTime getMaxCongestionDuration()
Definition: MSSwarmTrafficLightLogic.h:128
MSSwarmTrafficLightLogic::updateSensitivities
void updateSensitivities()
Definition: MSSwarmTrafficLightLogic.cpp:412
MSSwarmTrafficLightLogic::getChangePlanProbability
double getChangePlanProbability()
Definition: MSSwarmTrafficLightLogic.h:152
MSSwarmTrafficLightLogic::getForgettingCox
double getForgettingCox()
Definition: MSSwarmTrafficLightLogic.h:172
MSSwarmTrafficLightLogic::congestion_steps
SUMOTime congestion_steps
Definition: MSSwarmTrafficLightLogic.h:401
MSSwarmTrafficLightLogic::m_derivativeAlpha
double m_derivativeAlpha
Definition: MSSwarmTrafficLightLogic.h:441
MSSwarmTrafficLightLogic::getDispersionForInputLanes
double getDispersionForInputLanes(double average_phero_in)
Definition: MSSwarmTrafficLightLogic.cpp:531
MSSwarmTrafficLightLogic::calculatePhi
double calculatePhi(int factor)
Method that should calculate the valor of phi a coefficient to amplify/attenuate eta based on a facto...
Definition: MSSwarmTrafficLightLogic.cpp:668
MSSOTLPolicy::canRelease
virtual bool canRelease(SUMOTime elapsed, bool thresholdPassed, bool pushButtonPressed, const MSPhaseDefinition *stage, int vehicleCount)=0
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
MSSOTLPlatoonPolicy
Class for low-level platoon policy.
Definition: MSSOTLPlatoonPolicy.h:35
MSSwarmTrafficLightLogic::lastThetaSensitivityUpdate
SUMOTime lastThetaSensitivityUpdate
Definition: MSSwarmTrafficLightLogic.h:214
MSPhaseDefinition::isTarget
bool isTarget() const
Definition: MSPhaseDefinition.h:271
MSSwarmTrafficLightLogic::getPheromoneForInputLanes
double getPheromoneForInputLanes()
Definition: MSSwarmTrafficLightLogic.cpp:497
MSSOTLHiLevelTrafficLightLogic::init
void init(NLDetectorBuilder &nb)
Initialises the tls.
Definition: MSSOTLHiLevelTrafficLightLogic.cpp:48
MSSwarmTrafficLightLogic::canRelease
bool canRelease()
Definition: MSSwarmTrafficLightLogic.cpp:1138
MSSwarmTrafficLightLogic::getPheroMaxVal
double getPheroMaxVal()
Definition: MSSwarmTrafficLightLogic.h:132
MSSwarmTrafficLightLogic::choosePolicy
void choosePolicy(double phero_in, double phero_out, double dispersion_in, double dispersion_out)
Definition: MSSwarmTrafficLightLogic.cpp:1087
ANALYSIS_DBG
#define ANALYSIS_DBG(X)
Definition: MSSwarmTrafficLightLogic.cpp:22
MSTrafficLightLogic::LinkVectorVector
std::vector< LinkVector > LinkVectorVector
Definition of a list that holds lists of links that do have the same attribute.
Definition: MSTrafficLightLogic.h:67
MSSwarmTrafficLightLogic::calculateEtaDiff
double calculateEtaDiff()
Method that should calculate the valor of eta a coefficient to evaluate the current policy's work....
Definition: MSSwarmTrafficLightLogic.cpp:679
MSSOTLPolicyDesirability
This class determines the desirability algorithm of a MSSOTLPolicy when used in combination with a hi...
Definition: MSSOTLPolicyDesirability.h:35
MSSwarmTrafficLightLogic::getDistanceOfMaxPheroForOutputLanes
double getDistanceOfMaxPheroForOutputLanes()
Definition: MSSwarmTrafficLightLogic.cpp:598
MSSwarmTrafficLightLogic::decidePolicy
void decidePolicy()
Decide the current policy according to pheromone levels The decision reflects on currentPolicy value.
Definition: MSSwarmTrafficLightLogic.cpp:632
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
MSTrafficLightLogic::LinkVector
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
Definition: MSTrafficLightLogic.h:64
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
MSSwarmTrafficLightLogic::getPheromoneForOutputLanes
double getPheromoneForOutputLanes()
Definition: MSSwarmTrafficLightLogic.cpp:515
NLDetectorBuilder
Builds detectors for microsim.
Definition: NLDetectorBuilder.h:55
MSSOTLTrafficLightLogic::getCurrentPhaseElapsed
SUMOTime getCurrentPhaseElapsed()
Definition: MSSOTLTrafficLightLogic.cpp:358
MSSwarmTrafficLightLogic::getScaleFactorDispersionOut
double getScaleFactorDispersionOut()
Definition: MSSwarmTrafficLightLogic.h:180
MSSwarmTrafficLightLogic::m_meanSpeedHistory
std::map< std::string, CircularBuffer< double > * > m_meanSpeedHistory
Definition: MSSwarmTrafficLightLogic.h:439
MSSOTLHiLevelTrafficLightLogic::activate
void activate(MSSOTLPolicy *policy)
Definition: MSSOTLHiLevelTrafficLightLogic.cpp:52
MSSwarmTrafficLightLogic::m_derivativeHistory
std::map< std::string, CircularBuffer< double > * > m_derivativeHistory
Definition: MSSwarmTrafficLightLogic.h:440
MsgHandler::getMessageInstance
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:55
MSSOTLHiLevelTrafficLightLogic::policies
std::vector< MSSOTLPolicy * > policies
Definition: MSSOTLHiLevelTrafficLightLogic.h:117