Skip to content

Commit

Permalink
consider stop duration in consumption estimate ref #9663
Browse files Browse the repository at this point in the history
Signed-off-by: m-kro <m.barthauer@t-online.de>
  • Loading branch information
m-kro committed May 7, 2024
1 parent f84c68f commit 70ed115
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/microsim/devices/MSDevice_StationFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ SUMOTime
MSDevice_StationFinder::teleportToChargingStation(const SUMOTime /*currentTime*/) {
// find closest charging station
MSVehicleRouter& router = MSRoutingEngine::getRouterTT(myHolder.getRNGIndex(), myHolder.getVClass());
double expectedConsumption = estimateConsumption(nullptr, true);
double expectedConsumption = estimateConsumption(nullptr, true, myVeh.getStops().front().pars.duration);
MSChargingStation* cs = findChargingStation(router, expectedConsumption, false, false);
if (cs == nullptr) {
// continue waiting if all charging stations are occupied
Expand Down Expand Up @@ -396,7 +396,7 @@ MSDevice_StationFinder::teleportToChargingStation(const SUMOTime /*currentTime*/


double
MSDevice_StationFinder::estimateConsumption(const MSEdge* target, const bool includeEmptySoC) const {
MSDevice_StationFinder::estimateConsumption(const MSEdge* target, const bool includeEmptySoC, const double stopDiscount) const {
const SUMOTime now = SIMSTEP;
MSVehicleRouter& router = MSRoutingEngine::getRouterTT(myHolder.getRNGIndex(), myHolder.getVClass());
const ConstMSEdgeVector& route = myHolder.getRoute().getEdges();
Expand All @@ -406,12 +406,13 @@ MSDevice_StationFinder::estimateConsumption(const MSEdge* target, const bool inc
if (now > myHolder.getDeparture()) {
const double totalConsumption = myBattery->getTotalConsumption();
double expectedConsumption = 0.;
if (totalConsumption > 0.) {
expectedConsumption = totalConsumption / STEPS2TIME(now - myHolder.getDeparture()) * remainingTime;
double passedTime = STEPS2TIME(now - myHolder.getDeparture());
if (totalConsumption > 0. && passedTime - stopDiscount > DEFAULT_CONSUMPTION_ESTIMATE_HISTORY) {
expectedConsumption = totalConsumption / (passedTime - stopDiscount) * remainingTime;
} else {
// fallback consumption rate for vehicles starting with low battery
const double speed = MIN2(myHolder.getMaxSpeed(), myHolder.getLane()->getSpeedLimit());
expectedConsumption = DEFAULT_ENERGY_PER_DISTANCE * speed * (remainingTime - STEPS2TIME(now - myHolder.getDeparture())) / 1000.;
expectedConsumption = DEFAULT_ENERGY_PER_DISTANCE * speed * (remainingTime - passedTime) / 1000.;
}
if (includeEmptySoC) {
expectedConsumption += MAX2(0., myEmptySoC * myBattery->getMaximumBatteryCapacity() - myBattery->getActualBatteryCapacity());
Expand Down
4 changes: 3 additions & 1 deletion src/microsim/devices/MSDevice_StationFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define DEFAULT_ENERGY_PER_DISTANCE 200 // Wh/km
#define DEFAULT_AVG_WAITING_TIME 900 // s
#define DEFAULT_CHARGINGSTATION_VIEW_DIST 10 // m
#define DEFAULT_CONSUMPTION_ESTIMATE_HISTORY 10 // s

// ===========================================================================
// class declarations
Expand Down Expand Up @@ -188,9 +189,10 @@ class MSDevice_StationFinder : public MSVehicleDevice {
*
* @param[in] target edge along the route up to which the consumption shall be estimated - the complete route will be used if defaulting to nullptr
* @param[in] includeEmptySoC whether to add an additional buffer for the range up to the "empty" threshold
* @param[in] stopDiscount duration in seconds to discount in the consumption estimation due to occurred stopping time
* @return energy in Wh needed to complete the planned route
*/
double estimateConsumption(const MSEdge* target = nullptr, const bool includeEmptySoC = true) const;
double estimateConsumption(const MSEdge* target = nullptr, const bool includeEmptySoC = true, const double stopDiscount = 0.) const;

/** @brief adopt a planned charging stop outside of the device
*
Expand Down

0 comments on commit 70ed115

Please sign in to comment.