Eclipse SUMO - Simulation of Urban MObility
MSDevice_StationFinder.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 /****************************************************************************/
19 // A device which triggers rerouting to nearby charging stations
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
26 #include "MSVehicleDevice.h"
27 
28 
29 #define DEFAULT_SOC_INTERVAL 0.1
30 #define DEFAULT_ENERGY_PER_DISTANCE 200 // Wh/km
31 #define DEFAULT_AVG_WAITING_TIME 900. // s
32 #define DEFAULT_CHARGINGSTATION_VIEW_DIST 10 // m
33 #define DEFAULT_CONSUMPTION_ESTIMATE_HISTORY 10 // s
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSDevice_Battery;
39 class MSStoppingPlace;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
56 public:
57  enum ChargeType {
62  };
63 
68  };
69 
70  enum RescueAction {
74  };
75 
76  enum SearchState {
83  };
84 
87  static void insertOptions(OptionsCont& oc);
88 
89 
102  static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
103 
104 public:
110 
113 
116 
131  bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) override;
132 
142  bool notifyIdle(SUMOTrafficObject& veh) override;
143 
145 
147  const std::string deviceName() const override {
148  return "stationfinder";
149  }
150 
152  const std::string getChargingStrategy() const {
154  return "none";
156  return "balanced";
157  } else {
158  return "latest";
159  }
160  }
161 
168  void generateOutput(OutputDevice* tripinfoOut) const override;
169 
170  void setBattery(MSDevice_Battery* battery) {
171  myBattery = battery;
172  }
173 
174  std::string getParameter(const std::string& key) const override;
175 
191  bool evaluateCustomComponents(SUMOVehicle& veh, double brakeGap, bool newDestination,
192  MSStoppingPlace* alternative, double occupancy, double prob,
194  ConstMSEdgeVector& newRoute,
195  ConstMSEdgeVector& stoppingPlaceApproach,
196  StoppingPlaceParamMap_t& maxValues,
197  StoppingPlaceParamMap_t& addInput) override;
198 
200  bool validComponentValues(StoppingPlaceParamMap_t& stoppingPlaceValues) override;
201 
203  bool useStoppingPlace(MSStoppingPlace* stoppingPlace) override;
204 
207 
209  double getStoppingPlaceOccupancy(MSStoppingPlace* stoppingPlace) override;
210 
212  double getLastStepStoppingPlaceOccupancy(MSStoppingPlace* stoppingPlace) override;
213 
215  double getStoppingPlaceCapacity(MSStoppingPlace* stoppingPlace) override;
216 
218  void rememberBlockedStoppingPlace(SUMOVehicle& veh, const MSStoppingPlace* stoppingPlace, bool blocked) override;
219 
221  void rememberStoppingPlaceScore(SUMOVehicle& veh, MSStoppingPlace* place, const std::string& score) override;
222 
224  void resetStoppingPlaceScores(SUMOVehicle& veh) override;
225 
227  SUMOTime sawBlockedStoppingPlace(SUMOVehicle& veh, MSStoppingPlace* place, bool local) override;
228 
230  int getNumberStoppingPlaceReroutes(SUMOVehicle& veh) override;
231 
233  void setNumberStoppingPlaceReroutes(SUMOVehicle& veh, int value) override;
234 
235 protected:
239  void notifyMoveInternal(const SUMOTrafficObject& veh,
240  const double frontOnLane,
241  const double timeOnLane,
242  const double meanSpeedFrontOnLane,
243  const double meanSpeedVehicleOnLane,
244  const double travelledDistanceFrontOnLane,
245  const double travelledDistanceVehicleOnLane,
246  const double meanLengthOnLane) override;
247 
248 private:
259  MSChargingStation* findChargingStation(SUMOAbstractRouter<MSEdge, SUMOVehicle>& router, double expectedConsumption, StoppingPlaceParamMap_t& scores, bool constrainTT = true, bool skipVisited = true, bool skipOccupied = false);
260 
261 
267  bool rerouteToChargingStation(bool replace = false);
268 
271  SUMOTime teleportToChargingStation(const SUMOTime currentTime);
272 
280  double estimateConsumption(const MSEdge* target = nullptr, const bool includeEmptySoC = true, const double stopDiscount = 0.) const;
281 
288 
293  bool alreadyPlannedCharging();
294 
297  void initRescueCommand();
298 
301  void initChargeLimitCommand();
302 
305  SUMOTime updateChargeLimit(const SUMOTime currentTime);
306 
309  void implementChargingStrategy(SUMOTime begin, SUMOTime end, const double plannedCharge, const MSChargingStation* cs);
310 
311 private:
314 
317 
320 
323 
326 
328  std::vector<std::pair<SUMOTime, double>> myChargeLimits;
329 
332 
335 
338 
341 
343  double myRescueTime;
344 
347 
349  double myEmptySoC;
350 
353 
356 
359 
362 
364  double myUpdateSoC;
365 
368 
370  double myTargetSoC;
371 
373  double mySearchSoC;
374 
377 
380 
383 
386 
389 
392 
393 private:
396 
399 };
long long int SUMOTime
Definition: GUI.h:35
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition: MSEdge.h:73
Battery device for electric vehicles.
A device which triggers rerouting to nearby charging stations.
double myUpdateSoC
SoC the last time the station finder algorithm was run completely.
void resetStoppingPlaceScores(SUMOVehicle &veh) override
forget all stopping place score for this vehicle
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) override
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
void rememberBlockedStoppingPlace(SUMOVehicle &veh, const MSStoppingPlace *stoppingPlace, bool blocked) override
store the blocked stopping place in the vehicle
WrappingCommand< MSDevice_StationFinder > * myRescueCommand
The command responsible for rescue actions.
MSDevice_StationFinder & operator=(const MSDevice_StationFinder &)
Invalidated assignment operator.
void implementChargingStrategy(SUMOTime begin, SUMOTime end, const double plannedCharge, const MSChargingStation *cs)
MSDevice_StationFinder(SUMOVehicle &holder)
Constructor.
ChargingStrategy myChargingStrategy
The chosen charging strategy.
SUMOTime teleportToChargingStation(const SUMOTime currentTime)
search for a charging station and teleport the vehicle there as a rescue measure
double myDistanceToOriginalStop
The distance in meters to the original stop replaced by the charging stop (models charging close to t...
MSVehicle & myVeh
myHolder cast to needed type
double getStoppingPlaceOccupancy(MSStoppingPlace *stoppingPlace) override
Return the number of occupied places of the StoppingPlace.
MSStoppingPlace * myChargingStation
To which station we are currently travelling.
WrappingCommand< MSDevice_StationFinder > * myChargeLimitCommand
The command responsible for limiting the charging rate (~ implement charging strategies)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_StationFinder-options.
int getNumberStoppingPlaceReroutes(SUMOVehicle &veh) override
ask how many times already the vehicle has been rerouted to another stopping place
const std::string getChargingStrategy() const
return the string representation of the chosen charging strategy
double myTargetSoC
The target state of charge where the vehicle stops charging.
const std::string deviceName() const override
return the name for this type of device
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
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
bool useStoppingPlace(MSStoppingPlace *stoppingPlace) override
Whether the stopping place should be included in the search (can be used to add an additional filter)
double getLastStepStoppingPlaceOccupancy(MSStoppingPlace *stoppingPlace) override
Return the number of occupied places of the StoppingPlace from the previous time step.
double getStoppingPlaceCapacity(MSStoppingPlace *stoppingPlace) override
Return the number of places the StoppingPlace provides.
void rememberStoppingPlaceScore(SUMOVehicle &veh, MSStoppingPlace *place, const std::string &score) override
store the stopping place score in the vehicle
SUMOTime myWaitForCharge
Accepted waiting time at the charging station before a place becomes available.
SUMOTime myLastSearch
Last time charging stations have been searched.
void setNumberStoppingPlaceReroutes(SUMOVehicle &veh, int value) override
update the number of reroutes for the vehicle
SUMOTime sawBlockedStoppingPlace(SUMOVehicle &veh, MSStoppingPlace *place, bool local) override
ask the vehicle when it has seen the stopping place
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...
bool validComponentValues(StoppingPlaceParamMap_t &stoppingPlaceValues) override
Whether the stopping place should be discarded due to its results from the component evaluation.
bool notifyIdle(SUMOTrafficObject &veh) override
Computes idling emission values and adds them to the emission sums.
void generateOutput(OutputDevice *tripinfoOut) const override
Called on writing tripinfo output.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouter(SUMOVehicle &veh, const MSEdgeVector &prohibited) override
Provide the router to use (MSNet::getRouterTT or MSRoutingEngine)
MSDevice_Battery * myBattery
The corresponding battery device.
MSChargingStation * findChargingStation(SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, double expectedConsumption, StoppingPlaceParamMap_t &scores, bool constrainTT=true, bool skipVisited=true, bool skipOccupied=false)
central search function for close charging stations
ChargeType myChargeType
The type of charging permitted by the battery (charging, bidirectional, battery exchange)
void setBattery(MSDevice_Battery *battery)
bool alreadyPlannedCharging()
adopt a planned charging stop outside of the device
double freeSpaceAtChargingStation(MSChargingStation *cs) const
compute the free space at a charging station
std::vector< std::pair< SUMOTime, double > > myChargeLimits
The next charging rates to set via myChargingRateCommand.
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.
bool evaluateCustomComponents(SUMOVehicle &veh, double brakeGap, bool newDestination, MSStoppingPlace *alternative, double occupancy, double prob, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, StoppingPlaceParamMap_t &stoppingPlaceValues, ConstMSEdgeVector &newRoute, ConstMSEdgeVector &stoppingPlaceApproach, StoppingPlaceParamMap_t &maxValues, StoppingPlaceParamMap_t &addInput) override
Compute some custom target function components.
SUMOTime updateChargeLimit(const SUMOTime currentTime)
update the maximum charge rate of the battery to simulate charging strategies
double myMaxChargePower
The maximum charging speed of the vehicle battery in W.
double myReplacePlannedStop
The share of stopping time a charging stop should take from the next regulr (non-charging) stop under...
RescueAction myRescueAction
What to do when the state of charge gets very low.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed) override
Computes current emission values and adds them to their sums.
SUMOTime myCheckInterval
Time interval after which the SoC has to be checked.
double myReserveFactor
The safety buffer when calculating expected consumption.
MSDevice_StationFinder(const MSDevice_StationFinder &)
Invalidated copy constructor.
void initChargeLimitCommand()
create the event command for changing charging rates
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
A road/street connecting two junctions.
Definition: MSEdge.h:77
A lane area vehicles can halt at.
std::map< std::string, double > StoppingPlaceParamMap_t
Abstract in-vehicle device.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:62