LCOV - code coverage report
Current view: top level - src/microsim - MSMoveReminder.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 25 25
Test Date: 2024-10-24 15:46:30 Functions: 100.0 % 3 3

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2008-2024 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    MSMoveReminder.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    2008-10-27
      19              : ///
      20              : // Something on a lane to be noticed about vehicle movement
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <string>
      25              : #include "MSLane.h"
      26              : #include "MSMoveReminder.h"
      27              : 
      28              : 
      29              : // ===========================================================================
      30              : // method definitions
      31              : // ===========================================================================
      32     13188359 : MSMoveReminder::MSMoveReminder(const std::string& description, MSLane* const lane, const bool doAdd) :
      33     13188359 :     myLane(lane),
      34     13188359 :     myDescription(description)
      35              : #ifdef HAVE_FOX
      36     13188359 :     , myNotificationMutex(true)
      37              : #endif
      38              : {
      39     13188359 :     if (myLane != nullptr && doAdd) {
      40              :         // add reminder to lane
      41       137116 :         myLane->addMoveReminder(this);
      42              :     }
      43     13188359 : }
      44              : 
      45              : 
      46              : void
      47     31249039 : MSMoveReminder::updateDetector(SUMOTrafficObject& veh, double entryPos, double leavePos,
      48              :                                SUMOTime entryTime, SUMOTime currentTime, SUMOTime leaveTime,
      49              :                                bool cleanUp) {
      50              :     // each vehicle is tracked linearly across its segment. For each vehicle,
      51              :     // the time and position of the previous call are maintained and only
      52              :     // the increments are sent to notifyMoveInternal
      53     31249039 :     if (entryTime > currentTime) {
      54              :         return; // calibrator may insert vehicles a tiny bit into the future; ignore those
      55              :     }
      56     31244265 :     auto j = myLastVehicleUpdateValues.find(veh.getNumericalID());
      57     31244265 :     if (j != myLastVehicleUpdateValues.end()) {
      58              :         // the vehicle already has reported its values before; use these
      59              :         // however, if this was called from prepareDetectorForWriting the time
      60              :         // only has a resolution of DELTA_T and might be invalid
      61     19141434 :         const SUMOTime previousEntryTime = j->second.first;
      62     19141434 :         if (previousEntryTime <= currentTime) {
      63              :             entryTime = previousEntryTime;
      64     19141430 :             entryPos = j->second.second;
      65              :         }
      66              :     }
      67              :     assert(entryTime <= currentTime);
      68     31244265 :     if ((entryTime < leaveTime) && (entryPos <= leavePos)) {
      69     31244177 :         const double timeOnLane = STEPS2TIME(currentTime - entryTime);
      70     31244177 :         const double speed = (leavePos - entryPos) / STEPS2TIME(leaveTime - entryTime);
      71     31244177 :         myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(currentTime, entryPos + speed * timeOnLane);
      72              :         assert(timeOnLane >= 0);
      73     31244177 :         notifyMoveInternal(veh, timeOnLane, timeOnLane, speed, speed, speed * timeOnLane, speed * timeOnLane, 0.);
      74              :     } else {
      75              :         // it would be natural to
      76              :         // assert(entryTime == leaveTime);
      77              :         // assert(entryPos == leavePos);
      78              :         // However, in the presence of calibrators, vehicles may jump a bit
      79           88 :         myLastVehicleUpdateValues[veh.getNumericalID()] = std::pair<SUMOTime, double>(leaveTime, leavePos);
      80              :     }
      81     31244265 :     if (cleanUp) {
      82              :         // clean up after the vehicle has left the area of this reminder
      83      4167610 :         removeFromVehicleUpdateValues(veh);
      84              :     }
      85              : }
      86              : 
      87              : 
      88              : void
      89     13218314 : MSMoveReminder::removeFromVehicleUpdateValues(SUMOTrafficObject& veh) {
      90     13218314 :     myLastVehicleUpdateValues.erase(veh.getNumericalID());
      91     13218314 : }
      92              : 
      93              : 
      94              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1