65 SUMOTime haltingTimeThreshold,
double haltingSpeedThreshold,
double jamDistThreshold,
66 const std::string& vTypes) :
70 myJamHaltingSpeedThreshold(haltingSpeedThreshold),
71 myJamHaltingTimeThreshold(haltingTimeThreshold),
72 myJamDistanceThreshold(jamDistThreshold),
73 myNumberOfEnteredVehicles(0),
74 myNumberOfSeenVehicles(0),
75 myNumberOfLeftVehicles(0) {
78 #ifdef DEBUG_E2_CONSTRUCTOR
80 std::cout <<
"\n" <<
"Creating MSE2Collector " <<
id
81 <<
" with lane = " << lane->
getID()
82 <<
" startPos = " << startPos
83 <<
" endPos = " << endPos
84 <<
" length = " << length
85 <<
" haltingTimeThreshold = " << haltingTimeThreshold
86 <<
" haltingSpeedThreshold = " << haltingSpeedThreshold
87 <<
" jamDistThreshold = " << jamDistThreshold
95 bool lengthInvalid = length == std::numeric_limits<double>::max() || length <= 0;
96 bool endPosInvalid = endPos == std::numeric_limits<double>::max();
97 bool posInvalid = startPos == std::numeric_limits<double>::max();
103 WRITE_WARNING(
"No valid detector length and start position given. Assuming startPos = 0 and length = end position");
107 WRITE_WARNING(
"No valid detector length and end position given. Assuming endPos = lane length and length = endPos-startPos");
110 endPos = endPos < 0 ? lane->
getLength() + endPos : endPos;
111 startPos = startPos < 0 ? lane->
getLength() + startPos : startPos;
112 bool valid = endPos <= lane->
getLength() && 0 <= startPos && startPos < endPos;
114 throw InvalidArgument(
"Error in specification for E2Detector '" +
id +
"'. Positional argument is malformed. 0 <= pos < endPos <= lane.getLength() is required.");
118 startPos =
snap(startPos, 0., POSITION_EPS);
119 length = endPos - startPos;
120 }
else if (posInvalid) {
122 endPos = endPos < 0 ? lane->
getLength() + endPos : endPos;
126 startPos = startPos < 0 ? lane->
getLength() + startPos : startPos;
127 startPos =
snap(startPos, 0., POSITION_EPS);
133 std::vector<MSLane*> lanes;
136 }
else if (endPosInvalid) {
140 lanes.push_back(lane);
150 DetectorUsage usage, std::vector<MSLane*> lanes,
double startPos,
double endPos,
151 SUMOTime haltingTimeThreshold,
double haltingSpeedThreshold,
double jamDistThreshold,
152 const std::string& vTypes) :
156 myFirstLane(lanes[0]),
157 myLastLane(lanes[lanes.size() - 1]),
158 myStartPos(startPos),
160 myJamHaltingSpeedThreshold(haltingSpeedThreshold),
161 myJamHaltingTimeThreshold(haltingTimeThreshold),
162 myJamDistanceThreshold(jamDistThreshold),
163 myNumberOfEnteredVehicles(0),
164 myNumberOfSeenVehicles(0),
165 myNumberOfLeftVehicles(0) {
168 for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
172 #ifdef DEBUG_E2_CONSTRUCTOR
174 std::cout <<
"\n" <<
"Creating MSE2Collector " <<
id
176 <<
" endPos = " << endPos
178 <<
" startPos = " << startPos
179 <<
" haltingTimeThreshold = " << haltingTimeThreshold
180 <<
" haltingSpeedThreshold = " << haltingSpeedThreshold
181 <<
" jamDistThreshold = " << jamDistThreshold
192 if (
myEndPos > lanes[lanes.size() - 1]->getLength() - POSITION_EPS) {
193 myEndPos = lanes[lanes.size() - 1]->getLength();
206 if (desiredLength > 0 &&
myDetectorLength < desiredLength - NUMERICAL_EPS) {
207 std::stringstream ss;
208 ss <<
"Cannot build detector of length " << desiredLength
223 WRITE_WARNING(
"Adjusted detector positioning to meet requirement length >= " +
toString(POSITION_EPS)
236 #ifdef DEBUG_E2_CONSTRUCTOR
238 std::stringstream ss;
241 std::cout <<
"myStartPos = " <<
myStartPos << std::endl;
242 std::cout <<
"myEndPos = " <<
myEndPos << std::endl;
256 if (fabs(value - snapPoint) < snapDist) {
266 std::vector<std::string>::const_iterator i;
267 std::vector<MSLane*> lanes;
271 lanes.push_back(lane);
275 std::vector<MSLane*>::const_iterator j;
276 MSLane* previous =
nullptr;
278 for (j = lanes.begin(); j != lanes.end(); ++j) {
291 #ifdef DEBUG_E2_CONSTRUCTOR
293 std::cout <<
"Total detector length after recalculation = " <<
myDetectorLength << std::endl;
308 assert(dir ==
"fw" || dir ==
"bw");
309 bool fw = dir ==
"fw";
310 double linkLength = 0;
311 bool substractedLinkLength =
false;
313 #ifdef DEBUG_E2_CONSTRUCTOR
315 std::cout <<
"\n" <<
"selectLanes()" << (fw ?
"(forward)" :
"(backward)") << std::endl;
318 std::vector<MSLane*> lanes;
324 assert(
myStartPos != std::numeric_limits<double>::max());
327 assert(
myEndPos != std::numeric_limits<double>::max());
330 length =
MAX2(POSITION_EPS, length);
331 while (length >= POSITION_EPS && lane !=
nullptr) {
334 lanes.push_back(lane);
335 #ifdef DEBUG_E2_CONSTRUCTOR
337 std::cout <<
"Added lane " << lane->
getID()
338 <<
" (length: " << lane->
getLength() <<
")" << std::endl;
352 substractedLinkLength =
false;
362 length -= linkLength;
363 substractedLinkLength =
true;
367 #ifdef DEBUG_E2_CONSTRUCTOR
370 std::cout << (fw ?
"Successor lane: " :
"Predecessor lane: ") <<
"'" << lane->
getID() <<
"'";
372 std::cout << std::endl;
377 if (substractedLinkLength) {
381 length += linkLength;
394 if (length > -POSITION_EPS) {
395 myEndPos = lanes[lanes.size() - 1]->getLength();
396 }
else if (length < 0) {
397 myEndPos = lanes[lanes.size() - 1]->getLength() + length;
400 if (length > -POSITION_EPS) {
402 }
else if (length < 0) {
409 std::reverse(lanes.begin(), lanes.end());
417 #ifdef DEBUG_E2_CONSTRUCTOR
419 std::cout <<
"\n" <<
"Adding detector " <<
myID <<
" to lanes:" << std::endl;
422 for (std::vector<MSLane*>::iterator l = lanes.begin(); l != lanes.end(); ++l) {
423 (*l)->addMoveReminder(
this);
424 #ifdef DEBUG_E2_CONSTRUCTOR
426 std::cout << (*l)->getID() << std::endl;
438 #ifdef DEBUG_E2_CONSTRUCTOR
440 std::cout <<
"\n" <<
"Initializing auxiliaries:"
460 std::vector<MSLane*>::iterator il = lanes.begin();
467 #ifdef DEBUG_E2_CONSTRUCTOR
469 std::cout <<
"\n" <<
"Initializing offsets:" << std::endl;
474 #pragma warning(push)
475 #pragma warning(disable: 4127)
482 while (
internal !=
nullptr) {
483 myLanes.push_back(internal->getID());
486 #ifdef DEBUG_E2_CONSTRUCTOR
488 std::cout <<
"Offset for lane " <<
internal->getID() <<
" = " <<
myDetectorLength
499 assert(internal->getLinkCont().size() == 1);
501 internal =
internal->getLinkCont()[0]->getViaLaneOrLane();
502 if (!internal->isInternal()) {
514 while (il != lanes.end() && (*il)->isInternal()) {
517 if (il == lanes.end()) {
525 #ifdef DEBUG_E2_CONSTRUCTOR
539 if (++il == lanes.end()) {
543 if ((*il)->isInternal()) {
551 if (link ==
nullptr) {
552 throw InvalidArgument(
"Lanes '" + lane->
getID() +
"' and '" + (*il)->getID() +
"' are not consecutive in defintion of e2Detector '" +
getID() +
"'");
563 bool fw =
myEndPos == std::numeric_limits<double>::max();
570 #ifdef DEBUG_E2_CONSTRUCTOR
572 std::cout <<
"Total detector length after initAuxiliaries() = " <<
myDetectorLength << std::endl;
583 std::vector<MSLane*> res;
584 for (std::vector<std::string>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
593 double newPos,
double newSpeed) {
604 const std::string& vehID = veh.
getID();
613 #ifdef DEBUG_E2_NOTIFY_MOVE
616 <<
" MSE2Collector::notifyMove() (detID = " <<
myID <<
"on lane '" <<
myLane->
getID() <<
"')"
617 <<
" called by vehicle '" << vehID <<
"'"
618 <<
" at relative position " << relPos
626 #ifdef DEBUG_E2_NOTIFY_MOVE
628 std::cout <<
"Vehicle has not yet reached the detector start position." << std::endl;
645 if (vehicleEnteredLaneAfterDetector) {
646 #ifdef DEBUG_E2_NOTIFY_MOVE
648 std::cout <<
"Vehicle entered lane behind detector." << std::endl;
656 if (vehPassedDetectorEnd) {
657 #ifdef DEBUG_E2_NOTIFY_MOVE
659 std::cout <<
"Vehicle has left the detector longitudinally." << std::endl;
677 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
679 std::cout <<
"\n" <<
SIMTIME <<
" notifyLeave() (detID = " <<
myID <<
"on lane '" <<
myLane->
getID() <<
"')"
680 <<
"called by vehicle '" << veh.
getID() <<
"'" << std::endl;
690 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
692 std::cout <<
SIMTIME <<
" Left longitudinally (along junction) -> keep subscription [handle exit in notifyMove()]" << std::endl;
700 double exitOffset = vi->second->entryOffset -
myOffsets[vi->second->currentOffsetIndex] - vi->second->currentLane->getLength();
701 vi->second->exitOffset =
MAX2(vi->second->exitOffset, exitOffset);
702 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
704 std::cout <<
SIMTIME <<
" Vehicle '" << veh.
getID() <<
"' leaves the detector. Exit offset = " << vi->second->exitOffset << std::endl;
713 if (vi->second->hasEntered) {
718 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
720 std::cout <<
SIMTIME <<
" Left non-longitudinally (lanechange, teleport, parking, etc) -> discard subscription" << std::endl;
734 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
736 std::cout << std::endl <<
SIMTIME <<
" notifyEnter() (detID = " <<
myID <<
" on lane '" <<
myLane->
getID() <<
"')"
737 <<
" called by vehicle '" << veh.
getID()
738 <<
"' entering lane '" << (enteredLane != 0 ? enteredLane->
getID() :
"NULL") <<
"'" << std::endl;
743 assert(veh.
getLane() == enteredLane);
754 bool vehEnteredBehindDetectorEnd = (enteredLane ==
myLastLane) &&
myEndPos <= vehBackPos;
755 if (vehEnteredBehindDetectorEnd) {
758 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
760 std::cout <<
"Vehicle entered the lane behind the detector, ignoring it." << std::endl;
761 std::cout <<
"(myEndPos = " << this->
myEndPos <<
", veh.getBackPositionOnLane() = " << vehBackPos <<
")" << std::endl;
768 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
772 std::cout <<
"Vehicle is off road (teleporting over edge)..." << std::endl;
780 const std::string& vehID = veh.
getID();
784 if (vi->second->currentLane != enteredLane) {
785 vi->second->currentOffsetIndex++;
786 vi->second->currentLane = enteredLane;
789 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
792 <<
"' already known. No new VehicleInfo is created.\n"
793 <<
"enteredLane = " << enteredLane->
getID() <<
"\nmyLanes[vi->offset] = " <<
myLanes[vi->second->currentOffsetIndex]
797 assert(
myLanes[vi->second->currentOffsetIndex] == enteredLane->
getID());
805 #ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
807 std::cout <<
SIMTIME <<
" Adding VehicleInfo for vehicle '" << veh.
getID() <<
"'." << std::endl;
822 assert(j >= 0 && j < (
int)
myLanes.size());
827 #ifdef DEBUG_E2_MAKE_VEHINFO
829 std::cout <<
SIMTIME <<
" Making VehicleInfo for vehicle '" << veh.
getID() <<
"'."
830 <<
"\ndistToDetectorEnd = " << distToDetectorEnd
832 <<
"\nentry lane offset (lane begin from detector begin) = " << entryOffset
843 #ifdef DEBUG_E2_DETECTOR_UPDATE
845 std::cout <<
"\n" <<
SIMTIME <<
" detectorUpdate() for detector '" <<
myID <<
"'"
867 std::vector<JamInfo*> jams;
868 std::map<std::string, SUMOTime> haltingVehicles;
869 std::map<std::string, SUMOTime> intervalHaltingVehicles;
874 const std::string& vehID = (*i)->id;
885 bool isInJam =
checkJam(i, haltingVehicles, intervalHaltingVehicles);
886 buildJam(isInJam, i, currentJam, jams);
899 #ifdef DEBUG_E2_DETECTOR_UPDATE
901 std::cout <<
"\n" <<
SIMTIME <<
" Current lanes for vehicles still on or approaching the detector:" << std::endl;
905 VehicleInfoMap::iterator iv;
907 #ifdef DEBUG_E2_DETECTOR_UPDATE
909 std::cout <<
" Vehicle '" << iv->second->id <<
"'" <<
": '"
910 << iv->second->currentLane->getID() <<
"'"
916 #ifdef DEBUG_E2_DETECTOR_UPDATE
918 std::cout <<
SIMTIME <<
" Discarding vehicles that have left the detector:" << std::endl;
922 std::set<std::string>::const_iterator i;
928 #ifdef DEBUG_E2_DETECTOR_UPDATE
930 std::cout <<
"Erased vehicle '" << *i <<
"'" << std::endl;
971 #ifdef DEBUG_E2_DETECTOR_UPDATE
973 std::cout <<
SIMTIME <<
" integrateMoveNotification() for vehicle '" << mni->
id <<
"'"
977 <<
"\nspeed = " << mni->
speed
1007 #ifdef DEBUG_E2_NOTIFY_MOVE
1009 std::cout <<
SIMTIME <<
" makeMoveNotification() for vehicle '" << veh.
getID() <<
"'"
1010 <<
" oldPos = " << oldPos <<
" newPos = " << newPos <<
" newSpeed = " << newSpeed
1016 double timeOnDetector;
1028 double distToExit = -vehInfo.
exitOffset - newPos;
1030 lengthOnDetector =
MAX2(0., lengthOnDetector +
MIN2(0., distToExit));
1033 bool stillOnDetector = -distToExit < vehInfo.
length;
1035 #ifdef DEBUG_E2_NOTIFY_MOVE
1037 std::cout <<
SIMTIME <<
" lengthOnDetector = " << lengthOnDetector
1038 <<
"\nvehInfo.exitOffset = " << vehInfo.
exitOffset
1039 <<
" vehInfo.entryOffset = " << vehInfo.
entryOffset
1040 <<
" distToExit = " << distToExit
1048 timeOnDetector, lengthOnDetector, timeLoss, stillOnDetector);
1053 #ifdef DEBUG_E2_JAMS
1055 std::cout <<
SIMTIME <<
" buildJam() for vehicle '" << (*mni)->id <<
"'" << std::endl;
1061 if (currentJam ==
nullptr) {
1062 #ifdef DEBUG_E2_JAMS
1064 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"' forms the start of the first jam" << std::endl;
1077 #ifdef DEBUG_E2_JAMS
1079 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"' forms the start of a new jam" << std::endl;
1084 jams.push_back(currentJam);
1093 if (currentJam !=
nullptr) {
1094 #ifdef DEBUG_E2_JAMS
1096 std::cout <<
SIMTIME <<
" Closing current jam." << std::endl;
1099 jams.push_back(currentJam);
1100 currentJam =
nullptr;
1107 MSE2Collector::checkJam(std::vector<MoveNotificationInfo*>::const_iterator mni, std::map<std::string, SUMOTime>& haltingVehicles, std::map<std::string, SUMOTime>& intervalHaltingVehicles) {
1108 #ifdef DEBUG_E2_JAMS
1110 std::cout <<
SIMTIME <<
" CheckJam() for vehicle '" << (*mni)->id <<
"'" << std::endl;
1114 bool isInJam =
false;
1125 #ifdef DEBUG_E2_JAMS
1127 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"' starts halting." << std::endl;
1130 haltingVehicles[(*mni)->id] =
DELTA_T;
1131 intervalHaltingVehicles[(*mni)->id] =
DELTA_T;
1153 #ifdef DEBUG_E2_JAMS
1155 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"'" << (isInJam ?
"is jammed." :
"is not jammed.") << std::endl;
1165 if (currentJam !=
nullptr) {
1166 jams.push_back(currentJam);
1167 currentJam =
nullptr;
1170 #ifdef DEBUG_E2_JAMS
1172 std::cout <<
"\n" <<
SIMTIME <<
" processJams()"
1173 <<
"\nNumber of jams: " << jams.size() << std::endl;
1182 for (std::vector<JamInfo*>::const_iterator i = jams.begin(); i != jams.end(); ++i) {
1189 const int jamLengthInVehicles = (int) distance((*i)->firstStandingVehicle, (*i)->lastStandingVehicle) + 1;
1197 #ifdef DEBUG_E2_JAMS
1199 std::cout <<
SIMTIME <<
" processing jam nr." << ((int) distance((std::vector<JamInfo*>::const_iterator) jams.begin(), i) + 1)
1200 <<
"\njamLengthInMeters = " << jamLengthInMeters
1201 <<
" jamLengthInVehicles = " << jamLengthInVehicles
1209 for (std::vector<JamInfo*>::iterator i = jams.begin(); i != jams.end(); ++i) {
1219 if (oldPos == newPos) {
1222 timeOnDetector =
TS;
1229 double entryTime = 0;
1231 if (oldPos < entryPos) {
1239 assert(entryPos < exitPos);
1243 if (exitPos == newPos) {
1258 timeOnDetector = exitTime - entryTime;
1259 timeLoss =
MAX2(0., timeOnDetector * (vmax - (entrySpeed + exitSpeed) / 2) / vmax);
1261 #ifdef DEBUG_E2_TIME_ON_DETECTOR
1263 std::cout <<
SIMTIME <<
" calculateTimeLoss() for vehicle '" << veh.
getID() <<
"'"
1264 <<
" oldPos = " << oldPos <<
" newPos = " << newPos
1265 <<
" entryPos = " << entryPos <<
" exitPos = " << exitPos
1266 <<
" timeOnDetector = " << timeOnDetector
1267 <<
" timeLoss = " << timeLoss
1281 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
getID() <<
"\" ";
1294 haltingDurationSum += (*i);
1295 maxHaltingDuration =
MAX2(maxHaltingDuration, (*i));
1299 haltingDurationSum += (*i).second;
1300 maxHaltingDuration =
MAX2(maxHaltingDuration, (*i).second);
1303 const SUMOTime meanHaltingDuration = haltingNo != 0 ? haltingDurationSum / haltingNo : 0;
1305 SUMOTime intervalHaltingDurationSum = 0;
1306 SUMOTime intervalMaxHaltingDuration = 0;
1307 int intervalHaltingNo = 0;
1309 intervalHaltingDurationSum += (*i);
1310 intervalMaxHaltingDuration =
MAX2(intervalMaxHaltingDuration, (*i));
1311 intervalHaltingNo++;
1314 intervalHaltingDurationSum += (*i).second;
1315 intervalMaxHaltingDuration =
MAX2(intervalMaxHaltingDuration, (*i).second);
1316 intervalHaltingNo++;
1318 const SUMOTime intervalMeanHaltingDuration = intervalHaltingNo != 0 ? intervalHaltingDurationSum / intervalHaltingNo : 0;
1320 #ifdef DEBUG_E2_XML_OUT
1322 std::stringstream ss;
1328 <<
"meanSpeed=\"" << meanSpeed <<
"\"";
1329 std::cout << ss.str() << std::endl;
1338 <<
"meanSpeed=\"" << meanSpeed <<
"\" "
1339 <<
"meanTimeLoss=\"" << meanTimeLoss <<
"\" "
1340 <<
"meanOccupancy=\"" << meanOccupancy <<
"\" "
1342 <<
"meanMaxJamLengthInVehicles=\"" << meanJamLengthInVehicles <<
"\" "
1343 <<
"meanMaxJamLengthInMeters=\"" << meanJamLengthInMeters <<
"\" "
1348 <<
"meanHaltingDuration=\"" <<
STEPS2TIME(meanHaltingDuration) <<
"\" "
1349 <<
"maxHaltingDuration=\"" <<
STEPS2TIME(maxHaltingDuration) <<
"\" "
1350 <<
"haltingDurationSum=\"" <<
STEPS2TIME(haltingDurationSum) <<
"\" "
1351 <<
"meanIntervalHaltingDuration=\"" <<
STEPS2TIME(intervalMeanHaltingDuration) <<
"\" "
1352 <<
"maxIntervalHaltingDuration=\"" <<
STEPS2TIME(intervalMaxHaltingDuration) <<
"\" "
1353 <<
"intervalHaltingDurationSum=\"" <<
STEPS2TIME(intervalHaltingDurationSum) <<
"\" "
1355 <<
"meanVehicleNumber=\"" << meanVehicleNumber <<
"\" "
1395 if (it->second->onDetector) {
1404 std::vector<std::string>
1406 std::vector<std::string> ret;
1408 if (i->second->onDetector) {
1409 ret.push_back(i->second->id);
1412 std::sort(ret.begin(), ret.end());
1417 std::vector<MSE2Collector::VehicleInfo*>
1419 std::vector<VehicleInfo*> res;
1420 VehicleInfoMap::const_iterator i;
1422 if (i->second->onDetector) {
1423 res.push_back(i->second);
1440 if (it->second->onDetector) {
1445 const double realDistance = it->second->distToDetectorEnd;
1446 if (it->second->lastSpeed <= thresholdSpeed || it->second->lastAccel > 0) {
1447 count = (int)(realDistance / (it->second->length + it->second->minGap)) + 1;
1462 double distance = std::numeric_limits<double>::max();
1463 double realDistance = 0;
1464 bool flowing =
true;
1467 if (it->second->onDetector) {
1468 distance =
MIN2(it->second->lastPos, distance);
1470 if (it->second->lastSpeed <= 0.5) {
1471 realDistance = distance - it->second->length + it->second->minGap;
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t)
convert SUMOTime to string
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A scoped lock which only triggers on condition.
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t \in [0,TS] given the initial speed and the distance traveled in a...
static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
Base of value-generating classes (detectors)
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
void checkPositioning(bool posGiven=false, double desiredLength=0.)
Adjusts positioning if the detector length is less than POSITION_EPS and tests some assertions.
double myCurrentMaxJamLengthInMeters
the current maximum jam length in meters
bool checkJam(std::vector< MoveNotificationInfo * >::const_iterator mni, std::map< std::string, SUMOTime > &haltingVehicles, std::map< std::string, SUMOTime > &intervalHaltingVehicles)
checks whether the vehicle stands in a jam
MoveNotificationInfo * makeMoveNotification(const SUMOVehicle &veh, double oldPos, double newPos, double newSpeed, const VehicleInfo &vehInfo) const
Creates and returns a MoveNotificationInfo containing detector specific information on the vehicle's ...
void buildJam(bool isInJam, std::vector< MoveNotificationInfo * >::const_iterator mni, JamInfo *¤tJam, std::vector< JamInfo * > &jams)
Either adds the vehicle to the end of an existing jam, or closes the last jam, and/or creates a new j...
std::map< std::string, SUMOTime > myHaltingVehicleDurations
Storage for halting durations of known vehicles (for halting vehicles)
int myJamLengthInVehiclesSum
The sum of jam lengths [#veh].
int myMeanVehicleNumber
The mean number of vehicles [#veh].
int myCurrentStartedHalts
The number of started halts in the last step.
int myTimeSamples
The current aggregation duration [#steps].
static bool compareMoveNotification(MoveNotificationInfo *mni1, MoveNotificationInfo *mni2)
int myNumberOfSeenVehicles
The number of vehicles, present on the detector at the last reset.
int myCurrentMaxJamLengthInVehicles
The current maximum jam length in vehicles.
std::vector< MSLane * > getLanes()
Returns a vector containing pointers to the lanes covered by the detector ordered from its first to i...
int myNumberOfLeftVehicles
The number of vehicles, which have left the detector since the last reset.
std::vector< SUMOTime > myPastStandingDurations
Halting durations of ended halts [s].
void processJams(std::vector< JamInfo * > &jams, JamInfo *currentJam)
Calculates aggregated values from the given jam structure, deletes all jam-pointers.
std::vector< double > myOffsets
The distances of the lane-beginnings from the detector start-point.
int myMaxJamInVehicles
The max jam length [#veh].
virtual void reset()
Resets all values.
virtual bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Adds/removes vehicles from the list of vehicles to regard.
std::vector< VehicleInfo * > getCurrentVehicles() const
Returns the VehicleInfos for the vehicles currently on the detector.
double myJamHaltingSpeedThreshold
A vehicle must driver slower than this to be counted as a part of a jam.
virtual bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane)
Adds the vehicle to known vehicles if not beyond the dector.
VehicleInfoMap myVehicleInfos
int myNumberOfEnteredVehicles
static double snap(double value, double snapPoint, double snapDist)
Snaps value to snpPoint if they are closer than snapDist.
void initAuxiliaries(std::vector< MSLane * > &lanes)
Checks integrity of myLanes, adds internal-lane information, inits myLength, myFirstLane,...
MSLane * myFirstLane
The first lane of the detector's lane sequence.
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
double mySpeedSum
The sum of collected vehicle speeds [m/s].
std::set< std::string > myLeftVehicles
Keep track of vehicles that left the detector by a regular move along a junction (not lanechange,...
double myEndPos
The position the detector ends at on the last lane.
VehicleInfo * makeVehicleInfo(const SUMOVehicle &veh, const MSLane *enteredLane) const
Creates and returns a VehicleInfo (called at the vehicle's entry)
double myDetectorLength
The total detector length.
std::vector< MSLane * > selectLanes(MSLane *endLane, double length, std::string dir)
This is called if no lane sequence is given to the constructor. Builds myLanes from the given informa...
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
double myCurrentMeanSpeed
The current mean speed.
double myStartPos
The position the detector starts at on the first lane.
void calculateTimeLossAndTimeOnDetector(const SUMOVehicle &veh, double oldPos, double newPos, const VehicleInfo &vi, double &timeOnDetector, double &timeLoss) const
Calculates the time spent on the detector in the last step and the timeloss suffered in the last step...
std::vector< MoveNotificationInfo * > myMoveNotifications
Temporal storage for notifications from vehicles that did call the detector's notifyMove() in the las...
void addDetectorToLanes(std::vector< MSLane * > &lanes)
This adds the detector as a MoveReminder to the associated lanes.
SUMOTime myJamHaltingTimeThreshold
A vehicle must be that long beyond myJamHaltingSpeedThreshold to be counted as a part of a jam.
int myMaxVehicleNumber
The maximal number of vehicles located on the detector simultaneously since the last reset.
void recalculateDetectorLength()
Updates the detector length after myStartPos and myEndPos have been modified.
double myMaxOccupancy
The maximum occupancy [%].
virtual void detectorUpdate(const SUMOTime step)
Computes the detector values in each time step.
int myCurrentJamNo
The current jam number.
double myCurrentVehicleSamples
The current vehicle samples.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes a known vehicle due to its lane-change.
double myStartedHalts
The number of started halts [#].
double getEstimateQueueLength() const
Returns an estimate of the length of the queue of vehicles currently stopped on the detector.
virtual void writeXMLOutput(OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime)
Write the generated output to the given device.
double myMeanMaxJamInMeters
The mean jam length [m].
double myCurrentJamLengthInMeters
The overall jam length in meters.
double myCurrentMeanLength
The current mean length.
double myMaxJamInMeters
The max jam length [m].
std::vector< std::string > myLanes
int myMeanMaxJamInVehicles
The mean jam length [#veh].
int myCurrentJamLengthInVehicles
The overall jam length in vehicles.
double myJamLengthInMetersSum
The sum of jam lengths [m].
double myJamDistanceThreshold
Two standing vehicles must be closer than this to be counted into the same jam.
int getEstimatedCurrentVehicleNumber(double speedThreshold) const
Returns an estimate of the number of vehicles currently on the detector.
double getLength() const
Returns the length of the detector.
std::vector< SUMOTime > myPastIntervalStandingDurations
Halting durations of ended halts for the current interval [s].
virtual ~MSE2Collector()
Destructor.
MSLane * myLastLane
The last lane of the detector's lane sequence.
double myCurrentOccupancy
The current occupancy.
double myOccupancySum
The sum of occupancies [%].
int myCurrentHaltingsNumber
The number of halted vehicles [#].
virtual void clearState()
Remove all vehicles before quick-loading state.
MSE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string &vTypes)
Constructor with given end position and detector length.
virtual void writeXMLDetectorProlog(OutputDevice &dev) const
Open the XML-output.
double myTotalTimeLoss
The total amount of all time losses [time x vehicle] since the last reset.
void integrateMoveNotification(VehicleInfo *vi, const MoveNotificationInfo *mni)
This updates the detector values and the VehicleInfo of a vehicle on the detector with the given Move...
std::map< std::string, SUMOTime > myIntervalHaltingVehicleDurations
Storage for halting durations of known vehicles (current interval)
void aggregateOutputValues()
Aggregates and normalize some values for the detector output during detectorUpdate()
static int gNumSimThreads
how many threads to use for simulation
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Representation of a lane in the micro simulation.
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
MSLane * getCanonicalPredecessorLane() const
double getLength() const
Returns the lane's length.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
MSLane * getCanonicalSuccessorLane() const
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
MSLane * getViaLane() const
Returns the following inner lane.
double getLength() const
Returns the length of this link.
Something on a lane to be noticed about vehicle movement.
MSLane *const myLane
Lane on which the reminder works.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
double getMinGap() const
Get the free space in front of vehicles of this class.
const std::string & getID() const
Returns the name of the vehicle type.
double getLength() const
Get vehicle's length [m].
std::string myID
The name of the object.
const std::string & getID() const
Returns the id.
Static storage of an output device and its base (abstract) implementation.
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getBackPositionOnLane(const MSLane *lane) const =0
Get the object's back position along the given lane.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
Internal representation of a jam.
std::vector< MoveNotificationInfo * >::const_iterator lastStandingVehicle
The last standing vehicle.
std::vector< MoveNotificationInfo * >::const_iterator firstStandingVehicle
The first standing vehicle.
Values collected in notifyMove and needed in detectorUpdate() to calculate the accumulated quantities...
double speed
Speed after the last integration step.
double newPos
Position after the last integration step (relative to the vehicle's entry lane on the detector)
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
double accel
Acceleration in the last integration step.
double timeLoss
timeloss during the last integration step
double timeOnDetector
Time spent on the detector during the last integration step.
double lengthOnDetector
The length of the part of the vehicle on the detector at the end of the last time step.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
std::string id
Vehicle's id.
A VehicleInfo stores values that are tracked for the individual vehicles on the detector,...
double lastAccel
Last value of the acceleration.
double length
vehicle's length
double accumulatedTimeLoss
Accumulated time loss that this vehicle suffered since it entered the detector.
bool onDetector
whether the vehicle is on the detector at the end of the current timestep
double distToDetectorEnd
Distance left till the detector end after the last integration step (may become negative if the vehic...
double lastSpeed
Last value of the speed.
bool hasEntered
Whether the vehicle has already entered the detector (don't count twice!)
std::string id
vehicle's ID
double totalTimeOnDetector
Accumulated time that this vehicle has spent on the detector since its last entry.