48 MSLane* currentLane = NULL;
51 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
52 controlledLanes.begin(); laneVector != controlledLanes.end();
54 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
55 laneVector->begin(); lane != laneVector->end(); lane++) {
56 currentLane = (*lane);
69 MSLane* currentLane = NULL;
71 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
72 controlledLanes.begin(); laneVector != controlledLanes.end();
74 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
75 laneVector->begin(); lane != laneVector->end(); lane++) {
76 currentLane = (*lane);
86 MSLane* currentLane = NULL;
89 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
90 controlledLanes.begin(); laneVector != controlledLanes.end();
92 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
93 laneVector->begin(); lane != laneVector->end(); lane++) {
94 currentLane = (*lane);
109 MSLane* currentLane = NULL;
112 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
113 controlledLanes.begin(); laneVector != controlledLanes.end();
115 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
116 laneVector->begin(); lane != laneVector->end(); lane++) {
117 currentLane = (*lane);
137 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
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
147 "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
154 (lane->getLength() - sensorPos - lensorLength), lensorLength,
176 sensorPos = (lane->
getLength() - sensorLength)
177 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
181 sensorLength <= (lane->
getLength() - sensorPos) ?
182 sensorLength : (lane->
getLength() - sensorPos);
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
192 "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
199 (lane->getLength() - sensorPos - lensorLength), lensorLength,
212 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
226 return sensorsIterator->second->getPassedVeh() + additional;
233 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
237 sensorsIterator->second->subtractPassedVeh(passed);
283 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
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
292 "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
299 (lane->getLength() - sensorPos - lensorLength), lensorLength,
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";
312 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = lane->getIncomingLanes().begin(); it != lane->getIncomingLanes().end(); ++it) {
313 const MSEdge* edge = &it->lane->getEdge();
323 SUMOReal availableLength = sensorLength - usedLength;
329 (continueOnLane->getLength() - length), length,
334 std::ostringstream oss;
335 oss <<
"Continue sensor on lane " << continueOnLane->getID() <<
". Current length " << (length + usedLength);
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();
365 sensorPos = (lane->
getLength() - sensorLength)
366 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
370 sensorLength <= (lane->
getLength() - sensorPos) ?
371 sensorLength : (lane->
getLength() - sensorPos);
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
381 "MSSOTLE2Sensors::buildSensorForLane::" + phero_str.str());
388 (lane->getLength() - sensorPos - lensorLength), lensorLength,
409 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
414 SUMOReal estQL = sensorsIterator->second->getEstimateQueueLength();
419 std::ostringstream str;
420 str <<
"MSSOTLE2Sensors::getEstimateQueueLength lane " << sensorsIterator->second->getLane()->getID()
421 <<
" laneLength " << sensorsIterator->second->getLane()->getLength() <<
" estimateQueueLength " << estQL;
433 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
445 return sensorsIterator->second->getEstimatedCurrentVehicleNumber(
speedThresholdParam) + additional;
449 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
462 return count(sensorsIterator->second) + additional;
466 MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn =
m_maxSpeedMap.find(laneId);
469 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
472 return sensorsIteratorIn->second;
480 MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut =
m_sensorMap.find(laneId);
483 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
487 int totalCarNumer = 0;
495 totalCarNumer += number;
497 meanSpeedAcc += mean * (
SUMOReal) number;
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;
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));
512 std::vector<std::string>&
split(
const std::string& s,
char delim, std::vector<std::string>& elems) {
513 std::stringstream ss(s);
515 while (std::getline(ss, item, delim)) {
517 elems.push_back(item);
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]);
534 logstr << type <<
"=" << value <<
" ";
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;
561 DBG(
if (totCars != number) {
562 logstr <<
". Real number " << totCars <<
"; weighted " << number;
SUMOReal getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
SUMOReal getLength() const
Returns the lane's length.
Builds detectors for microsim.
MSEdge & getEdge() const
Returns the lane's edge.
#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.
std::map< const std::string, int > m_typeWeightMap
SUMOReal speedThresholdParam
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSLaneID_MSE2CollectorMap m_sensorMap
MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases *phases)
const std::string & getID() const
Returns the id.
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
#define COUNT_SENSOR_START
#define INPUT_SENSOR_LENGTH
A road/street connecting two junctions.
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.
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...
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
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.
bool isCrossing() const
return whether this edge is a pedestrian crossing
bool isInternal() const
return whether this edge is an internal edge
MSDetectorControl & getDetectorControl()
Returns the detector control.
const std::vector< VehicleInfo > & getCurrentVehicles() const
Returns the vehicles within the area.
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.
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
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)
bool isWalkingArea() const
return whether this edge is walking area
void buildContinueSensior(MSLane *lane, NLDetectorBuilder &nb, SUMOReal sensorLength, MSLane *continueOnLane, SUMOReal usedLength)
#define OUTPUT_SENSOR_LENGTH
void subtractPassedVeh(std::string laneId, int passed)
#define OUTPUT_COUNT_SENSOR_LENGTH
#define HALTING_SPEED_THRS
virtual SUMOReal meanVehiclesSpeed(MSLane *lane)
#define WRITE_MESSAGE(msg)
Representation of a lane in the micro simulation.
std::pair< std::string, SUMOReal > MSLaneID_MaxSpeed
int count(MSE2Collector *sensor)
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.