62 oc.
addSynonyme(
"device.fcd-replay.files",
"device.fcd-replay.file");
63 oc.
addDescription(
"device.fcd-replay.files",
"FCD Replay Device",
TL(
"FCD files to read"));
65 oc.
addDescription(
"device.fcd-replay.consistency",
"FCD Replay Device",
TL(
"Values to use when replaying ('all' or any combination of 'x', 'y', 'edge', 'lane', 'speed', 'position', 'angle', 'type')"));
74 into.push_back(device);
83 for (
const std::string& attr : oc.
getStringVector(
"device.fcd-replay.consistency")) {
84 if (attr ==
"x" || attr ==
"all") {
87 if (attr ==
"y" || attr ==
"all") {
90 if (attr ==
"edge" || attr ==
"all") {
93 if (attr ==
"lane" || attr ==
"all") {
96 if (attr ==
"speed" || attr ==
"all") {
99 if (attr ==
"position" || attr ==
"pos" || attr ==
"all") {
102 if (attr ==
"angle" || attr ==
"all") {
105 if (attr ==
"type" || attr ==
"all") {
110 if (oc.
isSet(
"device.fcd-replay.files")) {
111 for (
const std::string& filename : oc.
getStringVector(
"device.fcd-replay.files")) {
114 if (!
myParsers.back()->parseFirst(filename)) {
131 bool haveData =
false;
132 for (
int i = 0; i < (int)
myHandlers.size(); i++) {
137 while (
myHandlers[i]->getTime() < t + 2 * inc) {
146 return haveData ? inc : 0;
167 if (it != handler->getTrajectories().end()) {
182 if (v ==
nullptr || te.
time > currentTime) {
204 if (device !=
nullptr && i->second->hasDeparted()) {
205 device->
move(currentTime);
218 OptionsCont::getOptions().getFloat(
"mapmatch.distance"),
240 std::string edgeOrLane;
250 const auto& veh = myPositions.find(xy);
251 if (veh != myPositions.end()) {
252 vehicle = veh->second;
256 myPositions[xy] = id;
262 myTrajectories[id].push_back({myTime, xy, edgeOrLane, pos, speed, angle});
264 if (edge ==
nullptr && edgeOrLane !=
"") {
265 WRITE_WARNINGF(isPerson ?
TL(
"Unknown edge '%' in fcd replay file for person '%'.") :
TL(
"Unknown lane '%' in fcd replay file for vehicle '%'."), edgeOrLane, id);
267 if (myRoutes.count(
id) == 0) {
268 if (edgeOrLane ==
"") {
270 if (lane !=
nullptr) {
271 myTrajectories[id].back().edgeOrLane = lane->
getID();
280 myRoutes[id] = std::make_tuple(myTime, type, isPerson,
ConstMSEdgeVector{edge}, std::vector<StageStart>());
283 if (edge !=
nullptr && !edge->
isInternal() && edge != route.back()) {
284 route.push_back(edge);
287 std::vector<StageStart>& vehicleUsage = std::get<4>(myRoutes[
id]);
288 if ((vehicleUsage.empty() && vehicle !=
"") || (!vehicleUsage.empty() && vehicle != vehicleUsage.back().vehicle)) {
289 vehicleUsage.push_back({vehicle, (int)myTrajectories[
id].size() - 1, (int)std::get<3>(myRoutes[
id]).size() - 1});
301 const std::vector<StageStart>& stages,
const Trajectory& t) {
304 int prevRouteOffset = 0;
305 const MSEdge* start = route.front();
307 for (
const auto& stageStart : stages) {
308 if (stageStart.vehicle != prevVeh) {
309 if (stageStart.trajectoryOffset != 0) {
313 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
316 int offset = stageStart.routeOffset;
329 plan->push_back(
new MSStageDriving(start, prevEdge,
nullptr, -1, 0, {prevVeh}));
332 prevVeh = stageStart.vehicle;
333 prevRouteOffset = stageStart.routeOffset;
339 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
342 int offset = (int)route.size() - 1;
346 if (prevRouteOffset < offset) {
352 plan->push_back(
new MSStageDriving(start, route.back(),
nullptr, -1, 0, {prevVeh}));
361 for (
const MSEdge*
const e : edges) {
363 checkedRoute.push_back(e);
365 const MSEdge* fromEdge = checkedRoute.back();
366 checkedRoute.pop_back();
369 checkedRoute.push_back(fromEdge);
370 checkedRoute.push_back(e);
381 for (
const auto& desc : myRoutes) {
382 const std::string&
id = desc.first;
383 const bool isPerson = std::get<2>(desc.second);
386 if (t.front().time >= intervalStart) {
390 params->
depart = std::get<0>(desc.second);
394 std::string vType = std::get<1>(desc.second);
399 if (vehicleType ==
nullptr) {
403 if (routeEdges.front() ==
nullptr) {
422 if (device ==
nullptr) {
428 const std::string dummyRouteID =
"DUMMY_ROUTE_" + id;
430 ConstMSRoutePtr route = std::make_shared<MSRoute>(dummyRouteID, routeEdges,
true,
nullptr, stops);
434 if (t.front().edgeOrLane !=
"") {
445 if (device ==
nullptr) {
453 if (checkedRoute.size() != routeEdges.size()) {
457 }
else if (t.back().time >= intervalStart) {
461 if (person ==
nullptr) {
470 for (
MSStage*
const stage : *plan) {
471 if (stage->getStageType() == finalStage->
getStageType() && stage->getFromEdge() == finalStage->
getFromEdge()) {
486 if ((
int)checkedRoute.size() != vehicle->
getRoute().
size()) {
498 for (
MSLane* lane : edge->getLanes()) {
500 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
501 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
502 tree->
Insert(cmin, cmax, lane);
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::vector< std::string > StringVector
Definition of a vector of strings.
std::shared_ptr< const MSRoute > ConstMSRoutePtr
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_VTYPE_ID
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
@ GIVEN
The lane is given.
@ GIVEN
The position is given.
std::vector< SUMOVehicleParameter::Stop > StopParVector
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_VEHICLE
description of a vehicle
std::bitset< 96 > SumoXMLAttrMask
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_TIME
trigger: the time of the step
A class that stores a 2D geometrical boundary.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
void updateTrafficObjects(const SUMOTime intervalStart)
void initLaneTree(NamedRTree *tree) override
FCDHandler(const std::string &file)
ConstMSEdgeVector checkRoute(const ConstMSEdgeVector &edges, const SUMOVehicle *const vehicle)
MSTransportable::MSTransportablePlan * makePlan(const SUMOVehicleParameter ¶ms, const ConstMSEdgeVector &route, const std::vector< StageStart > &stages, const Trajectory &t)
void myStartElement(int element, const SUMOSAXAttributes &attrs) override
Called on the opening of a tag.
MSEdge * retrieveEdge(const std::string &id) override
SUMOTime execute(SUMOTime currentTime) override
Executes the command.
A device which replays a vehicle trajectory from an fcd file.
static std::vector< std::unique_ptr< SUMOSAXReader > > myParsers
~MSDevice_FCDReplay()
Destructor.
static void init()
Static intialization.
std::vector< TrajectoryEntry > Trajectory
const Trajectory * myTrajectory
static SUMOTime parseNext(SUMOTime t)
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
MSDevice_FCDReplay(SUMOVehicle &holder, const std::string &id)
Constructor.
static std::vector< std::unique_ptr< FCDHandler > > myHandlers
void move(SUMOTime currentTime)
void setTrajectory(const Trajectory *const t)
static SumoXMLAttrMask myUsedAttributes
bit mask for checking attributes to be used
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCDReplay-options.
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.
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.
A road/street connecting two junctions.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
bool isInternal() const
return whether this edge is an internal edge
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
Representation of a lane in the micro simulation.
double interpolateGeometryPosToLanePos(double geometryPos) const
virtual const PositionVector & getShape(bool) const
MSEdge & getEdge() const
Returns the lane's edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
MSVehicleRouter & getRouterTT(int rngIndex, const Prohibitions &prohibited={}) const
std::string getStoppingPlaceID(const MSLane *lane, const double pos, const SumoXMLTag category) const
Returns the stop of the given category close to the given position.
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
int size() const
Returns the number of edges to pass.
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
virtual const MSEdge * getFromEdge() const
MSStageType getStageType() const
A lane area vehicles can halt at.
virtual MSTransportable * buildPerson(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan, SumoRNG *rng) const
Builds a new person.
MSTransportable * get(const std::string &id) const
Returns the named transportable, if existing.
A device which collects info on the vehicle trip (mainly on departure and arrival)
void setTrajectory(MSDevice_FCDReplay::Trajectory *const t)
MSStage * getNextStage(int offset) const
Return the next (or previous) stage denoted by the offset.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
void removeStage(int next, bool stayInSim=true)
removes the nth next stage
MSDevice * getDevice(const std::type_info &type) const override
Returns a device of the given type if it exists or nullptr if not.
const SUMOVehicleParameter & getParameter() const override
Returns the vehicle's parameter (including departure definition)
void appendStage(MSStage *stage, int next=-1)
Appends the given stage to the current plan.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
void setSpeedMode(int speedMode)
Sets speed-constraining behaviors.
The class responsible for building and deletion of vehicles.
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const VehicleDefinitionSource source=ROUTEFILE, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
virtual void deleteVehicle(SUMOVehicle *v, bool discard=false, bool wasKept=false)
Deletes the vehicle.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
Representation of a vehicle in the micro simulation.
Influencer & getInfluencer()
The car-following model and parameter.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type's vehicle class.
Provides utility functions for matching locations to edges (during route parsing)
const std::string & getID() const
Returns the id.
A RT-tree for efficient storing of SUMO's Named objects.
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
A storage for options typed value containers)
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
double x() const
Returns the x-position.
double y() const
Returns the y-position.
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
double nearest_offset_to_point25D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D projected onto the 3D geometry
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
SAX-handler base for SUMO-files.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
Representation of a vehicle.
virtual bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given edges.
virtual const MSRoute & getRoute() const =0
Returns the current route.
Structure representing possible vehicle parameter.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
double departSpeed
(optional) The initial speed of the vehicle
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
double departPos
(optional) The position the vehicle shall depart from
std::string id
The vehicle's id.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
static int getIndexFromLane(const std::string laneID)
return lane index when given the lane ID
A wrapper for a Command function.
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler, const bool isNet=false, const bool isRoute=false)
Builds a reader and assigns the handler to it.
TRACI_CONST double INVALID_DOUBLE_VALUE