 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
50 #define DEBUG_COND (isSelected())
58 std::set<std::string> MSBaseVehicle::myShallTraceMoveReminders;
69 throw ProcessError(
"getPreviousSpeed() is not available for non-MSVehicles.");
78 myCurrEdge(route->begin()),
79 myChosenSpeedFactor(pars->speedFactor < 0 ? speedFactor : pars->speedFactor),
81 myPersonDevice(nullptr),
82 myContainerDevice(nullptr),
83 myDeparture(NOT_YET_DEPARTED),
89 myNumericalID(myCurrentNumericalIndex++)
91 , myTraceMoveReminders(myShallTraceMoveReminders.count(pars->id) > 0)
102 msg =
"Vehicle '" + pars->
id +
"' has no valid route. " + msg;
148 const std::map<int, double>*
151 if (batteryDevice !=
nullptr) {
190 if (source ==
nullptr) {
194 if (sink ==
nullptr) {
201 double firstPos = -1;
204 if (stops.size() > 0) {
207 const bool skipFirst = stops.front() == source && sourcePos < firstPos;
208 const bool skipLast = stops.back() == sink &&
myArrivalPos > lastPos;
212 <<
" source=" << source->
getID() <<
" sourcePos=" << sourcePos <<
" firstPos=" << firstPos <<
" arrivalPos=" <<
myArrivalPos <<
" lastPos=" << lastPos
216 if (stops.size() == 1 && (skipFirst || skipLast)) {
220 stops.erase(stops.begin());
223 stops.erase(stops.end() - 1);
232 if (viaEdge == source || viaEdge == sink) {
235 assert(viaEdge != 0);
237 throw ProcessError(
"Vehicle '" +
getID() +
"' is not allowed on any lane of via edge '" + viaEdge->
getID() +
"'.");
239 stops.push_back(viaEdge);
247 if (into.size() > 0) {
249 edges.insert(edges.end(), into.begin(), into.end());
250 if ((*s)->isTazConnector()) {
251 source = into.back();
257 std::string error =
"Vehicle '" +
getID() +
"' has no valid route from edge '" + source->
getID() +
"' to stop edge '" + (*s)->getID() +
"'.";
262 edges.push_back(source);
267 router.
compute(source, sink,
this, t, edges, silent);
268 if (edges.empty() && silent) {
271 if (!edges.empty() && edges.front()->isTazConnector()) {
272 edges.erase(edges.begin());
274 if (!edges.empty() && edges.back()->isTazConnector()) {
278 const double previousCost = onInit ? routeCost : router.
recomputeCosts(oldEdgesRemaining,
this, t);
279 const double savings = previousCost - routeCost;
309 std::string
id =
getID();
313 if (
myRoute->
getID().find(
"!var#") != std::string::npos) {
318 int oldSize = (int)edges.size();
321 if (origin != *
myCurrEdge && edges.front() == origin) {
323 oldSize = (int)edges.size();
349 if (!
replaceRoute(newRoute, info, onInit, (
int)edges.
size() - oldSize,
false, removeStops)) {
437 if (route ==
nullptr) {
440 start = route->
begin();
446 msg =
"No connection between edge '" + (*e)->getID() +
"' and edge '" + (*(e + 1))->getID() +
"'.";
453 if ((*e)->prohibits(
this)) {
454 msg =
"Edge '" + (*e)->getID() +
"' prohibits.";
465 if (myTraceMoveReminders) {
466 traceMoveReminder(
"add", rem, 0,
true);
476 if (r->first == rem) {
478 if (myTraceMoveReminders) {
479 traceMoveReminder(
"remove", rem, 0,
false);
492 if (rem->first->notifyEnter(*
this, reason, enteredLane)) {
494 if (myTraceMoveReminders) {
495 traceMoveReminder(
"notifyEnter", rem->first, rem->second,
true);
501 if (myTraceMoveReminders) {
502 traceMoveReminder(
"notifyEnter", rem->first, rem->second,
false);
517 const double lastLaneLength = lanes[0]->getLength();
521 WRITE_WARNING(
"Vehicle '" +
getID() +
"' will not be able to arrive at the given position!");
546 for (std::vector<MSLane*>::const_iterator l = lanes.begin(); l != lanes.end(); ++l) {
551 WRITE_WARNING(
"Vehicle '" +
getID() +
"' will not be able to arrive with the given speed!");
566 if (
typeid(*dev) == type) {
595 std::string errorMsg;
599 if (errorMsg !=
"") {
605 std::string errorMsg;
606 if (!
addStop(*i, errorMsg, untilOffset) && !ignoreStopErrors) {
609 if (errorMsg !=
"") {
622 std::vector<std::string>
624 std::vector<std::string> ret;
625 const std::vector<MSTransportable*>& persons =
getPersons();
626 for (std::vector<MSTransportable*>::const_iterator it_p = persons.begin(); it_p != persons.end(); ++it_p) {
627 ret.push_back((*it_p)->getID());
651 const std::vector<MSTransportable*>&
661 const std::vector<MSTransportable*>&
675 if (dev->deviceName() == deviceName) {
686 if (deviceName ==
"rerouting") {
692 assert(routingDevice != 0);
696 throw InvalidArgument(
"Creating device of type '" + deviceName +
"' is not supported");
705 if (dev->deviceName() == deviceName) {
706 return dev->getParameter(key);
709 throw InvalidArgument(
"No device of type '" + deviceName +
"' exists");
716 if (dev->deviceName() == deviceName) {
717 dev->setParameter(key, value);
721 throw InvalidArgument(
"No device of type '" + deviceName +
"' exists");
727 assert(type !=
nullptr);
749 if (lane ==
nullptr) {
760 if (lane ==
nullptr) {
770 MSBaseVehicle::initMoveReminderOutput(
const OptionsCont& oc) {
771 if (oc.
isSet(
"movereminder-output.vehicles")) {
772 const std::vector<std::string> vehicles = oc.
getStringVector(
"movereminder-output.vehicles");
773 myShallTraceMoveReminders.insert(vehicles.begin(), vehicles.end());
779 MSBaseVehicle::traceMoveReminder(
const std::string& type,
MSMoveReminder* rem,
double pos,
bool keep)
const {
static void checkDist(const std::string &id)
Checks the distribution whether it is permanent and deletes it if not.
void vehicleDeparted(const SUMOVehicle &v)
Informs this control about a vehicle's departure.
The car-following model and parameter.
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...
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons)
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
int containerNumber
The static number of containers in the vehicle when it departs.
void release() const
deletes the route if there are no further references to it
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
virtual SUMOTime getWaitingTime() const =0
@ ARRIVAL_POS_GIVEN
The arrival position is given.
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
const std::string & getID() const
Returns the name of the vehicle type.
bool wasSet(int what) const
Returns whether the given parameter was set.
const std::string & getDescription() const
bool hasDeparted() const
Returns whether this vehicle has already departed.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (whe changing color)
A device that performs vehicle rerouting based on current edge speeds.
#define WRITE_WARNING(msg)
int getContainerNumber() const
Returns the number of containers.
Representation of a lane in the micro simulation.
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...
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
virtual ~MSBaseVehicle()
Destructor.
MSBaseVehicle(SUMOVehicleParameter *pars, const MSRoute *route, MSVehicleType *type, const double speedFactor)
Constructor.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
@ ARRIVAL_LANE_GIVEN
The arrival lane is given.
void removeVType(const MSVehicleType *vehType)
Static storage of an output device and its base (abstract) implementation.
@ ARRIVAL_POS_RANDOM
The arrival position is chosen randomly.
SUMOTime myDeparture
The real departure time.
MSRouteIterator end() const
Returns the end of the list of edges to pass.
ConstMSEdgeVector::const_iterator MSRouteIterator
double myChosenSpeedFactor
A precomputed factor by which the driver wants to be faster than the speed limit.
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
const int VEHPARS_FORCE_REROUTE
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
MSInsertionControl & getInsertionControl()
Returns the insertion control.
const MSEdge * getLastEdge() const
returns the destination edge
const MSRoute * myRoute
This vehicle's route.
std::vector< const MSEdge * > ConstMSEdgeVector
bool hasValidRoute(std::string &msg, const MSRoute *route=0) const
Validates the current or given route.
void replaceParameter(const SUMOVehicleParameter *newParameter)
replace the vehicle parameter (deleting the old one)
static OptionsCont & getOptions()
Retrieves the options.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
int myArrivalLane
The destination lane where the vehicle stops.
void setCosts(double costs)
Sets the costs of the route.
int getRoutePosition() const
return index of edge within route
const ConstMSEdgeVector & getEdges() const
virtual const MSEdge * getRerouteOrigin() const
Returns the starting point for reroutes (usually the current edge)
Structure representing possible vehicle parameter.
long long int NumericalID
const RGBColor & getColor() const
Returns the color.
int getRNGIndex() const
returns the associated RNG index
void resetRoutePosition(int index, DepartLaneDefinition departLaneProcedure)
reset index of edge within route
double getMaxSpeed() const
Returns the maximum speed.
void calculateArrivalParams()
(Re-)Calculates the arrival position and lane from the vehicle parameters
Something on a lane to be noticed about vehicle movement.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
virtual const ConstMSEdgeVector getStopEdges(double &firstPos, double &lastPos) const =0
Returns the list of still pending stop edges.
const SUMOVehicleParameter * myParameter
This vehicle's parameter.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
double myArrivalPos
The position on the destination lane where the vehicle stops.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
@ SUMO_TAG_PARKING_ZONE_REROUTE
entry for an alternative parking zone
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
int size() const
Returns the number of edges to pass.
void createDevice(const std::string &deviceName)
create device of the given type
double getOdometer() const
Returns the distance that was already driven by this vehicle.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
virtual void saveState(OutputDevice &out)
Saves the (common) state of a vehicle.
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
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...
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
static bool endsWith(const std::string &str, const std::string suffix)
Checks whether a given string ends with the suffix.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
double getImpatience() const
Returns this vehicles impatience.
bool computeLooped(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time if from == to,...
const std::map< int, double > * getEmissionParameters() const
Returns the vehicle's emission model parameter.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
virtual void addPerson(MSTransportable *person)
Adds a person to this vehicle.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
bool isTazConnector() const
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 MSLane * getLane() const =0
Returns the lane the vehicle is on.
std::string id
The vehicle's id.
virtual bool replaceRoute(const MSRoute *route, const std::string &info, bool onInit=false, int offset=0, bool addStops=true, bool removeStops=true)=0
Replaces the current route by the given one.
double myDepartPos
The real depart position.
double arrivalPos
(optional) The position the vehicle shall arrive on
std::string fromTaz
The vehicle's origin zone (district)
void descheduleDeparture(const SUMOVehicle *veh)
stops trying to emit the given vehicle (and delete it)
Abstract in-vehicle / in-person device.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
int repetitionsDone
The number of times the vehicle was already inserted.
static MSDevice_Transportable * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into, const bool isContainer)
Build devices for the given vehicle, if needed.
A storage for options typed value containers)
A road/street connecting two junctions.
@ DEPART_TRIGGERED
The departure is person triggered.
Battery device for electric vehicles.
virtual double getAcceleration() const
Returns the vehicle's acceleration.
std::string routeid
The vehicle's route id.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
const std::vector< MSLane * > * allowedLanes(const MSEdge &destination, SUMOVehicleClass vclass=SVC_IGNORING) const
Get the allowed lanes to reach the destination-edge.
@ ARRIVAL_SPEED_GIVEN
The speed is given.
void removeTransportable(MSTransportable *transportable)
Remove a passenger (TraCI)
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_ATTR_TIME
trigger: the time of the step
bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true)
Replaces the current route by the given edges.
virtual double getSlope() const
Returns the slope of the road at vehicle's position.
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.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Computes a new route on vehicle insertion.
DepartLaneDefinition
Possible ways to choose a lane on depart.
void addStops(const bool ignoreStopErrors)
Adds stops to the built vehicle.
static SUMOTime gTimeToImpatience
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
const int VEHPARS_SPEEDFACTOR_SET
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
std::vector< std::string > getPersonIDList() const
Returns the list of persons.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSRouteIterator myCurrEdge
Iterator to current route-edge.
void addTransportable(MSTransportable *transportable)
Add a passenger.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
static std::vector< MSTransportable * > myEmptyTransportableVector
bool hasDevice(const std::string &deviceName) const
check whether the vehicle is equiped with a device of the given type
int size() const
Return the number of passengers / containers.
double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
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.
const MSEdge * succEdge(int nSuccs) const
Returns the nSuccs'th successor of edge the vehicle is currently at.
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
int getPersonNumber() const
Returns the number of persons.
const std::vector< SUMOVehicleParameter::Stop > & getStops() const
Returns the stops.
const std::map< int, double > & getEnergyParams() const
retrieve parameters for the energy consumption model
const std::string & getID() const
Returns the name of the vehicle.
virtual bool hasArrived() const
Returns whether this vehicle has already arived (by default this is true if the vehicle has reached i...
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
void addReminder(MSMoveReminder *rem)
Adds a MoveReminder dynamically.
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
MSRouteIterator begin() const
Returns the begin of the list of edges to pass.
void onDepart()
Called when the vehicle is inserted into the network.
double getPreviousSpeed() const
Returns the vehicle's previous speed.
static bool dictionary(const std::string &id, const MSRoute *route)
Adds a route to the dictionary.
static NumericalID myCurrentNumericalIndex
std::mt19937 * getRNG() const
return the associated RNG
void setSavings(double savings)
Sets the savings of the route.
std::string toTaz
The vehicle's destination zone (district)
@ ARRIVAL_POS_CENTER
Half the road length.
void removeReminder(MSMoveReminder *rem)
Removes a MoveReminder dynamically.
void addReference() const
increments the reference counter for the route
void removeTransportable(MSTransportable *t)
removes a person or container
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
void reroute(SUMOTime t, const std::string &info, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, const bool onInit=false, const bool withTaz=false, const bool silent=false)
Performs a rerouting using the given router.
MSVehicleType * myType
This vehicle's type.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
double myOdometer
A simple odometer to keep track of the length of the route already driven.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
static const SUMOTime NOT_YET_DEPARTED
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
virtual void activateReminders(const MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
"Activates" all current move reminder
const std::string & getID() const
Returns the id.
Notification
Definition of a vehicle state.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
void replaceVehicleType(MSVehicleType *type)
Replaces the current vehicle type by the one given.
std::mt19937 * getRNG() const
Abstract in-vehicle device.
virtual void addContainer(MSTransportable *container)
Adds a container to this vehicle.