LCOV - code coverage report
Current view: top level - src/microsim/devices - MSTransportableDevice_FCDReplay.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 31 34 91.2 %
Date: 2024-04-30 15:40:33 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2013-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    MSTransportableDevice_FCDReplay.cpp
      15             : /// @author  Michael Behrisch
      16             : /// @date    04.03.2024
      17             : ///
      18             : // A device which replays recorded floating car data
      19             : /****************************************************************************/
      20             : #include <config.h>
      21             : 
      22             : #include <utils/options/OptionsCont.h>
      23             : #include <libsumo/Person.h>
      24             : #include <microsim/MSEventControl.h>
      25             : #include <microsim/MSNet.h>
      26             : #include <microsim/transportables/MSPerson.h>
      27             : #include <microsim/transportables/MSStageWalking.h>
      28             : #include <microsim/transportables/MSTransportable.h>
      29             : #include <microsim/transportables/MSTransportableControl.h>
      30             : #include "MSTransportableDevice_FCDReplay.h"
      31             : 
      32             : 
      33             : // ===========================================================================
      34             : // static member initializations
      35             : // ===========================================================================
      36             : bool MSTransportableDevice_FCDReplay::myAmActive = false;
      37             : 
      38             : 
      39             : // ===========================================================================
      40             : // method definitions
      41             : // ===========================================================================
      42             : // ---------------------------------------------------------------------------
      43             : // static initialisation methods
      44             : // ---------------------------------------------------------------------------
      45             : void
      46           0 : MSTransportableDevice_FCDReplay::insertOptions(OptionsCont& oc) {
      47           0 :     insertDefaultAssignmentOptions("fcd-replay", "FCD Replay Device", oc, true);
      48           0 : }
      49             : 
      50             : 
      51             : void
      52      456733 : MSTransportableDevice_FCDReplay::buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into) {
      53      456733 :     OptionsCont& oc = OptionsCont::getOptions();
      54     1370199 :     if (equippedByDefaultAssignmentOptions(oc, "fcd-replay", t, oc.isSet("device.fcd-replay.file"), true)) {
      55          40 :         MSTransportableDevice_FCDReplay* device = new MSTransportableDevice_FCDReplay(t, "fcdReplay_" + t.getID());
      56          40 :         into.push_back(device);
      57          40 :         if (!myAmActive) {
      58           4 :             MSNet::getInstance()->getBeginOfTimestepEvents()->addEvent(new MovePedestrians(), SIMSTEP + DELTA_T);
      59           4 :             myAmActive = true;
      60             :         }
      61             :     }
      62      456733 : }
      63             : 
      64             : 
      65             : // ---------------------------------------------------------------------------
      66             : // MSTransportableDevice_FCDReplay-methods
      67             : // ---------------------------------------------------------------------------
      68          40 : MSTransportableDevice_FCDReplay::MSTransportableDevice_FCDReplay(MSTransportable& holder, const std::string& id) :
      69          40 :     MSTransportableDevice(holder, id) {
      70          40 : }
      71             : 
      72             : 
      73          80 : MSTransportableDevice_FCDReplay::~MSTransportableDevice_FCDReplay() {
      74          80 : }
      75             : 
      76             : 
      77             : bool
      78       15200 : MSTransportableDevice_FCDReplay::move() {
      79       15200 :     MSPerson* person = dynamic_cast<MSPerson*>(&myHolder);
      80       15200 :     if (person == nullptr || !person->hasDeparted()) {
      81        1800 :         return false;
      82             :     }
      83       13400 :     if (myTrajectory == nullptr || myTrajectory->empty()) {
      84             :         // removing person
      85             :         return true;
      86             :     }
      87             :     const auto& p = myTrajectory->front();
      88       13360 :     libsumo::Person::moveToXY(person->getID(), std::get<1>(p), std::get<0>(p).x(), std::get<0>(p).y(), std::get<4>(p), 7);
      89             :     // person->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
      90       13360 :     myTrajectory->erase(myTrajectory->begin());
      91       13360 :     return false;
      92             : }
      93             : 
      94             : 
      95             : SUMOTime
      96        1892 : MSTransportableDevice_FCDReplay::MovePedestrians::execute(SUMOTime /* currentTime */) {
      97        1892 :     MSTransportableControl& c = MSNet::getInstance()->getPersonControl();
      98             :     std::vector<MSTransportable*> toRemove;
      99       17092 :     for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
     100       15200 :         MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
     101       15200 :         if (device != nullptr && device->move()) {
     102          40 :             toRemove.push_back(&device->getHolder());
     103             :         }
     104             :     }
     105        1932 :     for (MSTransportable* t : toRemove) {
     106          40 :         t->removeStage(0, false);
     107             :     }
     108        1932 :     return DELTA_T;
     109             : }
     110             : 
     111             : 
     112             : /****************************************************************************/

Generated by: LCOV version 1.14