Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSTransportableDevice_FCDReplay.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2025 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/****************************************************************************/
18// A device which replays recorded floating car data
19/****************************************************************************/
20#include <config.h>
21
23#include <libsumo/Person.h>
24#include <microsim/MSEdge.h>
26#include <microsim/MSLane.h>
27#include <microsim/MSNet.h>
34
35
36// ===========================================================================
37// static member initializations
38// ===========================================================================
40
41
42// ===========================================================================
43// method definitions
44// ===========================================================================
45// ---------------------------------------------------------------------------
46// static initialisation methods
47// ---------------------------------------------------------------------------
48void
50 insertDefaultAssignmentOptions("fcd-replay", "FCD Replay Device", oc, true);
51}
52
53
54void
55MSTransportableDevice_FCDReplay::buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into) {
57 if (equippedByDefaultAssignmentOptions(oc, "fcd-replay", t, oc.isSet("device.fcd-replay.file"), true)) {
59 into.push_back(device);
60 if (!myAmActive) {
62 myAmActive = true;
63 }
64 }
65}
66
67
68// ---------------------------------------------------------------------------
69// MSTransportableDevice_FCDReplay-methods
70// ---------------------------------------------------------------------------
74
75
78
79
80bool
82 if (!myHolder.hasDeparted()) { // need to check this first for trajectories of size 1
83 return false;
84 }
85 if (myTrajectory == nullptr || myTrajectoryIndex == (int)myTrajectory->size()) {
86 // removing person
87 return true;
88 }
89 MSPerson* person = dynamic_cast<MSPerson*>(&myHolder);
90 const auto& te = myTrajectory->at(myTrajectoryIndex);
91 if (person == nullptr || te.time > currentTime) {
92 return false;
93 }
95 if (person->getVehicle() == nullptr) { // entering the vehicle
96 const MSEdge* const edge = person->getEdge();
97 for (const SUMOVehicle* v : edge->getVehicles()) {
98 if (v->getSpeed() == 0. && fabs(v->getPositionOnLane() - te.lanePos) < POSITION_EPS) {
99 v->getLane()->getVehiclesSecure(); // lock the lane
100 SUMOTime dummy = -1; // boarding- and loading-time are not considered
101 MSNet::getInstance()->getPersonControl().loadAnyWaiting(edge, const_cast<SUMOVehicle*>(v), dummy, dummy, person);
102 v->getLane()->releaseVehicles(); // unlock the lane
103 }
104 }
105 } else {
106 SUMOVehicle* v = person->getVehicle();
107 if (te.speed == 0. && fabs(v->getPositionOnLane() - te.lanePos) >= POSITION_EPS) { // leaving the vehicle
108 v->getLane()->getVehiclesSecure(); // lock the lane
110 transDev->removeTransportable(person);
111 person->proceed(MSNet::getInstance(), currentTime);
112 v->getLane()->releaseVehicles(); // unlock the lane
113 }
114 }
115 }
116 if (person->getCurrentStageType() == MSStageType::WALKING) {
117 try {
118 libsumo::Person::moveToXY(person->getID(), te.edgeOrLane, te.pos.x(), te.pos.y(), te.angle, 7, 0.1);
119 } catch (const libsumo::TraCIException& e) {
120 WRITE_WARNING(e.what());
121 }
122 MSStageWalking* walk = static_cast<MSStageWalking*>(person->getCurrentStage());
123 if (myTrajectoryIndex > 0 && myTrajectory->at(myTrajectoryIndex - 1).edgeOrLane != te.edgeOrLane) {
124 walk->moveToNextEdge(person, currentTime, 1, nullptr, true);
125 }
126 }
127 // person->setPreviousSpeed(std::get<3>(p), std::numeric_limits<double>::min());
129 return false;
130}
131
132
134 // higher than default command priority of 0
135 priority = 1;
136}
137
138
142 std::vector<MSTransportableDevice_FCDReplay*> devices;
143 for (MSTransportableControl::constVehIt i = c.loadedBegin(); i != c.loadedEnd(); ++i) {
144 MSTransportableDevice_FCDReplay* device = static_cast<MSTransportableDevice_FCDReplay*>(i->second->getDevice(typeid(MSTransportableDevice_FCDReplay)));
145 if (device != nullptr) {
146 devices.push_back(device);
147 }
148 }
149 for (MSTransportableDevice_FCDReplay* d : devices) {
150 if (d->move(currentTime)) {
151 d->getHolder().removeStage(0, false);
152 }
153 }
154 return DELTA_T;
155}
156
157
158/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
#define SIMSTEP
Definition SUMOTime.h:61
int priority
Definition Command.h:87
void removeTransportable(MSTransportable *transportable)
Remove a passenger (TraCI).
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition MSDevice.cpp:157
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition MSDevice.h:200
A road/street connecting two junctions.
Definition MSEdge.h:77
std::vector< const SUMOVehicle * > getVehicles() const
return vehicles on this edges lanes or segments
Definition MSEdge.cpp:1505
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition MSLane.h:483
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition MSLane.h:513
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:485
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1256
bool moveToNextEdge(MSTransportable *person, SUMOTime currentTime, int prevDir, MSEdge *nextInternal=nullptr, const bool isReplay=false)
move forward and return whether the person arrived
constVehIt loadedBegin() const
Returns the begin of the internal transportables map.
constVehIt loadedEnd() const
Returns the end of the internal transportables map.
std::map< std::string, MSTransportable * >::const_iterator constVehIt
Definition of the internal transportables map iterator.
bool loadAnyWaiting(const MSEdge *edge, SUMOVehicle *vehicle, SUMOTime &timeToLoadNext, SUMOTime &stopDuration, MSTransportable *const force=nullptr)
load any applicable transportables Loads any person / container that is waiting on that edge for the ...
SUMOTime execute(SUMOTime currentTime)
Executes the command.
MSTransportableDevice_FCDReplay(MSTransportable &holder, const std::string &id)
Constructor.
static bool myAmActive
whether an event for pedestrian processing was added
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSTransportableDevice_FCDReplay-options.
const MSDevice_FCDReplay::Trajectory * myTrajectory
MSTransportable & myHolder
The person that stores the device.
MSTransportableDevice(MSTransportable &holder, const std::string &id)
Constructor.
MSStage * getCurrentStage() const
Return the current stage.
virtual bool proceed(MSNet *net, SUMOTime time, const bool vehicleArrived=false)
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const override
Returns the current edge.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers).
Definition OptionsCont.h:89
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static OptionsCont & getOptions()
Retrieves the options.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:62
An error which allows to continue.
Definition TraCIDefs.h:145