29 #define INVALID_POSITION std::numeric_limits<double>::max()
50 MSLane* currentLane =
nullptr;
53 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
54 controlledLanes.begin(); laneVector != controlledLanes.end();
56 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
57 laneVector->begin(); lane != laneVector->end(); lane++) {
58 currentLane = (*lane);
71 MSLane* currentLane =
nullptr;
73 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
74 controlledLanes.begin(); laneVector != controlledLanes.end();
76 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
77 laneVector->begin(); lane != laneVector->end(); lane++) {
78 currentLane = (*lane);
88 MSLane* currentLane =
nullptr;
91 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
92 controlledLanes.begin(); laneVector != controlledLanes.end();
94 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
95 laneVector->begin(); lane != laneVector->end(); lane++) {
96 currentLane = (*lane);
111 MSLane* currentLane =
nullptr;
114 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
115 controlledLanes.begin(); laneVector != controlledLanes.end();
117 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
118 laneVector->begin(); lane != laneVector->end(); lane++) {
119 currentLane = (*lane);
139 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
156 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
177 sensorPos = (lane->
getLength() - sensorLength)
178 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
182 sensorLength <= (lane->
getLength() - sensorPos) ?
183 sensorLength : (lane->
getLength() - sensorPos);
200 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
212 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
226 return sensorsIterator->second->getPassedVeh() + additional;
233 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
237 sensorsIterator->second->subtractPassedVeh(passed);
263 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
279 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
287 if (lensorLength < sensorLength * 0.9) {
288 std::ostringstream oss;
289 oss <<
"Sensor on lane " << lane->getID() <<
" is long " << lensorLength <<
", while it should be " << sensorLength <<
". Continuing it on the other lanes if possible";
292 const MSEdge& inEdge = it.lane->getEdge();
302 double availableLength = sensorLength - usedLength;
304 double length = availableLength <= continueOnLane->
getLength() ? availableLength : continueOnLane->
getLength();
313 std::ostringstream oss;
314 oss <<
"Continue sensor on lane " << continueOnLane->
getID() <<
". Current length " << (length + usedLength);
317 if (length + usedLength < sensorLength * 0.9) {
318 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = continueOnLane->
getIncomingLanes().begin(); it != continueOnLane->
getIncomingLanes().end(); ++it) {
319 const MSEdge* edge = &it->lane->getEdge();
344 sensorPos = (lane->
getLength() - sensorLength)
345 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
349 sensorLength <= (lane->
getLength() - sensorPos) ?
350 sensorLength : (lane->
getLength() - sensorPos);
367 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
387 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
392 double estQL = sensorsIterator->second->getEstimateQueueLength();
413 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
425 return sensorsIterator->second->getEstimatedCurrentVehicleNumber(
speedThresholdParam) + additional;
429 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
442 return count(sensorsIterator->second) + additional;
446 MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn =
m_maxSpeedMap.find(laneId);
449 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
452 return sensorsIteratorIn->second;
460 MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut =
m_sensorMap.find(laneId);
463 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
466 double meanSpeedAcc = 0;
467 int totalCarNumer = 0;
475 totalCarNumer += number;
477 meanSpeedAcc += mean * (double) number;
479 int number = sensorsIteratorOut->second->getCurrentVehicleNumber();
480 totalCarNumer += number;
481 double mean = sensorsIteratorOut->second->getCurrentMeanSpeed();
482 meanSpeedAcc += mean * (double) number;
483 return totalCarNumer == 0 ? -1 : meanSpeedAcc / (double) totalCarNumer;
486 std::string
trim(std::string& str) {
487 int first = (int)str.find_first_not_of(
' ');
488 int last = (int)str.find_last_not_of(
' ');
489 return str.substr(first, (last - first + 1));
492 std::vector<std::string>&
split(
const std::string& s,
char delim, std::vector<std::string>& elems) {
493 std::stringstream ss(s);
495 while (std::getline(ss, item, delim)) {
497 elems.push_back(item);
504 std::vector<std::string> types;
505 split(weightString,
';', types);
506 std::ostringstream logstr;
507 logstr <<
"[MSSOTLE2Sensors::setVehicleWeigths] ";
508 for (std::vector<std::string>::iterator typesIt = types.begin(); typesIt != types.end(); ++typesIt) {
509 std::vector<std::string> typeWeight;
510 split(*typesIt,
'=', typeWeight);
511 if (typeWeight.size() == 2) {
512 std::string type =
trim(typeWeight[0]);
514 logstr << type <<
"=" << value <<
" ";
527 const std::vector<MSE2Collector::VehicleInfo*> vehicles = sensor->
getCurrentVehicles();
528 std::ostringstream logstr;
529 logstr <<
"[MSSOTLE2Sensors::count]";
530 for (std::vector<MSE2Collector::VehicleInfo*>::const_iterator vit = vehicles.begin(); vit != vehicles.end(); ++vit) {
531 if ((*vit)->onDetector) {
532 const std::string vtype = (*vit)->type;
#define INPUT_SENSOR_LENGTH
#define COUNT_SENSOR_START
#define OUTPUT_COUNT_SENSOR_LENGTH
#define INPUT_COUNT_SENSOR_LENGTH
#define HALTING_SPEED_THRS
#define SENSOR_START
For MSSOTLSensors.
#define OUTPUT_SENSOR_LENGTH
std::pair< std::string, MSE2Collector * > MSLaneID_MSE2Collector
#define HALTING_TIME_THRS
std::pair< std::string, double > MSLaneID_MaxSpeed
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
std::string trim(std::string &str)
#define WRITE_MESSAGE(msg)
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime interval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
An areal detector corresponding to a sequence of consecutive lanes.
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
int getPassedVeh()
Returns the number of vehicles passed over the sensor (i.e. entered the sensor)
A road/street connecting two junctions.
bool isCrossing() const
return whether this edge is a pedestrian crossing
bool isWalkingArea() const
return whether this edge is walking area
bool isInternal() const
return whether this edge is an internal edge
Representation of a lane in the micro simulation.
double getLength() const
Returns the lane's length.
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
MSEdge & getEdge() const
Returns the lane's edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSDetectorControl & getDetectorControl()
Returns the detector control.
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 ...
void buildSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific input lane Sensors ...
MSSOTLE2Sensors(std::string tlLogicID, const MSTrafficLightLogic::Phases *phases)
void buildCountOutSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
int estimateVehicles(std::string laneId)
virtual double meanVehiclesSpeed(MSLane *lane)
std::map< const std::string, int > m_typeWeightMap
int count(MSE2Collector *sensor)
void buildCountSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
MSLaneID_MaxSpeedMap m_maxSpeedMap
void subtractPassedVeh(std::string laneId, int passed)
int countVehicles(MSLane *lane)
double speedThresholdParam
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...
void buildSensorForOutLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific output lane Sensors...
MSLaneID_MSE2CollectorMap m_sensorMap
virtual void setVehicleWeigths(const std::string &weightString)
virtual double getMaxSpeed(std::string laneId)
void buildCountSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
int getPassedVeh(std::string laneId, bool out)
double getEstimateQueueLength(std::string laneId)
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
bool getVelueFromSensor(std::string laneId, Method function, ValueType &value)
void buildContinueSensior(MSLane *lane, NLDetectorBuilder &nb, double sensorLength, MSLane *continueOnLane, double usedLength)
std::map< std::string, std::vector< std::string > > m_continueSensorOnLanes
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes that do have the same attribute.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Builds detectors for microsim.
virtual MSE2Collector * createE2Detector(const std::string &id, DetectorUsage usage, MSLane *lane, double pos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons, bool showDetector)
Creates a MSE2Collector instance, overridden by GUIE2Collector::createE2Detector()
const std::string & getID() const
Returns the id.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...