69 SUMOTime haltingTimeThreshold,
double haltingSpeedThreshold,
double jamDistThreshold,
70 const std::string name,
const std::string& vTypes,
71 const std::string& nextEdges,
77 myJamHaltingSpeedThreshold(haltingSpeedThreshold),
78 myJamHaltingTimeThreshold(haltingTimeThreshold),
79 myJamDistanceThreshold(jamDistThreshold),
80 myNumberOfEnteredVehicles(0),
81 myNumberOfSeenVehicles(0),
82 myNumberOfLeftVehicles(0),
83 myCurrentVehicleSamples(0),
84 myCurrentOccupancy(0),
85 myCurrentMeanSpeed(0),
86 myCurrentMeanLength(0),
88 myCurrentMaxJamLengthInMeters(0),
89 myCurrentJamLengthInMeters(0),
90 myCurrentJamLengthInVehicles(0),
91 myCurrentHaltingsNumber(0),
92 myPreviousMeanOccupancy(0),
93 myPreviousMeanSpeed(0),
94 myPreviousMeanTimeLoss(0),
95 myPreviousMaxJamLengthInMeters(0),
96 myPreviousNumberOfSeenVehicles(0),
97 myOverrideVehNumber(-1) {
100#ifdef DEBUG_E2_CONSTRUCTOR
102 std::cout <<
"\n" <<
"Creating MSE2Collector " <<
id
103 <<
" with lane = " << lane->
getID()
104 <<
" startPos = " << startPos
105 <<
" endPos = " << endPos
106 <<
" length = " << length
107 <<
" haltingTimeThreshold = " << haltingTimeThreshold
108 <<
" haltingSpeedThreshold = " << haltingSpeedThreshold
109 <<
" jamDistThreshold = " << jamDistThreshold
117 bool lengthInvalid = length == std::numeric_limits<double>::max() || length <= 0;
118 bool endPosInvalid = endPos == std::numeric_limits<double>::max();
119 bool posInvalid = startPos == std::numeric_limits<double>::max();
125 WRITE_WARNING(
TL(
"No valid detector length and start position given. Assuming startPos = 0 and length = end position"));
129 WRITE_WARNING(
TL(
"No valid detector length and end position given. Assuming endPos = lane length and length = endPos-startPos"));
132 endPos = endPos < 0 ? lane->
getLength() + endPos : endPos;
133 startPos = startPos < 0 ? lane->
getLength() + startPos : startPos;
134 bool valid = endPos <= lane->
getLength() && 0 <= startPos && startPos < endPos;
136 throw InvalidArgument(
"Error in specification for E2Detector '" +
id +
"'. Positional argument is malformed. 0 <= pos < endPos <= lane.getLength() is required.");
140 startPos =
snap(startPos, 0., POSITION_EPS);
141 length = endPos - startPos;
142 }
else if (posInvalid) {
144 endPos = endPos < 0 ? lane->
getLength() + endPos : endPos;
148 startPos = startPos < 0 ? lane->
getLength() + startPos : startPos;
149 startPos =
snap(startPos, 0., POSITION_EPS);
155 std::vector<MSLane*> lanes;
158 }
else if (endPosInvalid) {
162 lanes.push_back(lane);
172 DetectorUsage usage, std::vector<MSLane*> lanes,
double startPos,
double endPos,
173 SUMOTime haltingTimeThreshold,
double haltingSpeedThreshold,
double jamDistThreshold,
174 const std::string name,
const std::string& vTypes,
175 const std::string& nextEdges,
181 myFirstLane(lanes[0]),
182 myLastLane(lanes[lanes.size() - 1]),
183 myStartPos(startPos),
185 myJamHaltingSpeedThreshold(haltingSpeedThreshold),
186 myJamHaltingTimeThreshold(haltingTimeThreshold),
187 myJamDistanceThreshold(jamDistThreshold),
188 myNumberOfEnteredVehicles(0),
189 myNumberOfSeenVehicles(0),
190 myNumberOfLeftVehicles(0),
191 myCurrentVehicleSamples(0),
192 myCurrentOccupancy(0),
193 myCurrentMeanSpeed(0),
194 myCurrentMeanLength(0),
196 myCurrentJamLengthInMeters(0),
197 myCurrentJamLengthInVehicles(0),
198 myCurrentJamDuration(0),
199 myCurrentHaltingsNumber(0),
200 myPreviousMeanOccupancy(0),
201 myPreviousMeanSpeed(0),
202 myPreviousMeanTimeLoss(0),
203 myPreviousMaxJamLengthInMeters(0),
204 myPreviousNumberOfSeenVehicles(0),
205 myOverrideVehNumber(-1) {
208 for (std::vector<MSLane*>::const_iterator i = lanes.begin(); i != lanes.end(); ++i) {
212#ifdef DEBUG_E2_CONSTRUCTOR
214 std::cout <<
"\n" <<
"Creating MSE2Collector " <<
id
216 <<
" endPos = " << endPos
218 <<
" startPos = " << startPos
219 <<
" haltingTimeThreshold = " << haltingTimeThreshold
220 <<
" haltingSpeedThreshold = " << haltingSpeedThreshold
221 <<
" jamDistThreshold = " << jamDistThreshold
232 if (
myEndPos > lanes[lanes.size() - 1]->getLength() - POSITION_EPS) {
233 myEndPos = lanes[lanes.size() - 1]->getLength();
246 if (desiredLength > 0 &&
myDetectorLength < desiredLength - NUMERICAL_EPS) {
247 std::stringstream ss;
248 ss <<
"Cannot build detector of length " << desiredLength
263 WRITE_WARNING(
"Adjusted detector positioning to meet requirement length >= " +
toString(POSITION_EPS)
276#ifdef DEBUG_E2_CONSTRUCTOR
278 std::stringstream ss;
281 std::cout <<
"myStartPos = " <<
myStartPos << std::endl;
282 std::cout <<
"myEndPos = " <<
myEndPos << std::endl;
296 if (fabs(value - snapPoint) < snapDist) {
306 std::vector<std::string>::const_iterator i;
307 std::vector<MSLane*> lanes;
311 lanes.push_back(lane);
315 std::vector<MSLane*>::const_iterator j;
316 MSLane* previous =
nullptr;
318 for (j = lanes.begin(); j != lanes.end(); ++j) {
331#ifdef DEBUG_E2_CONSTRUCTOR
333 std::cout <<
"Total detector length after recalculation = " <<
myDetectorLength << std::endl;
348 assert(dir ==
"fw" || dir ==
"bw");
349 bool fw = dir ==
"fw";
350 double linkLength = 0;
351 bool subtractedLinkLength =
false;
353#ifdef DEBUG_E2_CONSTRUCTOR
355 std::cout <<
"\n" <<
"selectLanes()" << (fw ?
"(forward)" :
"(backward)") << std::endl;
358 std::vector<MSLane*> lanes;
364 assert(
myStartPos != std::numeric_limits<double>::max());
367 assert(
myEndPos != std::numeric_limits<double>::max());
370 length =
MAX2(POSITION_EPS, length);
371 while (length >= POSITION_EPS && lane !=
nullptr) {
374 lanes.push_back(lane);
375#ifdef DEBUG_E2_CONSTRUCTOR
377 std::cout <<
"Added lane " << lane->
getID()
378 <<
" (length: " << lane->
getLength() <<
")" << std::endl;
392 subtractedLinkLength =
false;
402 length -= linkLength;
403 subtractedLinkLength =
true;
407#ifdef DEBUG_E2_CONSTRUCTOR
410 std::cout << (fw ?
"Successor lane: " :
"Predecessor lane: ") <<
"'" << lane->
getID() <<
"'";
412 std::cout << std::endl;
417 if (subtractedLinkLength) {
421 length += linkLength;
434 if (length > -POSITION_EPS) {
435 myEndPos = lanes[lanes.size() - 1]->getLength();
436 }
else if (length < 0) {
437 myEndPos = lanes[lanes.size() - 1]->getLength() + length;
440 if (length > -POSITION_EPS) {
442 }
else if (length < 0) {
449 std::reverse(lanes.begin(), lanes.end());
457#ifdef DEBUG_E2_CONSTRUCTOR
459 std::cout <<
"\n" <<
"Adding detector " <<
myID <<
" to lanes:" << std::endl;
462 for (std::vector<MSLane*>::iterator l = lanes.begin(); l != lanes.end(); ++l) {
463 (*l)->addMoveReminder(
this);
464#ifdef DEBUG_E2_CONSTRUCTOR
466 std::cout << (*l)->getID() << std::endl;
478#ifdef DEBUG_E2_CONSTRUCTOR
480 std::cout <<
"\n" <<
"Initializing auxiliaries:"
500 std::vector<MSLane*>::iterator il = lanes.begin();
507#ifdef DEBUG_E2_CONSTRUCTOR
509 std::cout <<
"\n" <<
"Initializing offsets:" << std::endl;
515 while (internal !=
nullptr) {
519#ifdef DEBUG_E2_CONSTRUCTOR
534 internal = internal->
getLinkCont()[0]->getViaLaneOrLane();
547 while (il != lanes.end() && (*il)->isInternal()) {
550 if (il == lanes.end()) {
558#ifdef DEBUG_E2_CONSTRUCTOR
572 if (++il == lanes.end()) {
576 if ((*il)->isInternal()) {
584 if (link ==
nullptr) {
585 throw InvalidArgument(
"Lanes '" + lane->
getID() +
"' and '" + (*il)->getID() +
"' are not consecutive in definition of e2Detector '" +
getID() +
"'");
596 bool fw =
myEndPos == std::numeric_limits<double>::max();
603#ifdef DEBUG_E2_CONSTRUCTOR
605 std::cout <<
"Total detector length after initAuxiliaries() = " <<
myDetectorLength << std::endl;
616 std::vector<MSLane*> res;
617 for (std::vector<std::string>::const_iterator i =
myLanes.begin(); i !=
myLanes.end(); ++i) {
626 double newPos,
double newSpeed) {
632 keep =
notifyMove(*p, oldPos, newPos, newSpeed);
641 const std::string objectType = veh.
isPerson() ?
"Person" :
"Vehicle";
650 const std::string& vehID = veh.
getID();
659#ifdef DEBUG_E2_NOTIFY_MOVE
662 <<
" MSE2Collector::notifyMove() (detID = " <<
myID <<
" on lane '" <<
myLane->
getID() <<
"')"
663 <<
" called by vehicle '" << vehID <<
"'"
664 <<
" at relative position " << relPos
672#ifdef DEBUG_E2_NOTIFY_MOVE
674 std::cout <<
"Vehicle has not yet reached the detector start position." << std::endl;
691 if (vehicleEnteredLaneAfterDetector) {
692#ifdef DEBUG_E2_NOTIFY_MOVE
694 std::cout <<
"Vehicle entered lane behind detector." << std::endl;
702 if (vehPassedDetectorEnd) {
703#ifdef DEBUG_E2_NOTIFY_MOVE
705 std::cout <<
"Vehicle has left the detector longitudinally." << std::endl;
719#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
721 std::cout <<
"\n" <<
SIMTIME <<
" notifyLeave() (detID = " <<
myID <<
" on lane '" <<
myLane->
getID() <<
"')"
722 <<
"called by vehicle '" << veh.
getID() <<
"'" << std::endl;
732#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
734 std::cout <<
SIMTIME <<
" Left longitudinally (along junction) -> keep subscription [handle exit in notifyMove()]" << std::endl;
742 double exitOffset = vi->second->entryOffset -
myOffsets[vi->second->currentOffsetIndex] - vi->second->currentLane->getLength();
743 vi->second->exitOffset =
MAX2(vi->second->exitOffset, exitOffset);
744#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
746 std::cout <<
SIMTIME <<
" Vehicle '" << veh.
getID() <<
"' leaves the detector. Exit offset = " << vi->second->exitOffset << std::endl;
756 if (vi->second->hasEntered) {
761#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
763 std::cout <<
SIMTIME <<
" Left non-longitudinally (lanechange, teleport, parking, etc) -> discard subscription" << std::endl;
776#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
778 std::cout << std::endl <<
SIMTIME <<
" notifyEnter() (detID = " <<
myID <<
" on lane '" <<
myLane->
getID() <<
"')"
779 <<
" called by vehicle '" << veh.
getID()
780 <<
"' entering lane '" << (enteredLane != 0 ? enteredLane->
getID() :
"NULL") <<
"'" << std::endl;
805 bool vehEnteredBehindDetectorEnd = (enteredLane ==
myLastLane) &&
myEndPos <= vehBackPos;
806 if (vehEnteredBehindDetectorEnd) {
809#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
811 std::cout <<
"Vehicle entered the lane behind the detector, ignoring it." << std::endl;
812 std::cout <<
"(myEndPos = " << this->
myEndPos <<
", veh.getBackPositionOnLane() = " << vehBackPos <<
")" << std::endl;
819#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
823 std::cout <<
"Vehicle is off road (teleporting over edge)..." << std::endl;
831 const std::string& vehID = veh.
getID();
835 if (vi->second->currentLane != enteredLane) {
836 vi->second->currentOffsetIndex++;
837 vi->second->currentLane = enteredLane;
840#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
843 <<
"' already known. No new VehicleInfo is created.\n"
844 <<
"enteredLane = " << enteredLane->
getID() <<
"\nmyLanes[vi->offset] = " <<
myLanes[vi->second->currentOffsetIndex]
848 assert(
myLanes[vi->second->currentOffsetIndex] == enteredLane->
getID());
856#ifdef DEBUG_E2_NOTIFY_ENTER_AND_LEAVE
858 std::cout <<
SIMTIME <<
" Adding VehicleInfo for vehicle '" << veh.
getID() <<
"'." << std::endl;
873 assert(j >= 0 && j < (
int)
myLanes.size());
878#ifdef DEBUG_E2_MAKE_VEHINFO
880 std::cout <<
SIMTIME <<
" Making VehicleInfo for vehicle '" << veh.
getID() <<
"'."
881 <<
"\ndistToDetectorEnd = " << distToDetectorEnd
883 <<
"\nentry lane offset (lane begin from detector begin) = " << entryOffset
895 const double newSpeed = p->
getSpeed();
900 const double oldPos = newPos -
SPEED2DIST(newSpeed);
915 throw ProcessError(
TL(
"Multi-lane e2Detector does not support detecting persons yet"));
918 if (lane->hasPedestrians()) {
928#ifdef DEBUG_E2_DETECTOR_UPDATE
930 std::cout <<
"\n" <<
SIMTIME <<
" detectorUpdate() for detector '" <<
myID <<
"'"
952 std::vector<JamInfo*> jams;
953 std::map<std::string, SUMOTime> haltingVehicles;
954 std::map<std::string, SUMOTime> intervalHaltingVehicles;
959 const std::string& vehID = (*i)->id;
970 bool isInJam =
checkJam(i, haltingVehicles, intervalHaltingVehicles);
971 buildJam(isInJam, i, currentJam, jams);
984#ifdef DEBUG_E2_DETECTOR_UPDATE
986 std::cout <<
"\n" <<
SIMTIME <<
" Current lanes for vehicles still on or approaching the detector:" << std::endl;
990 VehicleInfoMap::iterator iv;
992#ifdef DEBUG_E2_DETECTOR_UPDATE
994 std::cout <<
" Vehicle '" << iv->second->id <<
"'" <<
": '"
995 << iv->second->currentLane->getID() <<
"'"
1001#ifdef DEBUG_E2_DETECTOR_UPDATE
1003 std::cout <<
SIMTIME <<
" Discarding vehicles that have left the detector:" << std::endl;
1007 std::set<std::string>::const_iterator i;
1013#ifdef DEBUG_E2_DETECTOR_UPDATE
1015 std::cout <<
"Erased vehicle '" << *i <<
"'" << std::endl;
1056#ifdef DEBUG_E2_DETECTOR_UPDATE
1058 std::cout <<
SIMTIME <<
" integrateMoveNotification() for vehicle '" << mni->
id <<
"'"
1061 <<
"\ntimeLoss = " << mni->
timeLoss
1062 <<
"\nspeed = " << mni->
speed
1075 if (vi !=
nullptr) {
1092#ifdef DEBUG_E2_NOTIFY_MOVE
1094 std::cout <<
SIMTIME <<
" makeMoveNotification() for vehicle '" << veh.
getID() <<
"'"
1095 <<
" oldPos = " << oldPos <<
" newPos = " << newPos <<
" newSpeed = " << newSpeed
1101 double timeOnDetector;
1113 double distToExit = -vehInfo.
exitOffset - newPos;
1115 lengthOnDetector =
MAX2(0., lengthOnDetector +
MIN2(0., distToExit));
1118 bool stillOnDetector = -distToExit < vehInfo.
length;
1120#ifdef DEBUG_E2_NOTIFY_MOVE
1122 std::cout <<
SIMTIME <<
" lengthOnDetector = " << lengthOnDetector
1123 <<
"\nvehInfo.exitOffset = " << vehInfo.
exitOffset
1124 <<
" vehInfo.entryOffset = " << vehInfo.
entryOffset
1125 <<
" distToExit = " << distToExit
1133 timeOnDetector, lengthOnDetector, timeLoss,
1141 std::cout <<
SIMTIME <<
" buildJam() for vehicle '" << (*mni)->id <<
"'" << std::endl;
1147 if (currentJam ==
nullptr) {
1150 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"' forms the start of the first jam" << std::endl;
1165 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->
id <<
"' forms the start of a new jam" << std::endl;
1170 jams.push_back(currentJam);
1179 if (currentJam !=
nullptr) {
1182 std::cout <<
SIMTIME <<
" Closing current jam." << std::endl;
1185 jams.push_back(currentJam);
1186 currentJam =
nullptr;
1193MSE2Collector::checkJam(std::vector<MoveNotificationInfo*>::const_iterator mni, std::map<std::string, SUMOTime>& haltingVehicles, std::map<std::string, SUMOTime>& intervalHaltingVehicles) {
1196 std::cout <<
SIMTIME <<
" CheckJam() for vehicle '" << (*mni)->id <<
"'" << std::endl;
1200 bool isInJam =
false;
1213 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"' starts halting." << std::endl;
1216 haltingVehicles[(*mni)->id] =
DELTA_T;
1217 intervalHaltingVehicles[(*mni)->id] =
DELTA_T;
1241 std::cout <<
SIMTIME <<
" vehicle '" << (*mni)->id <<
"'" << (isInJam ?
"is jammed." :
"is not jammed.") << std::endl;
1251 if (currentJam !=
nullptr) {
1252 jams.push_back(currentJam);
1253 currentJam =
nullptr;
1258 std::cout <<
"\n" <<
SIMTIME <<
" processJams()"
1259 <<
"\nNumber of jams: " << jams.size() << std::endl;
1269 for (std::vector<JamInfo*>::const_iterator i = jams.begin(); i != jams.end(); ++i) {
1276 const int jamLengthInVehicles = (int) distance((*i)->firstStandingVehicle, (*i)->lastStandingVehicle) + 1;
1287 std::cout <<
SIMTIME <<
" processing jam nr." << ((int) distance((std::vector<JamInfo*>::const_iterator) jams.begin(), i) + 1)
1288 <<
"\njamLengthInMeters = " << jamLengthInMeters
1289 <<
" jamLengthInVehicles = " << jamLengthInVehicles
1297 for (std::vector<JamInfo*>::iterator i = jams.begin(); i != jams.end(); ++i) {
1307 if (oldPos == newPos) {
1310 timeOnDetector =
TS;
1317 double entryTime = 0;
1319 if (oldPos < entryPos) {
1327 assert(entryPos < exitPos);
1331 if (exitPos == newPos) {
1346 timeOnDetector = exitTime - entryTime;
1347 timeLoss =
MAX2(0., timeOnDetector * (vmax - (entrySpeed + exitSpeed) / 2) / vmax);
1349#ifdef DEBUG_E2_TIME_ON_DETECTOR
1351 std::cout <<
SIMTIME <<
" calculateTimeLoss() for vehicle '" << veh.
getID() <<
"'"
1352 <<
" oldPos = " << oldPos <<
" newPos = " << newPos
1353 <<
" entryPos = " << entryPos <<
" exitPos = " << exitPos
1354 <<
" timeOnDetector = " << timeOnDetector
1355 <<
" timeLoss = " << timeLoss
1382 dev <<
" <interval begin=\"" <<
time2string(startTime) <<
"\" end=\"" <<
time2string(stopTime) <<
"\" " <<
"id=\"" <<
getID() <<
"\" ";
1393 haltingDurationSum += (*i);
1394 maxHaltingDuration =
MAX2(maxHaltingDuration, (*i));
1398 haltingDurationSum += (*i).second;
1399 maxHaltingDuration =
MAX2(maxHaltingDuration, (*i).second);
1402 const SUMOTime meanHaltingDuration = haltingNo != 0 ? haltingDurationSum / haltingNo : 0;
1404 SUMOTime intervalHaltingDurationSum = 0;
1405 SUMOTime intervalMaxHaltingDuration = 0;
1406 int intervalHaltingNo = 0;
1408 intervalHaltingDurationSum += (*i);
1409 intervalMaxHaltingDuration =
MAX2(intervalMaxHaltingDuration, (*i));
1410 intervalHaltingNo++;
1413 intervalHaltingDurationSum += (*i).second;
1414 intervalMaxHaltingDuration =
MAX2(intervalMaxHaltingDuration, (*i).second);
1415 intervalHaltingNo++;
1417 const SUMOTime intervalMeanHaltingDuration = intervalHaltingNo != 0 ? intervalHaltingDurationSum / intervalHaltingNo : 0;
1419#ifdef DEBUG_E2_XML_OUT
1421 std::stringstream ss;
1427 <<
"meanSpeed=\"" << meanSpeed <<
"\"";
1428 std::cout << ss.str() << std::endl;
1437 <<
"meanSpeed=\"" << meanSpeed <<
"\" "
1438 <<
"meanTimeLoss=\"" << meanTimeLoss <<
"\" "
1439 <<
"meanOccupancy=\"" << meanOccupancy <<
"\" "
1441 <<
"meanMaxJamLengthInVehicles=\"" << meanJamLengthInVehicles <<
"\" "
1442 <<
"meanMaxJamLengthInMeters=\"" << meanJamLengthInMeters <<
"\" "
1447 <<
"meanHaltingDuration=\"" <<
STEPS2TIME(meanHaltingDuration) <<
"\" "
1448 <<
"maxHaltingDuration=\"" <<
STEPS2TIME(maxHaltingDuration) <<
"\" "
1449 <<
"haltingDurationSum=\"" <<
STEPS2TIME(haltingDurationSum) <<
"\" "
1450 <<
"meanIntervalHaltingDuration=\"" <<
STEPS2TIME(intervalMeanHaltingDuration) <<
"\" "
1451 <<
"maxIntervalHaltingDuration=\"" <<
STEPS2TIME(intervalMaxHaltingDuration) <<
"\" "
1452 <<
"intervalHaltingDurationSum=\"" <<
STEPS2TIME(intervalHaltingDurationSum) <<
"\" "
1454 <<
"meanVehicleNumber=\"" << meanVehicleNumber <<
"\" "
1497 if (it->second->onDetector) {
1512std::vector<std::string>
1514 std::vector<std::string> ret;
1516 if (i->second->onDetector) {
1517 ret.push_back(i->second->id);
1520 std::sort(ret.begin(), ret.end());
1525std::vector<MSE2Collector::VehicleInfo*>
1527 std::vector<VehicleInfo*> res;
1528 VehicleInfoMap::const_iterator i;
1530 if (i->second->onDetector) {
1531 res.push_back(i->second);
1548 if (it->second->onDetector) {
1553 const double realDistance = it->second->distToDetectorEnd;
1554 if (it->second->lastSpeed <= thresholdSpeed || it->second->lastAccel > 0) {
1555 count = (int)(realDistance / (it->second->length + it->second->minGap)) + 1;
1570 double distance = 0;
1571 double realDistance = 0;
1572 bool flowing =
true;
1575 if (it->second->onDetector && it->second->totalTimeOnDetector > 0) {
1578 distance =
MAX2(it->second->distToDetectorEnd, distance);
1579 realDistance = distance + it->second->length;
1598 return realDistance;
#define WRITE_WARNING(msg)
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
The base class for microscopic and mesoscopic vehicles.
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
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.
std::vector< const MSEdge * > myNextEdges
The upcoming edges to filter by (empty means no filtering)
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
bool personApplies(const MSTransportable &p, int dir) const
void checkPositioning(bool posGiven=false, double desiredLength=0.)
Adjusts positioning if the detector length is less than POSITION_EPS and tests some assertions.
void notifyMovePerson(MSTransportable *p, int dir, double pos)
double myCurrentMaxJamLengthInMeters
the current maximum jam length in meters
VehicleInfo * makeVehicleInfo(const SUMOTrafficObject &veh, const MSLane *enteredLane) const
Creates and returns a VehicleInfo (called at the vehicle's entry)
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
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.
double myPreviousMeanSpeed
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 myPreviousMaxJamLengthInMeters
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 getIntervalMeanSpeed() const
double myEndPos
The position the detector ends at on the last lane.
int myPreviousNumberOfSeenVehicles
double myDetectorLength
The total detector length.
virtual void clearState(SUMOTime step)
Remove all vehicles before quick-loading state.
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.
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 [%].
double myPreviousMeanOccupancy
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.
MSE2Collector(const std::string &id, DetectorUsage usage, MSLane *lane, double startPos, double endPos, double length, SUMOTime haltingTimeThreshold, double haltingSpeedThreshold, double jamDistThreshold, const std::string name, const std::string &vTypes, const std::string &nextEdges, int detectPersons)
Constructor with given end position and detector length.
virtual bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Removes a known vehicle due to its lane-change.
double myCurrentJamDuration
The overall jam duration in s.
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].
int myOverrideVehNumber
stores the overriden (via Traci) number of vehicles on detector
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
The detector's lane sequence.
int myMeanMaxJamInVehicles
The mean jam length [#veh].
int myCurrentJamLengthInVehicles
The overall jam length in vehicles.
void calculateTimeLossAndTimeOnDetector(const SUMOTrafficObject &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...
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.
void overrideVehicleNumber(int num)
Persistently overrides the number of vehicles on top of the detector Setting a negative value removes...
double myCurrentOccupancy
The current occupancy.
double getIntervalOccupancy() const
double myOccupancySum
The sum of occupancies [%].
double myPreviousMeanTimeLoss
int myCurrentHaltingsNumber
The number of halted vehicles [#].
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)
MoveNotificationInfo * makeMoveNotification(const SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed, const VehicleInfo &vehInfo) const
Creates and returns a MoveNotificationInfo containing detector specific information on the vehicle's ...
double getIntervalMeanTimeLoss() const
void aggregateOutputValues()
Aggregates and normalize some values for the detector output during detectorUpdate()
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
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 {.
MSEdge & getEdge() const
Returns the lane's edge.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
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.
Notification
Definition of a vehicle state.
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
MSLane * myLane
Lane on which the reminder works.
virtual double getSpeed() const
the current speed of the transportable
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
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.
virtual bool isNull()
returns the information whether the device will discard all output
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >(), bool includeConfig=true)
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 const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPreviousSpeed() const =0
Returns the object's previous speed.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual SUMOTime getWaitingTime(const bool accumulated=false) const =0
virtual bool isPerson() const
Whether it is a person.
virtual double getBackPositionOnLane(const MSLane *lane) const =0
Get the object's back position along the given lane.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
A scoped lock which only triggers on condition.
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 waitingTime
the current (consecutive) waitingTime on the detector in s
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.