SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSSOTLE2Sensors.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The class for SOTL sensors of "E2" type
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright 2001-2009 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
25 #include <microsim/MSEdge.h>
26 #include <microsim/MSVehicleType.h>
27 #include "MSSOTLE2Sensors.h"
28 
29 MSSOTLE2Sensors::MSSOTLE2Sensors(std::string tlLogicID,
30  const MSTrafficLightLogic::Phases* phases) :
31  MSSOTLSensors(tlLogicID, phases) {
32 }
33 
35  //Deleting sensors takes place in the detector control
36 }
37 
40  NLDetectorBuilder& nb) {
41  buildSensors(controlledLanes, nb, INPUT_SENSOR_LENGTH);
42 }
43 
46  NLDetectorBuilder& nb, SUMOReal sensorLength) {
47  //for each lane build an appropriate sensor on it
48  MSLane* currentLane = NULL;
49 
50  //input and ouput lanes
51  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
52  controlledLanes.begin(); laneVector != controlledLanes.end();
53  laneVector++) {
54  for (MSTrafficLightLogic::LaneVector::const_iterator lane =
55  laneVector->begin(); lane != laneVector->end(); lane++) {
56  currentLane = (*lane);
57  buildSensorForLane(currentLane, nb, sensorLength);
58  }
59  }
60 }
61 /****************************************************************************/
62 /*
63  * Count Sensors. Should be refactor to make a new class.
64  */
67  NLDetectorBuilder& nb) {
68  //for each lane build an appropriate sensor on it
69  MSLane* currentLane = NULL;
70  //input and ouput lanes
71  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
72  controlledLanes.begin(); laneVector != controlledLanes.end();
73  laneVector++) {
74  for (MSTrafficLightLogic::LaneVector::const_iterator lane =
75  laneVector->begin(); lane != laneVector->end(); lane++) {
76  currentLane = (*lane);
77  buildCountSensorForLane(currentLane, nb);
78  }
79  }
80 }
81 
84  NLDetectorBuilder& nb) {
85  //for each lane build an appropriate sensor on it
86  MSLane* currentLane = NULL;
87 
88  //input and ouput lanes
89  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
90  controlledLanes.begin(); laneVector != controlledLanes.end();
91  laneVector++) {
92  for (MSTrafficLightLogic::LaneVector::const_iterator lane =
93  laneVector->begin(); lane != laneVector->end(); lane++) {
94  currentLane = (*lane);
95  buildCountSensorForOutLane(currentLane, nb);
96  }
97  }
98 }
99 
102  NLDetectorBuilder& nb) {
103  buildOutSensors(controlledLanes, nb, OUTPUT_SENSOR_LENGTH);
104 }
107  NLDetectorBuilder& nb, SUMOReal sensorLength) {
108  //for each lane build an appropriate sensor on it
109  MSLane* currentLane = NULL;
110 
111  //input and ouput lanes
112  for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
113  controlledLanes.begin(); laneVector != controlledLanes.end();
114  laneVector++) {
115  for (MSTrafficLightLogic::LaneVector::const_iterator lane =
116  laneVector->begin(); lane != laneVector->end(); lane++) {
117  currentLane = (*lane);
118  buildSensorForOutLane(currentLane, nb, sensorLength);
119  }
120  }
121 }
122 
124  SUMOReal sensorPos;
125  SUMOReal lensorLength;
126  MSE2Collector* newSensor = NULL;
127  //Check not to have more than a sensor for lane
128  if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
129 
130  //Check and set zero if the lane is not long enough for the specified sensor start
131  sensorPos = COUNT_SENSOR_START <= lane->getLength() ? COUNT_SENSOR_START : 0;
132 
133  //Original:
134  SUMOReal sensorLength = INPUT_COUNT_SENSOR_LENGTH;
135 
136  //Check and trim if the lane is not long enough for the specified sensor length
137  lensorLength = sensorLength <= (lane->getLength() - sensorPos) ? sensorLength : (lane->getLength() - sensorPos);
138 
139  //TODO check this lengths
140  DBG(
141  std::ostringstream phero_str;
142  phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
143  << " ,SENSOR_START " << SENSOR_START << "; lane->getLength = "
144  << lane->getLength() << " ,lensorLength= " << lensorLength
145  << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
147  "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
148  )
149 
150  //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
151  newSensor = nb.buildSingleLaneE2Det(
152  "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
153  DU_TL_CONTROL, lane,
154  (lane->getLength() - sensorPos - lensorLength), lensorLength,
156  //newSensor = nb.buildSingleLaneE2Det("SOTL_E2_lane:"+lane->getID()+"_tl:"+tlLogicID, DU_TL_CONTROL, lane, (lane->getLength() - sensorPos- 5), lensorLength, HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS);
157 
159  SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
160 
161  m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
162  m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
163  }
164 }
165 
167  SUMOReal sensorPos;
168  SUMOReal lensorLength;
169  MSE2Collector* newSensor = NULL;
170  //Check not to have more than a sensor for lane
171  if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
172 
173  //Original:
174  SUMOReal sensorLength = OUTPUT_COUNT_SENSOR_LENGTH;
175  //Check and set zero if the lane is not long enough for the specified sensor start
176  sensorPos = (lane->getLength() - sensorLength)
177  - (SENSOR_START <= lane->getLength() ? SENSOR_START : 0);
178 
179  //Check and trim if the lane is not long enough for the specified sensor lenght
180  lensorLength =
181  sensorLength <= (lane->getLength() - sensorPos) ?
182  sensorLength : (lane->getLength() - sensorPos);
183 
184  //TODO check this lengths
185  DBG(
186  std::ostringstream phero_str;
187  phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
188  << " ,SENSOR_START " << SENSOR_START << "; lane->getLength = "
189  << lane->getLength() << " ,lensorLength= " << lensorLength
190  << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
192  "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
193  )
194 
195  //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
196  newSensor = nb.buildSingleLaneE2Det(
197  "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
198  DU_TL_CONTROL, lane,
199  (lane->getLength() - sensorPos - lensorLength), lensorLength,
201  //newSensor = nb.buildSingleLaneE2Det("SOTL_E2_lane:"+lane->getID()+"_tl:"+tlLogicID, DU_TL_CONTROL, lane, (lane->getLength() - sensorPos- 5), lensorLength, HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS);
202 
204  SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
205 
206  m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
207  m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
208  }
209 }
210 
211 int MSSOTLE2Sensors::getPassedVeh(std::string laneId, bool /* out */) {
212  MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
213  sensorsIterator = m_sensorMap.find(laneId);
214  if (sensorsIterator == m_sensorMap.end()) {
215  assert(0);
216  return 0;
217  } else {
218  int additional = 0;
219  if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
220  for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
221  int tmp = 0;
223  additional += tmp;
224  }
225  }
226  return sensorsIterator->second->getPassedVeh() + additional;
227  }
228 }
229 
230 void
231 MSSOTLE2Sensors::subtractPassedVeh(std::string laneId, int passed) {
232  //TODO Ivan: ciclare tutti i sensori di count e resettare passedVeh
233  MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
234 
235  sensorsIterator = m_sensorMap.find(laneId);
236  if (sensorsIterator != m_sensorMap.end()) {
237  sensorsIterator->second->subtractPassedVeh(passed);
238  }
239 }
240 
241 /*******************************************************************************/
242 /* @brief Builds an e2 detector that lies on only one lane
243  *
244  * @param[in] id The id the detector shall have
245  * @param[in] usage Information how the detector is used within the simulation
246  * @param[in] lane The lane the detector is placed at
247  * @param[in] pos The position on the lane the detector is placed at
248  * @param[in] length The length the detector has
249  * @param[in] haltingTimeThreshold Detector parameter: the time a vehicle's speed must be below haltingSpeedThreshold to be assigned as jammed
250  * @param[in] haltingSpeedThreshold Detector parameter: the speed a vehicle's speed must be below to be assigned as jammed
251  * @param[in] jamDistThreshold Detector parameter: the distance between two vehicles in order to not count them to one jam
252  * @todo Check whether this method is really needful
253  */
254 /*
255  Using
256  MSE2Collector* buildSingleLaneE2Det(const std::string& id,
257  DetectorUsage usage, MSLane* lane, SUMOReal pos, SUMOReal length,
258  SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold,
259  SUMOReal jamDistThreshold);
260 
261  */
262 
265 }
266 
267 
268 
270  const MSEdge* edge = &lane->getEdge();
271  if (edge->isInternal() || edge->isWalkingArea() || edge->isCrossing()) {
272  return;
273  }
274  SUMOReal sensorPos;
275  SUMOReal lensorLength;
276  MSE2Collector* newSensor = NULL;
277  //Check not to have more than a sensor for lane
278  if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
279 
280  //Check and set zero if the lane is not long enough for the specified sensor start
281  sensorPos = SENSOR_START <= lane->getLength() ? SENSOR_START : 0;
282  //Check and trim if the lane is not long enough for the specified sensor lenght
283  lensorLength = sensorLength <= (lane->getLength() - sensorPos) ? sensorLength : (lane->getLength() - sensorPos);
284  //TODO check this lengths
285  DBG(
286  std::ostringstream phero_str;
287  phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
288  << " ,SENSOR_START " << SENSOR_START << "; lane->getLength = "
289  << lane->getLength() << " ,lensorLength= " << lensorLength
290  << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
292  "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
293  )
294 
295  //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
296  newSensor = nb.buildSingleLaneE2Det(
297  "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
298  DU_TL_CONTROL, lane,
299  (lane->getLength() - sensorPos - lensorLength), lensorLength,
301 //newSensor = nb.buildSingleLaneE2Det("SOTL_E2_lane:"+lane->getID()+"_tl:"+tlLogicID, DU_TL_CONTROL, lane, (lane->getLength() - sensorPos- 5), lensorLength, HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS);
302 
304 
305  m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
306  m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
307  //Avoid creating really small sensors. Only add a further sensors if the one created is less than 90% the requested length
308  if (lensorLength < sensorLength * 0.9) {
309  std::ostringstream oss;
310  oss << "Sensor on lane " << lane->getID() << " is long " << lensorLength << ", while it should be " << sensorLength << ". Continuing it on the other lanes if possible";
311  WRITE_MESSAGE(oss.str())
312  for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = lane->getIncomingLanes().begin(); it != lane->getIncomingLanes().end(); ++it) {
313  const MSEdge* edge = &it->lane->getEdge();
314  if (!edge->isInternal() && !edge->isWalkingArea() && !edge->isCrossing()) {
315  buildContinueSensior(lane, nb, sensorLength, it->lane, lensorLength);
316  }
317  }
318  }
319  }
320 }
321 
322 void MSSOTLE2Sensors::buildContinueSensior(MSLane* lane, NLDetectorBuilder& nb, SUMOReal sensorLength, MSLane* continueOnLane, SUMOReal usedLength) {
323  SUMOReal availableLength = sensorLength - usedLength;
324  if (m_sensorMap.find(continueOnLane->getID()) == m_sensorMap.end()) {
325  SUMOReal length = availableLength <= continueOnLane->getLength() ? availableLength : continueOnLane->getLength();
326  MSE2Collector* newSensor = nb.buildSingleLaneE2Det(
327  "SOTL_E2_lane:" + continueOnLane->getID() + "_tl:" + tlLogicID,
328  DU_TL_CONTROL, continueOnLane,
329  (continueOnLane->getLength() - length), length,
332  m_sensorMap.insert(MSLaneID_MSE2Collector(continueOnLane->getID(), newSensor));
333  m_continueSensorOnLanes[lane->getID()].push_back(continueOnLane->getID());
334  std::ostringstream oss;
335  oss << "Continue sensor on lane " << continueOnLane->getID() << ". Current length " << (length + usedLength);
336  WRITE_MESSAGE(oss.str())
337  //Continue other line if needed.
338  if (length + usedLength < sensorLength * 0.9) {
339  for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = continueOnLane->getIncomingLanes().begin(); it != continueOnLane->getIncomingLanes().end(); ++it) {
340  const MSEdge* edge = &it->lane->getEdge();
341  if (!edge->isInternal() && !edge->isWalkingArea() && !edge->isCrossing()) {
342  buildContinueSensior(lane, nb, sensorLength, it->lane, length + usedLength);
343  }
344  }
345  }
346  }
347 }
348 
350  NLDetectorBuilder& nb) {
352 }
353 
355  NLDetectorBuilder& nb, SUMOReal sensorLength) {
356  SUMOReal sensorPos;
357  SUMOReal lensorLength;
358  MSE2Collector* newSensor = NULL;
359  //Check not to have more than a sensor for lane
360  if (m_sensorMap.find(lane->getID()) == m_sensorMap.end()) {
361 
362  //Original:
363  //SUMOReal sensorLength = OUTPUT_SENSOR_LENGTH;
364  //Check and set zero if the lane is not long enough for the specified sensor start
365  sensorPos = (lane->getLength() - sensorLength)
366  - (SENSOR_START <= lane->getLength() ? SENSOR_START : 0);
367 
368  //Check and trim if the lane is not long enough for the specified sensor lenght
369  lensorLength =
370  sensorLength <= (lane->getLength() - sensorPos) ?
371  sensorLength : (lane->getLength() - sensorPos);
372 
373  //TODO check this lengths
374  DBG(
375  std::ostringstream phero_str;
376  phero_str << " lane " << lane->getID() << " sensorPos= " << sensorPos
377  << " ,SENSOR_START " << SENSOR_START << "; lane->getLength = "
378  << lane->getLength() << " ,lensorLength= " << lensorLength
379  << " ,SENSOR_LENGTH= " << INPUT_SENSOR_LENGTH;
381  "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
382  )
383 
384  //Create sensor for lane and insert it into the map<MSLane*, MSE2Collector*>
385  newSensor = nb.buildSingleLaneE2Det(
386  "SOTL_E2_lane:" + lane->getID() + "_tl:" + tlLogicID,
387  DU_TL_CONTROL, lane,
388  (lane->getLength() - sensorPos - lensorLength), lensorLength,
390  //newSensor = nb.buildSingleLaneE2Det("SOTL_E2_lane:"+lane->getID()+"_tl:"+tlLogicID, DU_TL_CONTROL, lane, (lane->getLength() - sensorPos- 5), lensorLength, HALTING_TIME_THRS, HALTING_SPEED_THRS, DIST_THRS);
391 
393  SUMO_TAG_LANE_AREA_DETECTOR, newSensor);
394 
395  m_sensorMap.insert(MSLaneID_MSE2Collector(lane->getID(), newSensor));
396  m_maxSpeedMap.insert(MSLaneID_MaxSpeed(lane->getID(), lane->getSpeedLimit()));
397  }
398 }
399 
401  return countVehicles(lane->getID());
402 }
403 
404 /*
405  * Estimate queue lenght according to the distance of the last vehicles
406  */
407 
409  MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
410  if (sensorsIterator == m_sensorMap.end()) {
411  assert(0);
412  return 0;
413  } else {
414  SUMOReal estQL = sensorsIterator->second->getEstimateQueueLength();
415  if (estQL == -1) {
416  return 0;
417  } else
418  DBG(
419  std::ostringstream str;
420  str << "MSSOTLE2Sensors::getEstimateQueueLength lane " << sensorsIterator->second->getLane()->getID()
421  << " laneLength " << sensorsIterator->second->getLane()->getLength() << " estimateQueueLength " << estQL;
422  WRITE_MESSAGE(str.str());
423  )
424  return estQL;
425  }
426 }
427 
428 /*
429  * Estimate queue lenght according to the distance of the last vehicles that exceed a threshold
430  */
431 
432 int MSSOTLE2Sensors::estimateVehicles(std::string laneId) {
433  MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
434  if (sensorsIterator == m_sensorMap.end()) {
435  assert(0);
436  return 0;
437  }
438  int additional = 0;
439  if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
440  for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
441  if (m_sensorMap.find(*it) != m_sensorMap.end()) {
442  additional += m_sensorMap[*it]->getEstimatedCurrentVehicleNumber(speedThresholdParam);
443  }
444  }
445  return sensorsIterator->second->getEstimatedCurrentVehicleNumber(speedThresholdParam) + additional;
446 }
447 
448 int MSSOTLE2Sensors::countVehicles(std::string laneId) {
449  MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator = m_sensorMap.find(laneId);
450  if (sensorsIterator == m_sensorMap.end()) {
451  assert(0);
452  return 0;
453  }
454  int additional = 0;
455  if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end()) {
456  for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
457  if (m_sensorMap.find(*it) != m_sensorMap.end()) {
458  additional += count(m_sensorMap[*it]);
459  }
460  }
461  }
462  return count(sensorsIterator->second) + additional;
463 }
464 
466  MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn = m_maxSpeedMap.find(laneId);
467  if (sensorsIteratorIn == m_maxSpeedMap.end()) {
468  assert(0);
469  WRITE_ERROR("MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
470  return 0;
471  }
472  return sensorsIteratorIn->second;
473 }
474 
476  return meanVehiclesSpeed(lane->getID());
477 }
478 
480  MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut = m_sensorMap.find(laneId);
481  if (sensorsIteratorOut == m_sensorMap.end()) {
482  assert(0);
483  WRITE_ERROR("MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
484  return 0;
485  }
486  SUMOReal meanSpeedAcc = 0;
487  int totalCarNumer = 0;
488  if (m_continueSensorOnLanes.find(laneId) != m_continueSensorOnLanes.end())
489  for (std::vector<std::string>::iterator it = m_continueSensorOnLanes[laneId].begin(); it != m_continueSensorOnLanes[laneId].end(); ++ it) {
490  int number = 0;
491  SUMOReal mean = -1;
493  continue;
494  }
495  totalCarNumer += number;
497  meanSpeedAcc += mean * (SUMOReal) number;
498  }
499  int number = sensorsIteratorOut->second->getCurrentVehicleNumber();
500  totalCarNumer += number;
501  SUMOReal mean = sensorsIteratorOut->second->getCurrentMeanSpeed();
502  meanSpeedAcc += mean * (SUMOReal) number;
503  return totalCarNumer == 0 ? -1 : meanSpeedAcc / (SUMOReal) totalCarNumer;
504 }
505 
506 std::string trim(std::string& str) {
507  int first = (int)str.find_first_not_of(' ');
508  int last = (int)str.find_last_not_of(' ');
509  return str.substr(first, (last - first + 1));
510 }
511 
512 std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) {
513  std::stringstream ss(s);
514  std::string item;
515  while (std::getline(ss, item, delim)) {
516  if (!item.empty()) {
517  elems.push_back(item);
518  }
519  }
520  return elems;
521 }
522 
523 void MSSOTLE2Sensors::setVehicleWeigths(const std::string& weightString) {
524  std::vector<std::string> types;
525  split(weightString, ';', types);
526  std::ostringstream logstr;
527  logstr << "[MSSOTLE2Sensors::setVehicleWeigths] ";
528  for (std::vector<std::string>::iterator typesIt = types.begin(); typesIt != types.end(); ++typesIt) {
529  std::vector<std::string> typeWeight;
530  split(*typesIt, '=', typeWeight);
531  if (typeWeight.size() == 2) {
532  std::string type = trim(typeWeight[0]);
533  int value = TplConvert::_2int(typeWeight[1].c_str());
534  logstr << type << "=" << value << " ";
535  m_typeWeightMap[type] = value;
536  }
537  }
538  WRITE_MESSAGE(logstr.str());
539 }
540 
542  int totCars = sensor->getCurrentVehicleNumber();
543  if (m_typeWeightMap.size() == 0) {
544  return totCars;
545  }
546  int number = 0;
547  const std::vector<MSE2Collector::VehicleInfo> vehicles = sensor->getCurrentVehicles();
548  std::ostringstream logstr;
549  logstr << "[MSSOTLE2Sensors::count]";
550  for (std::vector<MSE2Collector::VehicleInfo>::const_iterator vit = vehicles.begin(); vit != vehicles.end(); ++vit) {
551  if (vit->stillOnDet) {
552  const std::string vtype = vit->type;
553  if (m_typeWeightMap.find(vtype) != m_typeWeightMap.end()) {
554  number += m_typeWeightMap[vtype];
555  DBG(logstr << " Added " << m_typeWeightMap[vtype] << " for vtype " << vtype;)
556  } else {
557  ++number;
558  }
559  }
560  }
561  DBG(if (totCars != number) {
562  logstr << ". Real number " << totCars << "; weighted " << number;
563  WRITE_MESSAGE(logstr.str());
564  })
565  return number;
566 }
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:571
Builds detectors for microsim.
#define SENSOR_START
For MSSOTLSensors.
void buildCountSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
int countVehicles(MSLane *lane)
SUMOReal getEstimateQueueLength(std::string laneId)
void buildOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
This function member has to be extended to properly build sensors for the output lanes Sensors has to...
An areal (along a single lane) detector.
Definition: MSE2Collector.h:83
std::map< const std::string, int > m_typeWeightMap
SUMOReal speedThresholdParam
SUMOReal getLength() const
Returns the lane's length.
Definition: MSLane.h:480
bool isWalkingArea() const
return whether this edge is walking area
Definition: MSEdge.h:264
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
MSLaneID_MSE2CollectorMap m_sensorMap
MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases *phases)
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
#define COUNT_SENSOR_START
#define INPUT_SENSOR_LENGTH
const std::string & getID() const
Returns the id.
Definition: Named.h:66
A road/street connecting two junctions.
Definition: MSEdge.h:80
std::map< std::string, std::vector< std::string > > m_continueSensorOnLanes
int estimateVehicles(std::string laneId)
MSE2Collector * buildSingleLaneE2Det(const std::string &id, DetectorUsage usage, MSLane *lane, SUMOReal pos, SUMOReal length, SUMOTime haltingTimeThreshold, SUMOReal haltingSpeedThreshold, SUMOReal jamDistThreshold, const std::string &vTypes)
Builds an e2 detector that lies on only one lane.
#define DIST_THRS
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
int getPassedVeh(std::string laneId, bool out)
std::string trim(std::string &str)
void buildSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific output lane Sensors...
SUMOReal getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
virtual SUMOReal getMaxSpeed(std::string laneId)
#define INPUT_COUNT_SENSOR_LENGTH
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
bool getVelueFromSensor(std::string laneId, Method function, ValueType &value)
MSLaneID_MaxSpeedMap m_maxSpeedMap
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime splInterval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
#define DBG(X)
Definition: SwarmDebug.h:30
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:370
bool isInternal() const
return whether this edge is an internal edge
Definition: MSEdge.h:254
void buildSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific input lane Sensors ...
std::pair< std::string, MSE2Collector * > MSLaneID_MSE2Collector
virtual void setVehicleWeigths(const std::string &weightString)
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of links that do have the same attribute.
#define HALTING_TIME_THRS
void buildSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
This function member has to be extended to properly build sensors for the input lanes Sensors has to ...
int getPassedVeh()
Returns the number of vehicles passed over the sensor.
void buildCountSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
void buildContinueSensior(MSLane *lane, NLDetectorBuilder &nb, SUMOReal sensorLength, MSLane *continueOnLane, SUMOReal usedLength)
#define SUMOReal
Definition: config.h:214
#define OUTPUT_SENSOR_LENGTH
bool isCrossing() const
return whether this edge is a pedestrian crossing
Definition: MSEdge.h:259
const std::vector< VehicleInfo > & getCurrentVehicles() const
Returns the vehicles within the area.
void subtractPassedVeh(std::string laneId, int passed)
#define OUTPUT_COUNT_SENSOR_LENGTH
std::string tlLogicID
Definition: MSSOTLSensors.h:43
#define HALTING_SPEED_THRS
virtual SUMOReal meanVehiclesSpeed(MSLane *lane)
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
std::pair< std::string, SUMOReal > MSLaneID_MaxSpeed
int count(MSE2Collector *sensor)