29 #define INVALID_POSITION std::numeric_limits<double>::max() 50 MSLane* currentLane = NULL;
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 = NULL;
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 = NULL;
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 = NULL;
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";
291 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = lane->getIncomingLanes().begin(); it != lane->getIncomingLanes().end(); ++it) {
292 const MSEdge* edge = &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;
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.
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
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 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.