28 #define INVALID_POSITION std::numeric_limits<double>::max() 49 MSLane* currentLane = NULL;
52 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
53 controlledLanes.begin(); laneVector != controlledLanes.end();
55 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
56 laneVector->begin(); lane != laneVector->end(); lane++) {
57 currentLane = (*lane);
70 MSLane* currentLane = NULL;
72 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
73 controlledLanes.begin(); laneVector != controlledLanes.end();
75 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
76 laneVector->begin(); lane != laneVector->end(); lane++) {
77 currentLane = (*lane);
87 MSLane* currentLane = NULL;
90 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
91 controlledLanes.begin(); laneVector != controlledLanes.end();
93 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
94 laneVector->begin(); lane != laneVector->end(); lane++) {
95 currentLane = (*lane);
110 MSLane* currentLane = NULL;
113 for (MSTrafficLightLogic::LaneVectorVector::const_iterator laneVector =
114 controlledLanes.begin(); laneVector != controlledLanes.end();
116 for (MSTrafficLightLogic::LaneVector::const_iterator lane =
117 laneVector->begin(); lane != laneVector->end(); lane++) {
118 currentLane = (*lane);
138 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
155 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
176 sensorPos = (lane->
getLength() - sensorLength)
177 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
181 sensorLength <= (lane->
getLength() - sensorPos) ?
182 sensorLength : (lane->
getLength() - sensorPos);
199 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
211 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
225 return sensorsIterator->second->getPassedVeh() + additional;
232 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator;
236 sensorsIterator->second->subtractPassedVeh(passed);
262 lensorLength = sensorLength <= (lane->
getLength() - sensorPos) ? sensorLength : (lane->
getLength() - sensorPos);
278 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
286 if (lensorLength < sensorLength * 0.9) {
287 std::ostringstream oss;
288 oss <<
"Sensor on lane " << lane->getID() <<
" is long " << lensorLength <<
", while it should be " << sensorLength <<
". Continuing it on the other lanes if possible";
290 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = lane->getIncomingLanes().begin(); it != lane->getIncomingLanes().end(); ++it) {
291 const MSEdge* edge = &it->lane->getEdge();
301 double availableLength = sensorLength - usedLength;
303 double length = availableLength <= continueOnLane->
getLength() ? availableLength : continueOnLane->
getLength();
312 std::ostringstream oss;
313 oss <<
"Continue sensor on lane " << continueOnLane->getID() <<
". Current length " << (length + usedLength);
316 if (length + usedLength < sensorLength * 0.9) {
317 for (std::vector<MSLane::IncomingLaneInfo>::const_iterator it = continueOnLane->getIncomingLanes().begin(); it != continueOnLane->getIncomingLanes().end(); ++it) {
318 const MSEdge* edge = &it->lane->getEdge();
343 sensorPos = (lane->
getLength() - sensorLength)
344 - (SENSOR_START <= lane->getLength() ?
SENSOR_START : 0);
348 sensorLength <= (lane->
getLength() - sensorPos) ?
349 sensorLength : (lane->
getLength() - sensorPos);
366 (lane->getLength() - sensorPos - lensorLength),
INVALID_POSITION, lensorLength,
386 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
391 double estQL = sensorsIterator->second->getEstimateQueueLength();
412 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
424 return sensorsIterator->second->getEstimatedCurrentVehicleNumber(
speedThresholdParam) + additional;
428 MSLaneID_MSE2CollectorMap::const_iterator sensorsIterator =
m_sensorMap.find(laneId);
441 return count(sensorsIterator->second) + additional;
445 MSLaneID_MaxSpeedMap::const_iterator sensorsIteratorIn =
m_maxSpeedMap.find(laneId);
448 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
451 return sensorsIteratorIn->second;
459 MSLaneID_MSE2CollectorMap::const_iterator sensorsIteratorOut =
m_sensorMap.find(laneId);
462 WRITE_ERROR(
"MSSOTLE2Sensors::meanVehiclesSpeed:: No lane found " + laneId);
465 double meanSpeedAcc = 0;
466 int totalCarNumer = 0;
474 totalCarNumer += number;
476 meanSpeedAcc += mean * (double) number;
478 int number = sensorsIteratorOut->second->getCurrentVehicleNumber();
479 totalCarNumer += number;
480 double mean = sensorsIteratorOut->second->getCurrentMeanSpeed();
481 meanSpeedAcc += mean * (double) number;
482 return totalCarNumer == 0 ? -1 : meanSpeedAcc / (double) totalCarNumer;
485 std::string
trim(std::string& str) {
486 int first = (int)str.find_first_not_of(
' ');
487 int last = (int)str.find_last_not_of(
' ');
488 return str.substr(first, (last - first + 1));
491 std::vector<std::string>&
split(
const std::string& s,
char delim, std::vector<std::string>& elems) {
492 std::stringstream ss(s);
494 while (std::getline(ss, item, delim)) {
496 elems.push_back(item);
503 std::vector<std::string> types;
504 split(weightString,
';', types);
505 std::ostringstream logstr;
506 logstr <<
"[MSSOTLE2Sensors::setVehicleWeigths] ";
507 for (std::vector<std::string>::iterator typesIt = types.begin(); typesIt != types.end(); ++typesIt) {
508 std::vector<std::string> typeWeight;
509 split(*typesIt,
'=', typeWeight);
510 if (typeWeight.size() == 2) {
511 std::string type =
trim(typeWeight[0]);
513 logstr << type <<
"=" << value <<
" ";
526 const std::vector<MSE2Collector::VehicleInfo*> vehicles = sensor->
getCurrentVehicles();
527 std::ostringstream logstr;
528 logstr <<
"[MSSOTLE2Sensors::count]";
529 for (std::vector<MSE2Collector::VehicleInfo*>::const_iterator vit = vehicles.begin(); vit != vehicles.end(); ++vit) {
530 if ((*vit)->onDetector) {
531 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.