61 oc.
addDescription(
"device.fcd-replay.file",
"FCD Replay Device",
TL(
"FCD file to read"));
70 into.push_back(device);
80 if (oc.
isSet(
"device.fcd-replay.file")) {
81 const std::string& filename = oc.
getString(
"device.fcd-replay.file");
142 if (v ==
nullptr || te.
time > currentTime) {
164 if (device !=
nullptr && i->second->hasDeparted()) {
165 device->
move(currentTime);
178 OptionsCont::getOptions().getFloat(
"mapmatch.distance"),
205 const auto& veh = myPositions.find(xy);
206 if (veh != myPositions.end()) {
207 vehicle = veh->second;
211 myPositions[xy] = id;
213 myTrajectories[id].push_back({myTime, xy, edgeOrLane, pos, speed, angle});
215 if (edge ==
nullptr && edgeOrLane !=
"") {
216 WRITE_WARNINGF(isPerson ?
TL(
"Unknown edge '%' in fcd replay file for person '%'.") :
TL(
"Unknown lane '%' in fcd replay file for vehicle '%'."), edgeOrLane, id);
218 if (myRoutes.count(
id) == 0) {
219 if (edgeOrLane ==
"") {
221 if (lane !=
nullptr) {
222 myTrajectories[id].back().edgeOrLane = lane->
getID();
231 myRoutes[id] = std::make_tuple(myTime, type, isPerson,
ConstMSEdgeVector{edge}, std::vector<StageStart>());
234 if (edge !=
nullptr && !edge->
isInternal() && edge != route.back()) {
235 route.push_back(edge);
238 std::vector<StageStart>& vehicleUsage = std::get<4>(myRoutes[
id]);
239 if ((vehicleUsage.empty() && vehicle !=
"") || (!vehicleUsage.empty() && vehicle != vehicleUsage.back().vehicle)) {
240 vehicleUsage.push_back({vehicle, (int)myTrajectories[
id].size() - 1, (int)std::get<3>(myRoutes[
id]).size() - 1});
253 const std::vector<StageStart>& stages,
const Trajectory& t) {
256 int prevRouteOffset = 0;
257 const MSEdge* start = route.front();
259 for (
const auto& stageStart : stages) {
260 if (stageStart.vehicle != prevVeh) {
261 if (stageStart.trajectoryOffset != 0) {
265 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
268 int offset = stageStart.routeOffset;
281 plan->push_back(
new MSStageDriving(start, prevEdge,
nullptr, -1, 0, {prevVeh}));
284 prevVeh = stageStart.vehicle;
285 prevRouteOffset = stageStart.routeOffset;
291 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
294 int offset = (int)route.size() - 1;
298 if (prevRouteOffset < offset) {
304 plan->push_back(
new MSStageDriving(start, route.back(),
nullptr, -1, 0, {prevVeh}));
313 for (
const MSEdge*
const e : edges) {
315 checkedRoute.push_back(e);
317 const MSEdge* fromEdge = checkedRoute.back();
318 checkedRoute.pop_back();
321 checkedRoute.push_back(fromEdge);
322 checkedRoute.push_back(e);
333 for (
const auto& desc : myRoutes) {
334 const std::string&
id = desc.first;
335 const bool isPerson = std::get<2>(desc.second);
338 if (t.front().time >= intervalStart) {
342 params->
depart = std::get<0>(desc.second);
346 std::string vType = std::get<1>(desc.second);
351 if (vehicleType ==
nullptr) {
354 if (routeEdges.front() ==
nullptr) {
371 if (device ==
nullptr) {
377 const std::string dummyRouteID =
"DUMMY_ROUTE_" + id;
378 const std::vector<SUMOVehicleParameter::Stop> stops;
379 ConstMSRoutePtr route = std::make_shared<MSRoute>(dummyRouteID, routeEdges,
true,
nullptr, stops);
381 throw ProcessError(
"Could not add route '" + dummyRouteID +
"'.");
383 if (t.front().edgeOrLane !=
"") {
394 if (device ==
nullptr) {
402 if (checkedRoute.size() != routeEdges.size()) {
406 }
else if (t.back().time >= intervalStart) {
410 if (person ==
nullptr) {
420 if (stage->getStageType() ==
final->getStageType() && stage->getFromEdge() ==
final->getFromEdge()) {
432 if ((
int)checkedRoute.size() != vehicle->
getRoute().
size()) {
444 for (
MSLane* lane : edge->getLanes()) {
446 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
447 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
448 tree->
Insert(cmin, cmax, lane);
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
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.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_VEHICLE
description of a vehicle
@ 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.
const std::map< std::string, Trajectory > & getTrajectories()
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.
~MSDevice_FCDReplay()
Destructor.
static void init()
Static intialization.
std::vector< TrajectoryEntry > Trajectory
const Trajectory * myTrajectory
static SUMOTime parseNext(SUMOTime t)
static FCDHandler * myHandler
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.
void move(SUMOTime currentTime)
static SUMOSAXReader * myParser
void setTrajectory(const Trajectory *const t)
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.
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.
MSVehicleRouter & getRouterTT(const int rngIndex, const MSEdgeVector &prohibited=MSEdgeVector()) const
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.
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
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
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or nullptr if not.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
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.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
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.
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.
SAX-reader encapsulation containing binary reader.
bool parseFirst(std::string systemID)
Start parsing the given file using parseFirst of myXMLReader.
bool parseNext()
Continue a progressive parse started by parseFirst.
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