LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_FCDReplay.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 75.0 % 8 6
Test Date: 2024-11-22 15:46:21 Functions: 0.0 % 1 0

            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    MSDevice_FCDReplay.h
      15              : /// @author  Michael Behrisch
      16              : /// @date    01.03.2024
      17              : ///
      18              : // A device which replays recorded floating car data
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <utils/common/Command.h>
      24              : #include <utils/common/MapMatcher.h>
      25              : #include <utils/xml/SUMOSAXHandler.h>
      26              : #include "MSVehicleDevice.h"
      27              : 
      28              : 
      29              : // ===========================================================================
      30              : // class declarations
      31              : // ===========================================================================
      32              : class SUMOSAXReader;
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // class definitions
      37              : // ===========================================================================
      38              : /**
      39              :  * @class MSDevice_FCDReplay
      40              :  * @brief A device which replays a vehicle trajectory from an fcd file
      41              :  *
      42              :  * @see MSDevice
      43              :  */
      44              : class MSDevice_FCDReplay : public MSVehicleDevice {
      45              : public:
      46              :     /** @brief Inserts MSDevice_FCDReplay-options
      47              :      * @param[filled] oc The options container to add the options to
      48              :      */
      49              :     static void insertOptions(OptionsCont& oc);
      50              : 
      51              : 
      52              :     /** @brief Build devices for the given vehicle, if needed
      53              :      *
      54              :      * The options are read and evaluated whether a FCDReplay-device shall be built
      55              :      *  for the given vehicle.
      56              :      *
      57              :      * The built device is stored in the given vector.
      58              :      *
      59              :      * @param[in] v The vehicle for which a device may be built
      60              :      * @param[filled] into The vector to store the built device in
      61              :      */
      62              :     static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
      63              : 
      64              :     /** @brief Static intialization
      65              :      */
      66              :     static void init();
      67              :     static SUMOTime parseNext(SUMOTime t);
      68              : 
      69              : public:
      70              :     /// @brief Destructor.
      71              :     ~MSDevice_FCDReplay();
      72              : 
      73              :     void move(SUMOTime currentTime);
      74              : 
      75              :     /// @brief return the name for this type of device
      76            0 :     const std::string deviceName() const override {
      77            0 :         return "fcd-replay";
      78              :     }
      79              : 
      80        55764 :     struct TrajectoryEntry {
      81              :         SUMOTime time;
      82              :         Position pos;
      83              :         std::string edgeOrLane;
      84              :         double lanePos;
      85              :         double speed;
      86              :         double angle;
      87              :     };
      88              : 
      89              :     typedef std::vector<TrajectoryEntry> Trajectory;
      90              : 
      91              :     void setTrajectory(Trajectory* const t) {
      92           28 :         myTrajectory = t;
      93           28 :         myTrajectoryIndex = 1;
      94              :     }
      95              : 
      96              : private:
      97              :     /** @brief Constructor
      98              :      *
      99              :      * @param[in] holder The vehicle that holds this device
     100              :      * @param[in] id The ID of the device
     101              :      */
     102              :     MSDevice_FCDReplay(SUMOVehicle& holder, const std::string& id);
     103              : 
     104           16 :     class MoveVehicles : public Command {
     105              :     public:
     106              :         SUMOTime execute(SUMOTime currentTime) override;
     107              :     private:
     108              :         /// @brief Invalidated assignment operator.
     109              :         MoveVehicles& operator=(const MoveVehicles&) = delete;
     110              :     };
     111              : 
     112              :     class FCDHandler : public SUMOSAXHandler, public MapMatcher<MSEdge, MSLane, MSJunction> {
     113              :     public:
     114              :         FCDHandler(const std::string& file);
     115              :         SUMOTime getTime() const {
     116        43612 :             return myTime;
     117              :         }
     118              :         void updateTrafficObjects(const SUMOTime intervalStart);
     119              : 
     120              :     protected:
     121              :         /// @name inherited from GenericSAXHandler
     122              :         //@{
     123              : 
     124              :         /** @brief Called on the opening of a tag
     125              :          *
     126              :          * @param[in] element ID of the currently opened element
     127              :          * @param[in] attrs Attributes within the currently opened element
     128              :          * @exception ProcessError If something fails
     129              :          * @see GenericSAXHandler::myStartElement
     130              :          */
     131              :         void myStartElement(int element, const SUMOSAXAttributes& attrs) override;
     132              :         //@}
     133              : 
     134              :         void initLaneTree(NamedRTree* tree) override;
     135              : 
     136              :         MSEdge* retrieveEdge(const std::string& id) override;
     137              : 
     138              :     private:
     139          200 :         struct StageStart {
     140              :             std::string vehicle;
     141              :             int trajectoryOffset;
     142              :             int routeOffset;
     143              :         };
     144              : 
     145              :         MSTransportable::MSTransportablePlan* makePlan(const SUMOVehicleParameter& params, const ConstMSEdgeVector& route,
     146              :                 const std::vector<StageStart>& stages, const Trajectory& t);
     147              :         ConstMSEdgeVector checkRoute(const ConstMSEdgeVector& edges, const SUMOVehicle* const vehicle);
     148              : 
     149              :         SUMOTime myTime = 0;
     150              :         std::map<std::string, Trajectory> myTrajectories;
     151              :         std::map<std::string, std::tuple<SUMOTime, std::string, bool, ConstMSEdgeVector, std::vector<StageStart> > > myRoutes;
     152              :         std::map<const Position, std::string> myPositions;
     153              :     };
     154              : 
     155              : private:
     156              :     static FCDHandler* myHandler;
     157              :     static SUMOSAXReader* myParser;
     158              :     Trajectory* myTrajectory = nullptr;
     159              :     int myTrajectoryIndex = 0;
     160              : 
     161              : private:
     162              :     /// @brief Invalidated copy constructor.
     163              :     MSDevice_FCDReplay(const MSDevice_FCDReplay&) = delete;
     164              : 
     165              :     /// @brief Invalidated assignment operator.
     166              :     MSDevice_FCDReplay& operator=(const MSDevice_FCDReplay&) = delete;
     167              : 
     168              : };
        

Generated by: LCOV version 2.0-1