56 std::set<std::string> MSBaseVehicle::myShallTraceMoveReminders;
65 throw ProcessError(
"getPreviousSpeed() is not available for non-MSVehicles.");
83 , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
92 for (std::vector< MSDevice* >::iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
101 throw ProcessError(
"Vehicle '" + pars->
id +
"' has no valid route. " + msg);
113 for (std::vector< MSDevice* >::iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
174 assert(viaEdge != 0);
176 throw ProcessError(
"Vehicle '" +
getID() +
"' is not allowed on any lane of via edge '" + viaEdge->
getID() +
"'.");
178 stops.push_back(viaEdge);
186 router.
compute(source, *s,
this, t, into);
187 if (into.size() > 0) {
189 edges.insert(edges.end(), into.begin(), into.end());
191 std::string error =
"Vehicle '" +
getID() +
"' has no valid route from edge '" + source->
getID() +
"' to stop edge '" + (*s)->getID() +
"'.";
196 edges.push_back(source);
202 router.
compute(source, sink,
this, t, edges);
203 if (!edges.empty() && edges.front()->isTazConnector()) {
204 edges.erase(edges.begin());
206 if (!edges.empty() && edges.back()->isTazConnector()) {
233 std::string
id =
getID();
237 if (
myRoute->
getID().find(
"!var#") != std::string::npos) {
242 int oldSize = (int)edges.size();
245 if (origin != *
myCurrEdge && edges.front() == origin) {
247 oldSize = (int)edges.size();
270 if (!
replaceRoute(newRoute, onInit, (
int)edges.
size() - oldSize,
false, removeStops)) {
312 throw ProcessError(
"Person '" + person->
getID() +
"' cannot ride in vehicle '" +
getID() +
"' in the mesoscopic simulation.");
317 throw ProcessError(
"Container '" + container->
getID() +
"' cannot ride in vehicle '" +
getID() +
"' in the mesoscopic simulation.");
326 start = route->
begin();
332 msg =
"No connection between edge '" + (*e)->getID() +
"' and edge '" + (*(e + 1))->getID() +
"'.";
339 if ((*e)->prohibits(
this)) {
340 msg =
"Edge '" + (*e)->getID() +
"' prohibits.";
351 if (myTraceMoveReminders) {
352 traceMoveReminder(
"add", rem, 0,
true);
362 if (r->first == rem) {
364 if (myTraceMoveReminders) {
365 traceMoveReminder(
"remove", rem, 0,
false);
378 if (rem->first->notifyEnter(*
this, reason, enteredLane)) {
380 if (myTraceMoveReminders) {
381 traceMoveReminder(
"notifyEnter", rem->first, rem->second,
true);
387 if (myTraceMoveReminders) {
388 traceMoveReminder(
"notifyEnter", rem->first, rem->second,
false);
403 const double lastLaneLength = lanes[0]->getLength();
407 WRITE_WARNING(
"Vehicle '" +
getID() +
"' will not be able to arrive at the given position!");
429 for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
434 WRITE_WARNING(
"Vehicle '" +
getID() +
"' will not be able to arrive with the given speed!");
448 for (std::vector<MSDevice*>::const_iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
449 if (
typeid(**dev) == type) {
475 std::string errorMsg;
479 if (errorMsg !=
"") {
485 std::string errorMsg;
486 if (!
addStop(*i, errorMsg, untilOffset) && !ignoreStopErrors) {
489 if (errorMsg !=
"") {
498 for (std::vector<MSDevice* >::const_iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
499 if ((*dev)->deviceName() == deviceName) {
510 if (deviceName ==
"rerouting") {
516 assert(routingDevice != 0);
520 throw InvalidArgument(
"Creating device of type '" + deviceName +
"' is not supported");
528 for (std::vector<MSDevice* >::const_iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
529 if ((*dev)->deviceName() == deviceName) {
530 return (*dev)->getParameter(key);
533 throw InvalidArgument(
"No device of type '" + deviceName +
"' exists");
539 for (std::vector<MSDevice* >::iterator dev =
myDevices.begin(); dev !=
myDevices.end(); ++dev) {
540 if ((*dev)->deviceName() == deviceName) {
541 (*dev)->setParameter(key, value);
545 throw InvalidArgument(
"No device of type '" + deviceName +
"' exists");
571 MSBaseVehicle::initMoveReminderOutput(
const OptionsCont& oc) {
572 if (oc.
isSet(
"movereminder-output.vehicles")) {
573 const std::vector<std::string> vehicles = oc.
getStringVector(
"movereminder-output.vehicles");
574 myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
580 MSBaseVehicle::traceMoveReminder(
const std::string& type,
MSMoveReminder* rem,
double pos,
bool keep)
const {
virtual bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, bool collision=false, ConstMSEdgeVector::const_iterator *searchStart=0)=0
Adds a stop.
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
const int VEHPARS_FORCE_REROUTE
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
const ConstMSEdgeVector & getEdges() const
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
bool hasDeparted() const
Returns whether this vehicle has already departed.
void release() const
deletes the route if there are no further references to it
void setDeviceParameter(const std::string &deviceName, const std::string &key, const std::string &value)
try to set the given parameter from any of the vehicles devices, raise InvalidArgument if no device p...
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
virtual bool replaceRoute(const MSRoute *route, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double myArrivalPos
The position on the destination lane where the vehicle stops.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
Notification
Definition of a vehicle state.
A device that performs vehicle rerouting based on current edge speeds.
int repetitionsDone
The number of times the vehicle was already inserted.
virtual bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E *> &into)=0
Builds the route between the given edges using the minimum effort at the given time The definition of...
const RGBColor & getColor() const
Returns the color.
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
virtual ~MSBaseVehicle()
Destructor.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
const MSRoute * myRoute
This vehicle's route.
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 MSEdge * getLastEdge() const
returns the destination edge
std::vector< const MSEdge * > ConstMSEdgeVector
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
int myArrivalLane
The destination lane where the vehicle stops.
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
const std::string & getID() const
Returns the id.
The arrival position is given.
int size() const
Returns the number of edges to pass.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
#define WRITE_WARNING(msg)
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
The car-following model and parameter.
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
static OptionsCont & getOptions()
Retrieves the options.
std::string toTaz
The vehicle's destination zone (district)
std::string getDeviceParameter(const std::string &deviceName, const std::string &key) const
try to retrieve the given parameter from any of the vehicles devices, raise InvalidArgument if no dev...
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
double getMaxSpeed() const
Returns the maximum speed.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
A road/street connecting two junctions.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static SUMOTime gTimeToImpatience
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
double myDepartPos
The real depart position.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
void createDevice(const std::string &deviceName)
create device of the given type
std::string routeid
The vehicle's route id.
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
ConstMSEdgeVector::const_iterator MSRouteIterator
void removeVType(const MSVehicleType *vehType)
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
SUMOTime depart
The vehicle's departure time.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag tag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
std::vector< std::string > getStringVector(const std::string &name) const
Returns the list of string-vector-value of the named option (only for Option_String) ...
const std::string & getID() const
returns the id of the transportable
std::string fromTaz
The vehicle's origin zone (district)
bool replaceRouteEdges(ConstMSEdgeVector &edges, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
double getImpatience() const
Returns this vehicles impatience.
virtual const ConstMSEdgeVector getStopEdges() const =0
Returns the list of still pending stop edges.
Something on a lane to be noticed about vehicle movement.
double arrivalPos
(optional) The position the vehicle shall arrive on
std::vector< std::string > via
List of the via-edges the vehicle must visit.
Abstract in-vehicle device.
trigger: the time of the step
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
The vehicle has departed (was inserted into the network)
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
Structure representing possible vehicle parameter.
MSDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isTazConnector() const
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
virtual double getAcceleration() const
Returns the vehicle's acceleration.
const std::string & getDescription() const
MSInsertionControl & getInsertionControl()
Returns the insertion control.
MSVehicleType * myType
This vehicle's type.
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
void onDepart()
Called when the vehicle is inserted into the network.
virtual double getSlope() const
Returns the slope of the road at vehicle's position.
A storage for options typed value containers)
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
const std::string & getID() const
Returns the name of the vehicle type.
The arrival lane is given.
void addReference() const
increments the reference counter for the route
int myNumberReroutes
The number of reroutings.
virtual SUMOTime getWaitingTime() const =0
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
bool notifyEnter(SUMOVehicle &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
bool wasSet(int what) const
Returns whether the given parameter was set.
Static storage of an output device and its base (abstract) implementation.
bool closeTag()
Closes the most recently opened tag.
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
MSRouteIterator myCurrEdge
Iterator to current route-edge.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
void reroute(SUMOTime t, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false)
Performs a rerouting using the given router.
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const std::string & getID() const
Returns the name of the vehicle.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
Representation of a lane in the micro simulation.
std::vector< MSDevice * > myDevices
The devices this vehicle has.
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
virtual void addContainer(MSTransportable *container)
Adds a container to this vehicle.
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
double getPreviousSpeed() const
Returns the vehicle's previous speed.
SUMOTime myDeparture
The real departure time.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
static const SUMOTime NOT_YET_DEPARTED
std::string id
The vehicle's id.
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit. ...
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
The arrival position is chosen randomly.