60 oc.
addDescription(
"device.stationfinder.rescueTime",
"Battery",
TL(
"Time to wait for a rescue vehicle on the road side when the battery is empty"));
62 oc.
addDescription(
"device.stationfinder.rescueAction",
"Battery",
TL(
"How to deal with a vehicle which has to stop due to low battery: [none, remove, tow]"));
64 oc.
addDescription(
"device.stationfinder.reserveFactor",
"Battery",
TL(
"Scale battery need with this factor to account for unexpected traffic situations"));
66 oc.
addDescription(
"device.stationfinder.emptyThreshold",
"Battery",
TL(
"Battery percentage to go into rescue mode"));
68 oc.
addDescription(
"device.stationfinder.radius",
"Battery",
TL(
"Search radius in travel time seconds"));
70 oc.
addDescription(
"device.stationfinder.maxEuclideanDistance",
"Battery",
TL(
"Euclidean search distance in meters"));
72 oc.
addDescription(
"device.stationfinder.repeat",
"Battery",
TL(
"When to trigger a new search if no station has been found"));
74 oc.
addDescription(
"device.stationfinder.maxChargePower",
"Battery",
TL(
"The maximum charging speed of the vehicle battery"));
76 oc.
addDescription(
"device.stationfinder.chargeType",
"Battery",
TL(
"Type of energy transfer"));
78 oc.
addDescription(
"device.stationfinder.waitForCharge",
"Battery",
TL(
"After this waiting time vehicle searches for a new station when the initial one is blocked"));
80 oc.
addDescription(
"device.stationfinder.saturatedChargeLevel",
"Battery",
TL(
"Target state of charge after which the vehicle stops charging"));
82 oc.
addDescription(
"device.stationfinder.needToChargeLevel",
"Battery",
TL(
"State of charge the vehicle begins searching for charging stations"));
100 myBattery(nullptr), myChargingStation(nullptr), myRescueCommand(nullptr), myLastChargeCheck(0),
101 myCheckInterval(1000), myArrivalAtChargingStation(-1), myLastSearch(-1) {
177 if (stopPos.first !=
nullptr) {
179 double endPos = stopPos.second;
180 if (stopLane != stopPos.first) {
190 rescueStop.
index = 0;
194 rescueStop.
endPos = endPos;
202 std::string errorMsg =
"Could not insert the rescue stop.";
203 if (!
myVeh.
insertStop(0, rescueStop,
"stationfinder:rescue",
false, errorMsg)) {
214 std::string errorMsg =
"Could not insert the rescue stop.";
215 if (!
myVeh.
insertStop(0, rescueStop,
"stationfinder:rescue",
false, errorMsg)) {
260 double minTargetValue = std::numeric_limits<double>::max();
267 std::map<MSChargingStation*, double> travelTimeToCharging;
289 const MSEdge*
const csEdge = &stop.second->getLane().getEdge();
294 if (!constrainTT || time < maxTT) {
295 travelTimeToCharging.insert({ cs, time });
302 for (
const auto& tt : travelTimeToCharging) {
311 if (csEdge == route.back() || router.
compute(csEdge, route.back(), &
myHolder, now, routeFrom,
true)) {
312 double time = tt.second;
313 if (csEdge != route.back()) {
314 routeFrom.erase(routeFrom.begin());
317 double targetValue = time + chargingTime + waitingTime / parkingCapacity;
319 #ifdef DEBUG_STATIONFINDER_REROUTE
320 std::cout <<
"MSDevice_StationFinder::findChargingStation: CS " << cs->
getID() <<
" targetValue " << targetValue <<
" travelTime " << time <<
" freeParkingCapacity " << freeParkingCapacity <<
" chargingTime " << chargingTime <<
"\n";
322 if (targetValue < minTargetValue) {
323 minTargetValue = targetValue;
353 std::string errorMsg;
354 #ifdef DEBUG_STATIONFINDER_REROUTE
355 std::ostringstream os;
357 for (
auto edge : edgesBefore) {
358 os << edge->getID() <<
" ";
360 std::cout <<
"MSDevice_StationFinder::rerouteToChargingStation: \n\tRoute before scheduling the charging station: " << os.str() <<
"\n";
362 if ((replace && !
myVeh.
replaceStop(0, stopPar,
"stationfinder:search",
false, errorMsg)) || (!replace && !
myVeh.
insertStop(0, stopPar,
"stationfinder:search",
false, errorMsg))) {
366 #ifdef DEBUG_STATIONFINDER_REROUTE
367 std::ostringstream os2;
369 for (
auto edge : edgesAfter) {
370 os2 << edge->getID() <<
" ";
372 std::cout <<
"\tRoute after scheduling the charging station: " << os2.str() <<
"\n";
377 #ifdef DEBUG_STATIONFINDER_REROUTE
378 std::cout <<
"\tVehicle " <<
myHolder.
getID() <<
" gets rerouted to charging station " << cs->
getID() <<
" on edge " << stopPar.
edge <<
" at time " <<
SIMTIME <<
"\n";
397 #ifdef DEBUG_STATIONFINDER_RESCUE
398 std::cout <<
"MSDevice_StationFinder::teleportToChargingStation: No charging station available to teleport the broken-down vehicle " <<
myHolder.
getID() <<
" to at time " <<
SIMTIME <<
".\n.";
410 #ifdef DEBUG_STATIONFINDER_RESCUE
412 #ifdef DEBUG_STATIONFINDER_RESCUE
413 std::cout <<
"MSDevice_StationFinder::teleportToChargingStation: Rescue stop of " <<
myHolder.
getID() <<
" ended prematurely before regular end at " <<
SIMTIME <<
".\n.";
434 std::string errorMsg;
435 if (!
myVeh.
insertStop(1, stopPar,
"stationfinder:search",
true, errorMsg)) {
450 ConstMSEdgeVector::const_iterator targetIt = (target ==
nullptr) ? route.end() : std::find(route.begin(), route.end(), target) + 1;
455 double expectedConsumption = 0.;
458 expectedConsumption = totalConsumption / (passedTime - stopDiscount) * remainingTime;
464 speed * 0.8, 0., 0., params) * (remainingTime - passedTime);
466 if (includeEmptySoC) {
470 return expectedConsumption;
486 for (
auto stop : stops) {
487 if (stop.chargingStation !=
nullptr) {
512 tripinfoOut->
openTag(
"stationfinder");
521 if (key ==
"chargingStation") {
523 }
else if (key ==
"batteryNeed") {
532 const std::string action =
getStringParam(v, oc, option,
"remove");
533 if (action ==
"remove") {
535 }
else if (action ==
"tow") {
537 }
else if (action ==
"none") {
#define DEFAULT_CONSUMPTION_ESTIMATE_HISTORY
#define DEFAULT_SOC_INTERVAL
#define DEFAULT_AVG_WAITING_TIME
#define DEFAULT_CHARGINGSTATION_VIEW_DIST
std::vector< const MSEdge * > ConstMSEdgeVector
#define WRITE_WARNINGF(...)
#define WRITE_MESSAGEF(...)
#define WRITE_MESSAGE(msg)
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_ATTR_PROPULSIONEFFICIENCY
Propulsion efficiency.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
An upper class for objects with additional parameters.
double getDouble(SumoXMLAttr attr) const
bool replaceStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
const std::list< MSStop > & getStops() const
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool hasStops() const
Returns whether the vehicle has to stop somewhere.
MSStop & getStop(int nextStopIndex)
bool insertStop(int nextStopIndex, SUMOVehicleParameter::Stop stop, const std::string &info, bool teleport, std::string &errorMsg)
const MSRoute & getRoute() const
Returns the current route.
bool abortNextStop(int nextStopIndex=0)
deletes the next stop at the given index if it exists
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
double getChargingPower(bool usingFuel) const
Get charging station's charging power.
SUMOTime getChargeDelay() const
Get Charge Delay.
double getEfficency() const
Get efficiency of the charging station.
const MSParkingArea * getParkingArea() const
Get the parking area the charging station is placed on.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in Wh.
double getTotalConsumption() const
Get total consumption.
double getEnergyCharged() const
Get charged energy.
std::string getChargingStationID() const
Get current Charging Station ID.
double myUpdateSoC
SoC the last time the station finder algorithm was run completely.
MSChargingStation * findChargingStation(SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, double expectedConsumption, bool constrainTT=true, bool skipVisited=true, bool skipOccupied=false)
central search function for close charging stations
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
WrappingCommand< MSDevice_StationFinder > * myRescueCommand
The command responsible for rescue actions.
std::vector< MSChargingStation * > myPassedChargingStations
The memory of lastly visited charging stations during the search before being able to charge.
MSDevice_StationFinder(SUMOVehicle &holder)
Constructor.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
SUMOTime teleportToChargingStation(const SUMOTime currentTime)
search for a charging station and teleport the vehicle there as a rescue measure
MSVehicle & myVeh
myHolder cast to needed type
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Computes current emission values and adds them to their sums.
MSStoppingPlace * myChargingStation
To which station we are currently travelling.
const std::string deviceName() const
return the name for this type of device
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_StationFinder-options.
~MSDevice_StationFinder()
Destructor.
double myTargetSoC
The target state of charge where the vehicle stops charging.
bool rerouteToChargingStation(bool replace=false)
reroute to a charging station
double myRescueTime
The time to wait for a rescue vehicle in case the battery is empty.
SUMOTime myLastChargeCheck
Last time the SoC was checked.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
void initRescueCommand()
create the event command for teleporting in case of brake-down
SUMOTime myWaitForCharge
Accepted waiting time at the charging station before a place becomes available.
static void initRescueAction(const SUMOVehicle &v, const OptionsCont &oc, const std::string &option, RescueAction &myAction)
SUMOTime myLastSearch
Last time charging stations have been searched.
@ SEARCHSTATE_BROKEN_DOWN
@ SEARCHSTATE_UNSUCCESSFUL
bool notifyIdle(SUMOTrafficObject &veh)
Computes idling emission values and adds them to the emission sums.
double mySearchSoC
The state of charge at which the vehicle starts looking for charging stations.
SUMOTime myArrivalAtChargingStation
Arrival time in the vicinity of the target charging station (to track the waiting time before accessi...
double myEmptySoC
The state of charge threshold below which rescue mode is activated.
double myMaxEuclideanDistance
The maximum euclidean distance between the vehicle and the charging station (-1 deactivates the condi...
MSDevice_Battery * myBattery
The corresponding battery device.
ChargeType myChargeType
The type of charging permitted by the battery (charging, bidirectional, battery exchange)
bool alreadyPlannedCharging()
adopt a planned charging stop outside of the device
double freeSpaceAtChargingStation(MSChargingStation *cs) const
compute the free space at a charging station
SUMOTime myRadius
The max travel time to the next charging station.
SearchState mySearchState
The current state of the charging search (remember for decision logic)
SUMOTime myRepeatInterval
Time interval to search again for a charging station if the first attempt failed.
double myMaxChargePower
The maximum charging speed of the vehicle battery in W.
RescueAction myRescueAction
What to do when the state of charge gets very low.
double myReserveFactor
The safety buffer when calculating expected consumption.
double estimateConsumption(const MSEdge *target=nullptr, const bool includeEmptySoC=true, const double stopDiscount=0.) const
estimate the energy needed for the planned route / up to a target edge
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const double deflt, bool required=false)
static std::string getStringParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const std::string &deflt, bool required=false)
static SUMOTime getTimeParam(const SUMOVehicle &v, const OptionsCont &oc, const std::string ¶mName, const SUMOTime deflt, bool required=false)
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.
double getLength() const
return the length of the edge
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Representation of a lane in the micro simulation.
const MSLane * getNormalSuccessorLane() const
get normal lane following this internal lane, for normal lanes, the lane itself is returned
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
double getLength() const
Returns the lane's length.
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.
int getCapacity() const
Returns the area capacity.
bool parkOnRoad() const
whether vehicles park on the road
bool accepts(MSBaseVehicle *veh) const
Return the parking accepts the vehicle (due to its given badges)
int getOccupancy() const
Returns the area occupancy.
const ConstMSEdgeVector & getEdges() const
static MSVehicleRouter & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the vehicle router instance
MSStoppingPlace * chargingStation
(Optional) charging station if one is assigned to the stop
SUMOTime duration
The stopping duration.
const SUMOVehicleParameter::Stop pars
The stop parameter.
double getBeginLanePosition() const
Returns the begin position of this stop.
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
double getLastFreePos(const SUMOVehicle &forVehicle, double brakePos=0) const
Returns the last free position on this stop.
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
Representation of a vehicle in the micro simulation.
bool willStop() const
Returns whether the vehicle will stop on the current edge.
double getDistanceToPosition(double destPos, const MSLane *destLane) const
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
double getSpeed() const
Returns the vehicle's current speed.
const MSLane * getLane() const
Returns the lane the vehicle is on.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
double getLength() const
Get vehicle's length [m].
const SUMOVTypeParameter & getParameter() const
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.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
virtual void setBulkMode(const bool mode)
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...
virtual double recomputeCosts(const std::vector< const E * > &edges, const V *const v, SUMOTime msTime, double *lengthp=nullptr) const
Representation of a vehicle, person, or container.
virtual int getRNGIndex() const =0
virtual bool isStopped() const =0
Returns whether the object is at a stop.
virtual double getMaxSpeed() const =0
Returns the object's maximum speed (minimum of technical and desired maximum speed)
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual int getRoutePosition() const =0
return index of edge within route
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
double length
The physical vehicle length.
Representation of a vehicle.
virtual const MSRoute & getRoute() const =0
Returns the current route.
virtual const std::list< MSStop > & getStops() const =0
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual MSStop & getNextStop()=0
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at.
ParkingType parking
whether the vehicle is removed from the net while stopping
std::string lane
The lane to stop at.
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
bool breakDown
Whether this stop was triggered by a car failure / mechanical problem / lack of energy.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
int parametersSet
Information for the output which parameter were set.
int index
at which position in the stops list
SUMOTime jump
transfer time if there shall be a jump from this stop to the next route edge
SUMOTime until
The time at which the vehicle may continue its journey.
double endPos
The stopping position end.
SUMOTime duration
The stopping duration.
void deschedule()
Marks this Command as being descheduled.