Eclipse SUMO - Simulation of Urban MObility
MSDevice_StationFinder.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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/****************************************************************************/
18// A device which triggers rerouting to nearby charging stations
19/****************************************************************************/
20#include <config.h>
21
22#include <microsim/MSNet.h>
23#include <microsim/MSLane.h>
24#include <microsim/MSStop.h>
31#include "MSRoutingEngine.h"
32#include "MSDevice_Battery.h"
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39// ---------------------------------------------------------------------------
40// static initialisation methods
41// ---------------------------------------------------------------------------
42void
44 insertDefaultAssignmentOptions("stationfinder", "Battery", oc);
45 oc.doRegister("device.stationfinder.rescueTime", new Option_String("1800", "TIME"));
46 oc.addDescription("device.stationfinder.rescueTime", "Battery", TL("Time to wait for a rescue vehicle on the road side when the battery is empty"));
47 oc.doRegister("device.stationfinder.reserveFactor", new Option_Float(1.1));
48 oc.addDescription("device.stationfinder.reserveFactor", "Battery", TL("Additional battery buffer for unexpected traffic situation when estimating the battery need"));
49 oc.doRegister("device.stationfinder.emptyThreshold", new Option_Float(5));
50 oc.addDescription("device.stationfinder.emptyThreshold", "Battery", TL("Battery percentage to go into rescue mode"));
51 oc.doRegister("device.stationfinder.radius", new Option_String("180", "TIME"));
52 oc.addDescription("device.stationfinder.radius", "Battery", TL("Search radius in travel time seconds"));
53 oc.doRegister("device.stationfinder.repeat", new Option_String("60", "TIME"));
54 oc.addDescription("device.stationfinder.repeat", "Battery", TL("When to trigger a new search if no station has been found"));
55 oc.doRegister("device.stationfinder.maxChargePower", new Option_Float(1000.));
56 oc.addDescription("device.stationfinder.maxChargePower", "Battery", TL("The maximum charging speed of the vehicle battery"));
57 oc.doRegister("device.stationfinder.chargeType", new Option_String("charging"));
58 oc.addDescription("device.stationfinder.chargeType", "Battery", TL("Type of energy transfer"));
59 oc.doRegister("device.stationfinder.waitForCharge", new Option_String("600", "TIME"));
60 oc.addDescription("device.stationfinder.waitForCharge", "Battery", TL("After this waiting time vehicle searches for a new station when the initial one is blocked"));
61}
62
63
64void
65MSDevice_StationFinder::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
67 if (equippedByDefaultAssignmentOptions(oc, "stationfinder", v, false)) {
68 into.push_back(new MSDevice_StationFinder(v));
69 }
70}
71
72
73// ---------------------------------------------------------------------------
74// MSDevice_StationFinder-methods
75// ---------------------------------------------------------------------------
77 : MSVehicleDevice(holder, "stationfinder_" + holder.getID()),
78 myBattery(nullptr), myChargingStation(nullptr) {
80 myReserveFactor = getFloatParam(holder, oc, "stationfinder.reserveFactor", 1.1);
81}
82
83
85}
86
87
88bool
89MSDevice_StationFinder::notifyMove(SUMOTrafficObject& /*veh*/, double /*oldPos*/, double /*newPos*/, double /*newSpeed*/) {
90 if (myChargingStation == nullptr) {
91 const SUMOTime now = SIMSTEP;
94 const ConstMSEdgeVector remainingRoute(route.begin() + myHolder.getRoutePosition(), route.end());
95 const double remainingTime = router.recomputeCosts(remainingRoute, &myHolder, now);
96 if (now > myHolder.getDeparture()) {
97 double expectedConsumption = myBattery->getTotalConsumption() / STEPS2TIME(now - myHolder.getDeparture()) * remainingTime;
98 if (expectedConsumption > myBattery->getActualBatteryCapacity() * myReserveFactor) {
99 const MSEdge* const start = myHolder.getEdge();
100 double minTime = std::numeric_limits<double>::max();
101 MSChargingStation* minStation = nullptr;
102 ConstMSEdgeVector minRoute;
103 // TODO do some form of bulk routing here
104 for (const auto& stop : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_CHARGING_STATION)) {
105 ConstMSEdgeVector routeTo;
106 const MSEdge* const csEdge = &stop.second->getLane().getEdge();
107 if (router.compute(start, myHolder.getPositionOnLane(), csEdge, stop.second->getBeginLanePosition(), &myHolder, now, routeTo)) {
108 ConstMSEdgeVector routeFrom;
109 if (csEdge == route.back() || router.compute(start, &stop.second->getLane().getEdge(), &myHolder, now, routeFrom)) {
110 if (csEdge != route.back()) {
111 routeTo.insert(routeTo.end(), routeFrom.begin() + 1, routeFrom.end());
112 }
113 const double time = router.recomputeCosts(routeTo, &myHolder, now);
114 if (time < minTime) {
115 minTime = time;
116 minStation = static_cast<MSChargingStation*>(stop.second);
117 minRoute = routeTo;
118 }
119 }
120 }
121 }
122 if (minStation != nullptr) {
123 if (myHolder.hasStops()) {
124 WRITE_WARNINGF(TL("Rerouting using station finder removes all upcoming stops for vehicle '%'."), myHolder.getID());
125 }
126 myHolder.replaceRouteEdges(minRoute, minTime, 0., getID());
127 myChargingStation = minStation;
129 stopPar.chargingStation = minStation->getID();
130 stopPar.lane = minStation->getLane().getID();
131 stopPar.endPos = minStation->getEndLanePosition();
132 stopPar.duration = TIME2STEPS(expectedConsumption / minStation->getChargingPower(false) * myReserveFactor);
133 std::string errorMsg;
134 if (!myHolder.addStop(stopPar, errorMsg)) {
135 WRITE_ERROR(errorMsg);
136 } else if (errorMsg != "") {
137 WRITE_WARNING(errorMsg);
138 }
139 }
140 }
141 }
142 }
143 return true;
144}
145
146
147bool
149 return true;
150}
151
152
153void
155 const double /* frontOnLane */,
156 const double /* timeOnLane */,
157 const double /* meanSpeedFrontOnLane */,
158 const double /* meanSpeedVehicleOnLane */,
159 const double /* travelledDistanceFrontOnLane */,
160 const double /* travelledDistanceVehicleOnLane */,
161 const double /* meanLengthOnLane */) {
162
163 // called by meso (see MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal)
164}
165
166
167
168void
170 if (tripinfoOut != nullptr) {
171 }
172}
173
174
175/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:271
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:279
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:270
#define TL(string)
Definition: MsgHandler.h:287
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
#define SIMSTEP
Definition: SUMOTime.h:61
#define TIME2STEPS(x)
Definition: SUMOTime.h:57
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
double getChargingPower(bool usingFuel) const
Get charging station's charging power in the.
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in Wh.
double getTotalConsumption() const
Get total consumption.
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
MSDevice_StationFinder(SUMOVehicle &holder)
Constructor.
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.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_StationFinder-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
bool notifyIdle(SUMOTrafficObject &veh)
Computes idling emission values and adds them to the emission sums.
MSDevice_Battery * myBattery
The corresponding battery device.
double myReserveFactor
The safety buffer when calculating expected consumption.
static double getFloatParam(const SUMOVehicle &v, const OptionsCont &oc, std::string paramName, double deflt, bool required=false)
Definition: MSDevice.cpp:199
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.
Definition: MSDevice.cpp:148
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.
Definition: MSDevice.h:202
A road/street connecting two junctions.
Definition: MSEdge.h:77
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:183
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:124
static SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const int rngIndex, SUMOVehicleClass svc, const MSEdgeVector &prohibited=MSEdgeVector())
return the router instance
double getEndLanePosition() const
Returns the end position of this stop.
const MSLane & getLane() const
Returns the lane this stop is located at.
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
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.
Definition: OptionsCont.cpp:76
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
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 SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual int getRoutePosition() const =0
return index of edge within route
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.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual bool replaceRouteEdges(ConstMSEdgeVector &edges, double cost, double savings, const std::string &info, bool onInit=false, bool check=false, bool removeStops=true, std::string *msgReturn=nullptr)=0
Replaces the current route by the given edges.
virtual bool hasStops() const =0
Returns whether the vehicle has to stop somewhere.
virtual bool addStop(const SUMOVehicleParameter::Stop &stopPar, std::string &errorMsg, SUMOTime untilOffset=0, ConstMSEdgeVector::const_iterator *searchStart=0)=0
Adds a stop.
virtual SUMOTime getDeparture() const =0
Returns this vehicle's real departure time.
virtual int getRNGIndex() const =0
virtual const MSRoute & getRoute() const =0
Returns the current route.
Definition of vehicle stop (position and duration)
std::string lane
The lane to stop at.
std::string chargingStation
(Optional) charging station if one is assigned to the stop
double endPos
The stopping position end.
SUMOTime duration
The stopping duration.