26 #define INVALID_POSITION std::numeric_limits<double>::max() 47 MSLane* currentLane =
nullptr;
50 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
51 controlledLanes.begin(); laneVector != controlledLanes.end();
53 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
54 laneVector->begin(); lane != laneVector->end(); lane++) {
55 currentLane = (*lane);
68 MSLane* currentLane =
nullptr;
70 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
71 controlledLanes.begin(); laneVector != controlledLanes.end();
73 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
74 laneVector->begin(); lane != laneVector->end(); lane++) {
75 currentLane = (*lane);
85 MSLane* currentLane =
nullptr;
88 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
89 controlledLanes.begin(); laneVector != controlledLanes.end();
91 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
92 laneVector->begin(); lane != laneVector->end(); lane++) {
93 currentLane = (*lane);
108 MSLane* currentLane =
nullptr;
111 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
112 controlledLanes.begin(); laneVector != controlledLanes.end();
114 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
115 laneVector->begin(); lane != laneVector->end(); lane++) {
116 currentLane = (*lane);
136 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
153 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
174 sensorPos = (lane->
getLength() - sensorLength)
175 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
179 sensorLength <= (lane->
getLength() - sensorPos) ?
180 sensorLength : (lane->
getLength() - sensorPos);
197 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
209 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
223 return sensorsIterator->second->getPassedVeh() + additional;
230 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
234 sensorsIterator->second->subtractPassedVeh(passed);
260 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
276 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
284 if (lensorLength < sensorLength * 0.9) {
285 std::ostringstream oss;
286 oss <<
"Sensor on lane " << lane->getID() <<
" is long " << lensorLength <<
", while it should be " << sensorLength <<
". Continuing it on the other lanes if possible";
288 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = lane->getIncomingLanes().begin(); it != lane->getIncomingLanes().end(); ++it) {
289 const MSEdge* edge = &it->lane->getEdge();
299 double availableLength = sensorLength - usedLength;
301 double length = availableLength <= continueOnLane->
getLength() ? availableLength : continueOnLane->
getLength();
310 std::ostringstream oss;
311 oss <<
"Continue sensor on lane " << continueOnLane->getID() <<
". Current length " << (length + usedLength);
314 if (length + usedLength < sensorLength * 0.9) {
315 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = continueOnLane->getIncomingLanes().begin(); it != continueOnLane->getIncomingLanes().end(); ++it) {
316 const MSEdge* edge = &it->lane->getEdge();
341 sensorPos = (lane->
getLength() - sensorLength)
342 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
346 sensorLength <= (lane->
getLength() - sensorPos) ?
347 sensorLength : (lane->
getLength() - sensorPos);
364 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
384 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
389 double estQL = sensorsIterator->second->getEstimateQueueLength();
410 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
422 return sensorsIterator->second->getEstimatedCurrentVehicleNumber(
speedThresholdParam) + additional;
426 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
439 return count(sensorsIterator->second) + additional;
443 MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn =
m_maxSpeedMap.find(laneId);
446 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
449 return sensorsIteratorIn->second;
457 MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut =
m_sensorMap.find(laneId);
460 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
463 double meanSpeedAcc = 0;
464 int totalCarNumer = 0;
472 totalCarNumer += number;
474 meanSpeedAcc += mean * (double) number;
476 int number = sensorsIteratorOut->second->getCurrentVehicleNumber();
477 totalCarNumer += number;
478 double mean = sensorsIteratorOut->second->getCurrentMeanSpeed();
479 meanSpeedAcc += mean * (double) number;
480 return totalCarNumer == 0 ? -1 : meanSpeedAcc / (double) totalCarNumer;
483 std::string
trim(std::string& str) {
484 int first = (int)str.find_first_not_of(
' ');
485 int last = (int)str.find_last_not_of(
' ');
486 return str.substr(first, (last - first + 1));
489 std::vector<std::string>&
split(
const std::string& s,
char delim, std::vector<std::string>& elems) {
490 std::stringstream ss(s);
492 while (std::getline(ss, item, delim)) {
494 elems.push_back(item);
501 std::vector<std::string> types;
502 split(weightString,
';', types);
503 std::ostringstream logstr;
504 logstr <<
"[MSSOTLE2Sensors::setVehicleWeigths] ";
505 for (std::vector<std::string>::iterator typesIt = types.begin(); typesIt != types.end(); ++typesIt) {
506 std::vector<std::string> typeWeight;
507 split(*typesIt,
'=', typeWeight);
508 if (typeWeight.size() == 2) {
509 std::string type =
trim(typeWeight[0]);
511 logstr << type <<
"=" << value <<
" ";
524 const std::vector<MSE2Collector::VehicleInfo*> vehicles = sensor->
getCurrentVehicles();
525 std::ostringstream logstr;
526 logstr <<
"[MSSOTLE2Sensors::count]";
527 for (std::vector<MSE2Collector::VehicleInfo*>::const_iterator vit = vehicles.begin(); vit != vehicles.end(); ++vit) {
528 if ((*vit)->onDetector) {
529 const std::string vtype = (*vit)->type;
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)
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 detector corresponding to a sequence of consecutive lanes.
std::map< const std::string, int > m_typeWeightMap
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
double getLength() const
Returns the lane's length.
MSLaneID_MSE2CollectorMap m_sensorMap
void buildContinueSensior(MSLane *lane, NLDetectorBuilder &nb, double sensorLength, MSLane *continueOnLane, double usedLength)
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
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
virtual double meanVehiclesSpeed(MSLane *lane)
#define INPUT_SENSOR_LENGTH
A road/street connecting two junctions.
std::map< std::string, std::vector< std::string > > m_continueSensorOnLanes
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
int estimateVehicles(std::string laneId)
void buildCountSensors(MSTrafficLightLogic::LaneVectorVector controlledLanes, NLDetectorBuilder &nb)
int getPassedVeh(std::string laneId, bool out)
std::string trim(std::string &str)
virtual double getMaxSpeed(std::string laneId)
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::pair< std::string, double > MSLaneID_MaxSpeed
std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
#define INPUT_COUNT_SENSOR_LENGTH
double getEstimateQueueLength(std::string laneId)
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.
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
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.
void buildSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
This function member has to be extended to properly build a sensor for a specific input lane Sensors ...
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 &vTypes, bool showDetector=true)
Creates a MSE2Collector instance, overridden by GUIE2Collector::createE2Detector() ...
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.
double speedThresholdParam
std::vector< LaneVector > LaneVectorVector
Definition of a list that holds lists of lanes 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 (i.e. entered the sensor)
void buildCountSensorForLane(MSLane *lane, NLDetectorBuilder &nb)
bool isWalkingArea() const
return whether this edge is walking area
#define OUTPUT_SENSOR_LENGTH
void subtractPassedVeh(std::string laneId, int passed)
#define OUTPUT_COUNT_SENSOR_LENGTH
#define HALTING_SPEED_THRS
#define WRITE_MESSAGE(msg)
Representation of a lane in the micro simulation.
int count(MSE2Collector *sensor)
alternative tag for e2 detector
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.