61 oc.
addDescription(
"device.fcd-replay.file",
"FCD Replay Device",
TL(
"FCD file to read"));
70 into.push_back(device);
79 if (oc.
isSet(
"device.fcd-replay.file")) {
80 const std::string& filename = oc.
getString(
"device.fcd-replay.file");
132 if (v ==
nullptr || te.
time > currentTime) {
149 if (device !=
nullptr && i->second->hasDeparted()) {
150 device->
move(currentTime);
183 const auto& veh = myPositions.find(xy);
184 if (veh != myPositions.end()) {
185 vehicle = veh->second;
189 myPositions[xy] = id;
191 myTrajectories[id].push_back({myTime, xy, edgeOrLane, pos, speed, angle});
193 if (edge !=
nullptr) {
194 if (myRoutes.count(
id) == 0) {
195 myRoutes[id] = std::make_tuple(myTime, type, isPerson,
ConstMSEdgeVector{edge}, std::vector<StageStart>());
198 if (!edge->
isInternal() && edge != route.back()) {
199 route.push_back(edge);
202 std::vector<StageStart>& vehicleUsage = std::get<4>(myRoutes[
id]);
203 if ((vehicleUsage.empty() && vehicle !=
"") || (!vehicleUsage.empty() && vehicle != vehicleUsage.back().vehicle)) {
204 vehicleUsage.push_back({vehicle, (int)myTrajectories[
id].size() - 1, (int)std::get<3>(myRoutes[
id]).size() - 1});
219 myTrajectories.clear();
226 const std::vector<StageStart>& stages,
const Trajectory& t) {
229 int prevRouteOffset = 0;
230 const MSEdge* start = route.front();
232 for (
const auto& stageStart : stages) {
233 if (stageStart.vehicle != prevVeh) {
234 if (stageStart.trajectoryOffset != 0) {
238 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
241 int offset = stageStart.routeOffset;
254 plan->push_back(
new MSStageDriving(start, prevEdge,
nullptr, -1, 0, {prevVeh}));
257 prevVeh = stageStart.vehicle;
258 prevRouteOffset = stageStart.routeOffset;
264 if (prevRouteOffset < (
int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() &
SVC_PEDESTRIAN) == 0) {
267 int offset = (int)route.size() - 1;
271 if (prevRouteOffset < offset) {
277 plan->push_back(
new MSStageDriving(start, route.back(),
nullptr, -1, 0, {prevVeh}));
286 for (
const MSEdge*
const e : edges) {
288 checkedRoute.push_back(e);
290 const MSEdge* fromEdge = checkedRoute.back();
291 checkedRoute.pop_back();
292 if (!
MSNet::getInstance()->getRouterTT(0).compute(fromEdge, e, vehicle, myTime, checkedRoute)) {
294 checkedRoute.push_back(fromEdge);
295 checkedRoute.push_back(e);
306 for (
const auto& desc : myRoutes) {
307 const std::string&
id = desc.first;
308 const bool isPerson = std::get<2>(desc.second);
310 if (t.front().time >= intervalStart) {
314 params->
depart = std::get<0>(desc.second);
318 std::string vType = std::get<1>(desc.second);
323 if (vehicleType ==
nullptr) {
335 if (device ==
nullptr) {
341 const std::string dummyRouteID =
"DUMMY_ROUTE_" + id;
342 const std::vector<SUMOVehicleParameter::Stop> stops;
344 ConstMSRoutePtr route = std::make_shared<MSRoute>(dummyRouteID, routeEdges,
true,
nullptr, stops);
346 throw ProcessError(
"Could not add route '" + dummyRouteID +
"'.");
356 if (device ==
nullptr) {
361 static_cast<MSVehicle*
>(vehicle)->getInfluencer().setSpeedMode(0);
365 if (checkedRoute.size() != routeEdges.size()) {
369 }
else if (t.back().time >= intervalStart) {
379 if (stage->getStageType() == final->getStageType() && stage->getFromEdge() == final->getFromEdge()) {
392 if ((
int)checkedRoute.size() != vehicle->
getRoute().
size()) {
std::vector< const MSEdge * > ConstMSEdgeVector
std::shared_ptr< const MSRoute > ConstMSRoutePtr
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_VTYPE_ID
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PEDESTRIAN
pedestrian
@ GIVEN
The lane 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
const double INVALID_DOUBLE
invalid double
void updateTrafficObjects(const SUMOTime intervalStart)
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)
Called on the opening of a tag.
SUMOTime execute(SUMOTime currentTime)
Executes the command.
A device which replays a vehicle trajectory from an fcd file.
~MSDevice_FCDReplay()
Destructor.
static FCDHandler myHandler
static void init()
Static intialization.
std::vector< TrajectoryEntry > Trajectory
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.
void move(SUMOTime currentTime)
static SUMOSAXReader * myParser
Trajectory * myTrajectory
void setTrajectory(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.
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....
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
void add(SUMOVehicle *veh)
Adds a single vehicle for departure.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
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.
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
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)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
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.
The class responsible for building and deletion of vehicles.
virtual SUMOVehicle * buildVehicle(SUMOVehicleParameter *defs, ConstMSRoutePtr route, MSVehicleType *type, const bool ignoreStopErrors, const bool fromRouteFile=true, bool addRouteStops=true)
Builds a vehicle, increases the number of built vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
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.
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.
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.
const std::string & getID() const
Returns the id.
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.
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-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 MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
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.
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.