Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_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-2026 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 <utils/geom/Position.h>
26#include <utils/xml/XMLSubSys.h>
27#include <libsumo/Vehicle.h>
28#include <microsim/MSNet.h>
29#include <microsim/MSEdge.h>
30#include <microsim/MSLane.h>
31#include <microsim/MSRoute.h>
39#include "MSDevice_FCDReplay.h"
40
41
42// ===========================================================================
43// static member initializations
44// ===========================================================================
45std::vector<std::unique_ptr<MSDevice_FCDReplay::FCDHandler> > MSDevice_FCDReplay::myHandlers;
46std::vector<std::unique_ptr<SUMOSAXReader> > MSDevice_FCDReplay::myParsers;
48
49
50// ===========================================================================
51// method definitions
52// ===========================================================================
53// ---------------------------------------------------------------------------
54// static initialisation methods
55// ---------------------------------------------------------------------------
56void
58 oc.addOptionSubTopic("FCD Replay Device");
59 insertDefaultAssignmentOptions("fcd-replay", "FCD Replay Device", oc);
60
61 oc.doRegister("device.fcd-replay.files", new Option_FileName());
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"));
64 oc.doRegister("device.fcd-replay.consistency", new Option_StringVector(StringVector({ "all" })));
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')"));
66}
67
68
69void
70MSDevice_FCDReplay::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
72 if (equippedByDefaultAssignmentOptions(oc, "fcd-replay", v, oc.isSet("device.fcd-replay.files"))) {
73 MSDevice_FCDReplay* device = new MSDevice_FCDReplay(v, "fcdReplay_" + v.getID());
74 into.push_back(device);
75 }
76}
77
78
79void
82 myUsedAttributes.reset();
83 for (const std::string& attr : oc.getStringVector("device.fcd-replay.consistency")) {
84 if (attr == "x" || attr == "all") {
86 }
87 if (attr == "y" || attr == "all") {
89 }
90 if (attr == "edge" || attr == "all") {
92 }
93 if (attr == "lane" || attr == "all") {
95 }
96 if (attr == "speed" || attr == "all") {
98 }
99 if (attr == "position" || attr == "pos" || attr == "all") {
101 }
102 if (attr == "angle" || attr == "all") {
104 }
105 if (attr == "type" || attr == "all") {
107 }
108 }
109 myParsers.clear();
110 myHandlers.clear();
111 if (oc.isSet("device.fcd-replay.files")) {
112 for (const std::string& filename : oc.getStringVector("device.fcd-replay.files")) {
113 myHandlers.push_back(std::unique_ptr<MSDevice_FCDReplay::FCDHandler>(new MSDevice_FCDReplay::FCDHandler(filename)));
114 myParsers.push_back(std::unique_ptr<SUMOSAXReader>(XMLSubSys::getSAXReader(*myHandlers.back())));
115 if (!myParsers.back()->parseFirst(filename)) {
116 throw ProcessError(TLF("Can not read XML-file '%'.", filename));
117 }
118 }
119 const SUMOTime inc = parseNext(SIMSTEP);
121 if (inc > 0) {
123 SIMSTEP + inc);
124 }
125 }
126}
127
128
131 SUMOTime inc = string2time(OptionsCont::getOptions().getString("route-steps"));
132 bool haveData = false;
133 for (int i = 0; i < (int)myHandlers.size(); i++) {
134 if (myParsers[i] != nullptr) {
135 haveData = true;
136 // make sure that we have always at least inc time steps buffered, so at time 200 we will parse 400 to 600
137 const SUMOTime start = myHandlers[i]->getTime();
138 while (myHandlers[i]->getTime() < t + 2 * inc) {
139 if (!myParsers[i]->parseNext()) {
140 myParsers[i] = nullptr;
141 myHandlers[i]->setFinished();
142 break;
143 }
144 }
145 myHandlers[i]->updateTrafficObjects(start);
146 }
147 }
148 return haveData ? inc : 0;
149}
150
151
152// ---------------------------------------------------------------------------
153// MSDevice_FCDReplay-methods
154// ---------------------------------------------------------------------------
156 MSVehicleDevice(holder, id) {
157}
158
159
162
163
164bool
166 if (myTrajectory == nullptr) {
167 for (auto& handler : myHandlers) {
168 auto it = handler->getTrajectories().find(myHolder.getID());
169 if (it != handler->getTrajectories().end()) {
170 setTrajectory(&it->second, handler.get(), false);
171 break;
172 }
173 }
174 if (myTrajectory == nullptr) {
175 return false;
176 }
177 }
178 if (myTrajectoryIndex == (int)myTrajectory->size()) {
179 // The reader may still append samples to this trajectory.
181 }
182 MSVehicle* v = dynamic_cast<MSVehicle*>(&myHolder);
183 // Apply the latest position due at this simulation step when the recording
184 // has a finer time resolution than the replay.
185 while (myTrajectoryIndex + 1 < (int)myTrajectory->size()
186 && myTrajectory->at(myTrajectoryIndex + 1).time <= currentTime) {
188 }
190 if (v == nullptr || te.time > currentTime) {
191 return false;
192 }
193 if (te.edgeOrLane != "") {
194 const std::string& edgeID = SUMOXMLDefinitions::getEdgeIDFromLane(te.edgeOrLane);
195 const int laneIdx = SUMOXMLDefinitions::getIndexFromLane(te.edgeOrLane);
196 libsumo::Vehicle::moveToXY(myHolder.getID(), edgeID, laneIdx, te.pos.x(), te.pos.y(), te.angle, 7);
197 } else if (te.pos.x() != libsumo::INVALID_DOUBLE_VALUE) {
198 libsumo::Vehicle::moveToXY(myHolder.getID(), "", -1, te.pos.x(), te.pos.y(), te.angle, 0);
199 }
201 libsumo::Vehicle::setSpeed(myHolder.getID(), te.speed);
202 // libsumo::Vehicle::changeLane(myHolder.getID(), laneIdx, TS);
204 return false;
205}
206
207
211 std::vector<std::string> finished;
212 for (MSVehicleControl::constVehIt i = c.loadedVehBegin(); i != c.loadedVehEnd(); ++i) {
213 MSDevice_FCDReplay* device = static_cast<MSDevice_FCDReplay*>(i->second->getDevice(typeid(MSDevice_FCDReplay)));
214 if (device != nullptr && i->second->hasDeparted() && device->move(currentTime)) {
215 finished.push_back(i->first);
216 }
217 }
218 for (const std::string& id : finished) {
219 libsumo::Vehicle::remove(id, libsumo::REMOVE_ARRIVED);
220 }
221 return DELTA_T;
222}
223
224
225// ---------------------------------------------------------------------------
226// MSDevice_FCDReplay::FCDHandler-methods
227// ---------------------------------------------------------------------------
229 SUMOSAXHandler(file),
230 MapMatcher(false, false,
231 OptionsCont::getOptions().getFloat("mapmatch.distance"),
232 MsgHandler::getErrorInstance()) {}
233
234
235void
237 bool ok = true;
238 switch (element) {
240 myTime = attrs.getSUMOTimeReporting(SUMO_ATTR_TIME, "", ok);
241 myPositions.clear();
242 return;
243 case SUMO_TAG_VEHICLE:
244 case SUMO_TAG_PERSON:
245 if (myTime >= SIMSTEP) {
246 const bool isPerson = element == SUMO_TAG_PERSON;
247 const std::string id = attrs.getString(SUMO_ATTR_ID);
248 auto getOptDouble = [&](const SumoXMLAttr attr) {
249 return myUsedAttributes.test(attr) ? attrs.getOpt<double>(attr, id.c_str(), ok, libsumo::INVALID_DOUBLE_VALUE) : libsumo::INVALID_DOUBLE_VALUE;
250 };
251 const Position xy = Position(getOptDouble(SUMO_ATTR_X), getOptDouble(SUMO_ATTR_Y));
252 const std::string type = myUsedAttributes.test(SUMO_ATTR_TYPE) ? attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "") : "";
253 std::string edgeOrLane;
255 edgeOrLane = attrs.getOpt<std::string>(isPerson ? SUMO_ATTR_EDGE : SUMO_ATTR_LANE, id.c_str(), ok, "");
256 }
257 const double speed = getOptDouble(SUMO_ATTR_SPEED);
258 const double pos = getOptDouble(SUMO_ATTR_POSITION);
259 const double angle = getOptDouble(SUMO_ATTR_ANGLE);
260 std::string vehicle = attrs.getOpt<std::string>(SUMO_ATTR_VEHICLE, id.c_str(), ok, "");
261 if (isPerson) {
262 if (vehicle == "") {
263 const auto& veh = myPositions.find(xy);
264 if (veh != myPositions.end()) {
265 vehicle = veh->second;
266 }
267 }
268 } else {
269 myPositions[xy] = id;
270 }
271 if (!ok) {
272 WRITE_WARNING("Invalid FCD data.");
273 return;
274 }
275 myTrajectories[id].push_back({myTime, xy, edgeOrLane, pos, speed, angle});
276 const MSEdge* edge = MSEdge::dictionary(isPerson ? edgeOrLane : SUMOXMLDefinitions::getEdgeIDFromLane(edgeOrLane));
277 if (edge == nullptr && edgeOrLane != "") {
278 WRITE_WARNINGF(isPerson ? TL("Unknown edge '%' in fcd replay file for person '%'.") : TL("Unknown lane '%' in fcd replay file for vehicle '%'."), edgeOrLane, id);
279 }
280 if (myRoutes.count(id) == 0) {
281 if (edgeOrLane == "") {
282 const MSLane* const lane = getClosestLane(xy, SVC_PASSENGER);
283 if (lane != nullptr) {
284 myTrajectories[id].back().edgeOrLane = lane->getID();
285 myTrajectories[id].back().lanePos = lane->interpolateGeometryPosToLanePos(
286 lane->getShape().nearest_offset_to_point25D(xy, false));
287 edge = &lane->getEdge();
288 while (edge->isInternal()) { // we cannot use an internal edge for a route
289 edge = edge->getSuccessors().front();
290 }
291 }
292 }
293 myRoutes[id] = std::make_tuple(myTime, type, isPerson, ConstMSEdgeVector{edge}, std::vector<StageStart>());
294 } else {
295 ConstMSEdgeVector& route = std::get<3>(myRoutes[id]);
296 if (edge != nullptr && !edge->isInternal() && edge != route.back()) {
297 route.push_back(edge);
298 }
299 }
300 std::vector<StageStart>& vehicleUsage = std::get<4>(myRoutes[id]);
301 if ((vehicleUsage.empty() && vehicle != "") || (!vehicleUsage.empty() && vehicle != vehicleUsage.back().vehicle)) {
302 vehicleUsage.push_back({vehicle, (int)myTrajectories[id].size() - 1, (int)std::get<3>(myRoutes[id]).size() - 1});
303 }
304 }
305 return;
306 default:
307 break;
308 }
309}
310
311
314 const std::vector<StageStart>& stages, const Trajectory& t) {
316 plan->push_back(new MSStageWaiting(route.front(), nullptr, 0, params.depart, params.departPos, "awaiting departure", true));
317 int prevRouteOffset = 0;
318 const MSEdge* start = route.front();
319 std::string prevVeh;
320 for (const auto& stageStart : stages) {
321 if (stageStart.vehicle != prevVeh) {
322 if (stageStart.trajectoryOffset != 0) {
323 const MSEdge* prevEdge = MSEdge::dictionary(t[stageStart.trajectoryOffset - 1].edgeOrLane);
324 if (prevVeh == "") {
325 MSStoppingPlace* finalStop = nullptr;
326 if (prevRouteOffset < (int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() & SVC_PEDESTRIAN) == 0) {
327 prevRouteOffset++; // skip the access
328 }
329 int offset = stageStart.routeOffset;
330 if (offset < (int)route.size() - 1 && (route[offset]->getPermissions() & SVC_PEDESTRIAN) == SVC_PEDESTRIAN) {
331 offset++; // a bus stop or two consecutive walks so include the edge in both
332 } else {
333 // may have an access, let's find the stop
334 const std::string& stop = MSNet::getInstance()->getStoppingPlaceID(route[offset]->getLanes()[0], t[stageStart.trajectoryOffset].lanePos, SUMO_TAG_BUS_STOP);
335 if (stop != "") {
337 }
338 }
339 ConstMSEdgeVector subRoute = ConstMSEdgeVector(route.begin() + prevRouteOffset, route.begin() + offset);
340 plan->push_back(new MSStageWalking(params.id, subRoute, finalStop, -1, params.departSpeed, params.departPos, 0, 0));
341 } else {
342 plan->push_back(new MSStageDriving(start, prevEdge, nullptr, -1, 0, {prevVeh}));
343 }
344 start = MSEdge::dictionary(t[stageStart.trajectoryOffset].edgeOrLane);
345 prevVeh = stageStart.vehicle;
346 prevRouteOffset = stageStart.routeOffset;
347 }
348 }
349 }
350 // final stage
351 if (prevVeh == "") {
352 if (prevRouteOffset < (int)route.size() - 1 && (route[prevRouteOffset]->getPermissions() & SVC_PEDESTRIAN) == 0) {
353 prevRouteOffset++;
354 }
355 int offset = (int)route.size() - 1;
356 if ((route[offset]->getPermissions() & SVC_PEDESTRIAN) == SVC_PEDESTRIAN) {
357 offset++;
358 }
359 if (prevRouteOffset < offset) {
360 // otherwise we may be still in a vehicle or in access, skip the stage for now
361 ConstMSEdgeVector subRoute = ConstMSEdgeVector(route.begin() + prevRouteOffset, route.begin() + offset);
362 plan->push_back(new MSStageWalking(params.id, subRoute, nullptr, -1, params.departSpeed, params.departPos, 0, 0));
363 }
364 } else {
365 plan->push_back(new MSStageDriving(start, route.back(), nullptr, -1, 0, {prevVeh}));
366 }
367 return plan;
368}
369
370
373 ConstMSEdgeVector checkedRoute;
374 for (const MSEdge* const e : edges) {
375 if (checkedRoute.empty() || checkedRoute.back()->isConnectedTo(*e, vehicle->getVehicleType().getVehicleClass())) {
376 checkedRoute.push_back(e);
377 } else {
378 const MSEdge* fromEdge = checkedRoute.back();
379 checkedRoute.pop_back();
380 if (!MSNet::getInstance()->getRouterTT(0).compute(fromEdge, e, vehicle, myTime, checkedRoute)) {
381 // TODO maybe warn about disconnected route
382 checkedRoute.push_back(fromEdge);
383 checkedRoute.push_back(e);
384 }
385 // TODO check whether we introduced a big detour
386 }
387 }
388 return checkedRoute;
389}
390
391
392void
394 for (const auto& desc : myRoutes) {
395 const std::string& id = desc.first;
396 const bool isPerson = std::get<2>(desc.second);
397 const ConstMSEdgeVector& routeEdges = std::get<3>(desc.second);
398 Trajectory& t = myTrajectories[id];
399 if (t.front().time >= intervalStart) {
400 // new vehicle or person
402 params->id = id;
403 params->depart = std::get<0>(desc.second);
404 params->departPos = t.front().lanePos;
405 params->departSpeed = t.front().speed;
406 // params->arrivalPos = t.back().lanePos;
407 std::string vType = std::get<1>(desc.second);
408 if (vType == "") {
409 vType = isPerson ? DEFAULT_PEDTYPE_ID : DEFAULT_VTYPE_ID;
410 }
412 if (vehicleType == nullptr) {
413 delete params;
414 throw ProcessError(TLF("Unknown vType '%'.", vType));
415 }
416 if (routeEdges.front() == nullptr) {
417 if (isPerson) {
418 WRITE_WARNINGF(TL("No edge in fcd replay file for person '%' at time %."), id, time2string(t.front().time));
419 } else {
420 WRITE_WARNINGF(TL("No lane in fcd replay file for vehicle '%' at time %."), id, time2string(t.front().time));
421 }
422 delete params;
423 continue;
424 }
425 if (isPerson) {
426 MSTransportable::MSTransportablePlan* plan = makePlan(*params, routeEdges, std::get<4>(desc.second), t);
427 // plan completed, now build the person
428 MSTransportable* person = MSNet::getInstance()->getPersonControl().buildPerson(params, vehicleType, plan, nullptr);
430 if (!MSNet::getInstance()->getPersonControl().add(person)) {
431 delete person;
432 throw ProcessError(TLF("Duplicate person '%'.", id));
433 }
435 if (device == nullptr) { // Person did not get a replay device
436 delete person;
437 continue;
438 }
439 device->setTrajectory(&t);
440 } else {
441 const std::string dummyRouteID = "DUMMY_ROUTE_" + id;
442 const StopParVector stops;
443 ConstMSRoutePtr route = std::make_shared<MSRoute>(dummyRouteID, routeEdges, true, nullptr, stops);
444 if (!MSRoute::dictionary(dummyRouteID, route)) {
445 throw ProcessError(TLF("Could not add route '%'.", dummyRouteID));
446 }
447 if (t.front().edgeOrLane != "") {
450 params->departLane = SUMOXMLDefinitions::getIndexFromLane(t.front().edgeOrLane);
451 }
453 if (!MSNet::getInstance()->getVehicleControl().addVehicle(id, vehicle)) {
454 throw ProcessError(TLF("Duplicate vehicle '%'.", id));
455 }
457 MSDevice_FCDReplay* device = static_cast<MSDevice_FCDReplay*>(vehicle->getDevice(typeid(MSDevice_FCDReplay)));
458 if (device == nullptr) { // Vehicle did not get a replay device
460 continue;
461 }
462 device->setTrajectory(&t, this, true);
463
464 // repair the route, cannot do this on parsing because a vehicle is needed
465 ConstMSEdgeVector checkedRoute = checkRoute(routeEdges, vehicle);
466 if (checkedRoute.size() != routeEdges.size()) {
467 vehicle->replaceRouteEdges(checkedRoute, -1, 0, "FCDReplay", true);
468 }
469 }
470 } else if (t.back().time >= intervalStart) {
471 // new data for existing person / vehicle
472 if (isPerson) {
474 if (person == nullptr) {
475 // TODO this should not happen
476 continue;
477 }
478 // TODO optimize: no need to regenerate the whole plan
479 MSTransportable::MSTransportablePlan* plan = makePlan(person->getParameter(), routeEdges, std::get<4>(desc.second), t);
480 const int stageIndex = person->getNumRemainingStages() - 1;
481 const MSStage* const finalStage = person->getNextStage(stageIndex);
482 bool append = false;
483 for (MSStage* const stage : *plan) {
484 if (stage->getStageType() == finalStage->getStageType() && stage->getFromEdge() == finalStage->getFromEdge()) {
485 // TODO: circular plans?
486 append = true;
487 }
488 if (append) {
489 person->appendStage(stage);
490 } else {
491 delete stage;
492 }
493 }
494 person->removeStage(stageIndex);
495 delete plan;
496 } else {
498 ConstMSEdgeVector checkedRoute = checkRoute(routeEdges, vehicle);
499 if ((int)checkedRoute.size() != vehicle->getRoute().size()) {
500 vehicle->replaceRouteEdges(checkedRoute, -1, 0, "FCDReplay", true);
501 }
502 }
503 }
504 }
505}
506
507
508void
510 for (const auto& edge : MSEdge::getAllEdges()) {
511 for (MSLane* lane : edge->getLanes()) {
512 Boundary b = lane->getShape().getBoxBoundary();
513 const float cmin[2] = {(float) b.xmin(), (float) b.ymin()};
514 const float cmax[2] = {(float) b.xmax(), (float) b.ymax()};
515 tree->Insert(cmin, cmax, lane);
516 }
517 }
518}
519
520
521MSEdge*
523 return MSEdge::dictionary(id);
524}
525
526
527/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:75
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
#define TLF(string,...)
Definition MsgHandler.h:318
std::vector< std::string > StringVector
Definition of a vector of strings.
Definition Option.h:42
std::shared_ptr< const MSRoute > ConstMSRoutePtr
Definition Route.h:32
SUMOTime DELTA_T
Definition SUMOTime.cpp:39
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:47
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:107
#define SIMSTEP
Definition SUMOTime.h:69
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_TIMESTEP
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_PERSON
std::bitset< 96 > SumoXMLAttrMask
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_Y
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_X
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_VEHICLE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
@ SUMO_ATTR_TIME
trigger: the time of the step
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
PositionVector getShape(const bool closeShape) const
get position vector (shape) based on this boundary
Definition Boundary.cpp:444
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
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 &params, 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
const FCDHandler * myTrajectorySource
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
bool move(SUMOTime currentTime)
Returns true when a replay-created vehicle has finished its recording.
void setTrajectory(const Trajectory *t, const FCDHandler *source, bool replayCreated)
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.
Definition MSDevice.cpp:181
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:213
A road/street connecting two junctions.
Definition MSEdge.h:78
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
Definition MSEdge.cpp:1157
bool isInternal() const
return whether this edge is an internal edge
Definition MSEdge.h:270
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....
Definition MSEdge.cpp:1117
const MSEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
Definition MSEdge.cpp:1342
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.
Definition MSLane.h:84
double interpolateGeometryPosToLanePos(double geometryPos) const
Definition MSLane.h:567
virtual const PositionVector & getShape(bool) const
Definition MSLane.h:294
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:790
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:201
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:496
MSVehicleRouter & getRouterTT(int rngIndex, const Prohibitions &prohibited={}) const
Definition MSNet.cpp:1659
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.
Definition MSNet.cpp:1548
MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Returns the named stopping place of the given category.
Definition MSNet.cpp:1527
MSInsertionControl & getInsertionControl()
Returns the insertion control.
Definition MSNet.h:456
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:403
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition MSNet.cpp:1317
int size() const
Returns the number of edges to pass.
Definition MSRoute.cpp:85
static bool dictionary(const std::string &id, ConstMSRoutePtr route)
Adds a route to the dictionary.
Definition MSRoute.cpp:116
virtual const MSEdge * getFromEdge() const
Definition MSStage.cpp:77
MSStageType getStageType() const
Definition MSStage.h:138
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.
Definition MSVehicle.h:77
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)
Definition MapMatcher.h:45
const std::string & getID() const
Returns the id.
Definition Named.h:73
A RT-tree for efficient storing of SUMO's Named objects.
Definition NamedRTree.h:61
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition NamedRTree.h:79
A storage for options typed value containers)
Definition OptionsCont.h:92
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.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:52
double y() const
Returns the y-position.
Definition Position.h:57
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.
Definition SUMOVehicle.h:63
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
TRACI_CONST int REMOVE_ARRIVED
SUMOTime time
double angle
std::string edgeOrLane
Position pos
double speed