LCOV - code coverage report
Current view: top level - src/microsim/trigger - MSChargingStation.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 60.7 % 28 17
Test Date: 2025-12-06 15:35:27 Functions: 66.7 % 3 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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              : /****************************************************************************/
      14              : /// @file    MSChargingStation.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Tamas Kurczveil
      17              : /// @author  Pablo Alvarez Lopez
      18              : /// @author  Mirko Barthauer
      19              : /// @date    20-12-13
      20              : ///
      21              : // Charging Station for Electric vehicles
      22              : /****************************************************************************/
      23              : #pragma once
      24              : #include <config.h>
      25              : 
      26              : #include <list>
      27              : #include <string>
      28              : #include <iostream>
      29              : #include <fstream>
      30              : #include <sstream>
      31              : #include <microsim/MSStoppingPlace.h>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class declarations
      36              : // ===========================================================================
      37              : class MSLane;
      38              : class MSBusStop;
      39              : class OptionsCont;
      40              : class MSDevice_Battery;
      41              : class Command;
      42              : 
      43              : // ===========================================================================
      44              : // class definitions
      45              : // ===========================================================================
      46              : /**
      47              :  * @class ChargingStation
      48              :  * @brief Definition of charging stations
      49              :  */
      50              : class MSChargingStation : public MSStoppingPlace {
      51              : 
      52              : public:
      53              :     enum ChargeType {
      54              :         CHARGETYPE_NORMAL = 0,
      55              :         CHARGETYPE_BATTERYEXCHANGE,
      56              :         CHARGETYPE_FUEL
      57              :     };
      58              : 
      59              :     /** @brief Get the string representation of a charge type
      60              :     * @param[in] type The charge type to represent
      61              :     */
      62            0 :     static inline std::string chargeTypeToString(ChargeType type) {
      63            0 :         if (type == CHARGETYPE_NORMAL) {
      64            0 :             return "normal";
      65            0 :         } else if (type == CHARGETYPE_BATTERYEXCHANGE) {
      66            0 :             return "battery-exchange";
      67            0 :         } else if (type == CHARGETYPE_FUEL) {
      68            0 :             return "fuel";
      69              :         } else {
      70            0 :             WRITE_WARNING(TL("Encountered an unknown charge type. Assuming charge type 'normal'."));
      71            0 :             return "normal";
      72              :         }
      73              :     }
      74              : 
      75              :     /** @brief Get the charge type from its string representation
      76              :     * @param[in] repr The string to convert into charge type
      77              :     */
      78        12231 :     static inline ChargeType stringToChargeType(const std::string& repr) {
      79        12231 :         if (repr == "normal") {
      80              :             return ChargeType::CHARGETYPE_NORMAL;
      81           99 :         } else if (repr == "battery-exchange") {
      82              :             return ChargeType::CHARGETYPE_BATTERYEXCHANGE;
      83           88 :         } else if (repr == "fuel") {
      84              :             return ChargeType::CHARGETYPE_FUEL;
      85              :         } else {
      86            0 :             WRITE_WARNINGF("Encountered an unknown charge type string '%'. Assuming charge type 'normal'.", repr);
      87            0 :             return ChargeType::CHARGETYPE_NORMAL;
      88              :         }
      89              :     }
      90              : 
      91              : public:
      92              : 
      93              :     /// @brief constructor
      94              :     MSChargingStation(const std::string& chargingStationID, MSLane& lane, double startPos, double endPos,
      95              :                       const std::string& name, double chargingPower, double totalPower, double efficency, bool chargeInTransit,
      96              :                       SUMOTime chargeDelay, const std::string& chargeType, SUMOTime waitingTime);
      97              : 
      98              :     MSChargingStation(const std::string& chargingStationID, const MSParkingArea* parkingArea, const std::string& name, double chargingPower,
      99              :                       double totalPower, double efficency, bool chargeInTransit, SUMOTime chargeDelay, const std::string& chargeType,
     100              :                       SUMOTime waitingTime);
     101              : 
     102              :     /// @brief destructor
     103              :     ~MSChargingStation();
     104              : 
     105              :     /// @brief Get charging station's charging power
     106              :     double getChargingPower(bool usingFuel) const;
     107              : 
     108              :     /// @brief Get efficiency of the charging station
     109              :     double getEfficency() const;
     110              : 
     111              :     /// @brief Get chargeInTransit
     112              :     bool getChargeInTransit() const;
     113              : 
     114              :     /// @brief Get Charge Delay
     115              :     SUMOTime getChargeDelay() const;
     116              : 
     117              :     /// @brief Get charge type
     118              :     ChargeType getChargeType() const;
     119              : 
     120              :     /// @brief Get waiting time
     121              :     SUMOTime getWaitingTime() const;
     122              : 
     123              :     /** @brief Get the parking area the charging station is placed on
     124              :      * @return pointer to the parking area or nullptr
     125              :      */
     126              :     const MSParkingArea* getParkingArea() const;
     127              : 
     128              :     /// @brief set charging station's charging power
     129              :     void setChargingPower(double chargingPower);
     130              : 
     131              :     /// @brief set efficiency of the charging station
     132              :     void setEfficiency(double efficiency);
     133              : 
     134              :     /// @brief set charging delay of the charging station
     135              :     void setChargeDelay(SUMOTime delay);
     136              : 
     137              :     /// @brief set charging in transit
     138              :     void setChargeInTransit(bool value);
     139              : 
     140              :     /// @brief enable or disable charging vehicle
     141              :     void setChargingVehicle(bool value);
     142              : 
     143              :     /// @brief update the delivered power to all charging vehicles after all requests are known
     144              :     SUMOTime checkTotalPower(SUMOTime currentTime);
     145              : 
     146              :     /** @brief Check if a vehicle is inside in  the Charge Station
     147              :      * @param[in] position Position of vehicle in the LANE
     148              :      * @return true if is between StartPostion and EndPostion
     149              :      */
     150              :     bool vehicleIsInside(const double position) const;
     151              : 
     152              :     /// @brief Return true if in the current time step charging station is charging a vehicle
     153              :     bool isCharging() const;
     154              : 
     155              :     double getTotalCharged() const {
     156            5 :         return myTotalCharge;
     157              :     }
     158              : 
     159              :     /// @brief add charge value for output
     160              :     void addChargeValueForOutput(double WCharged, MSDevice_Battery* battery);
     161              : 
     162              :     /// @brief write charging station values
     163              :     void writeChargingStationOutput(OutputDevice& output);
     164              : 
     165              :     /// @brief write ungrouped output (flush data after writing)
     166              :     void writeAggregatedChargingStationOutput(OutputDevice& output, bool includeUnfinished = false);
     167              : 
     168              : protected:
     169              : 
     170              :     /// @brief struct to save information for the chargingStation output
     171              :     struct Charge {
     172              :         /// @brief constructor
     173        99609 :         Charge(SUMOTime _timeStep, std::string _vehicleID, std::string _vehicleType, std::string _status,
     174              :                double _WCharged, double _actualBatteryCapacity, double _maxBatteryCapacity, double _chargingPower,
     175        99609 :                double _chargingEfficiency, double _totalEnergyCharged) :
     176        99609 :             timeStep(_timeStep),
     177        99609 :             vehicleID(_vehicleID),
     178        99609 :             vehicleType(_vehicleType),
     179        99609 :             status(_status),
     180        99609 :             WCharged(_WCharged),
     181        99609 :             actualBatteryCapacity(_actualBatteryCapacity),
     182        99609 :             maxBatteryCapacity(_maxBatteryCapacity),
     183        99609 :             chargingPower(_chargingPower),
     184        99609 :             chargingEfficiency(_chargingEfficiency),
     185        99609 :             totalEnergyCharged(_totalEnergyCharged) {}
     186              : 
     187              :         // @brief vehicle TimeStep
     188              :         SUMOTime timeStep;
     189              :         // @brief vehicle ID
     190              :         std::string vehicleID;
     191              :         // @brief vehicle Type
     192              :         std::string vehicleType;
     193              :         /// @brief status
     194              :         std::string status;
     195              :         // @brief W charged
     196              :         double WCharged;
     197              :         // @brief actual battery capacity AFTER charging
     198              :         double actualBatteryCapacity;
     199              :         // @brief battery max capacity
     200              :         double maxBatteryCapacity;
     201              :         // @brief current charging power of charging station
     202              :         double chargingPower;
     203              :         // @brief current efficiency of charging station
     204              :         double chargingEfficiency;
     205              :         // @brief current energy charged by charging stations AFTER charging
     206              :         double totalEnergyCharged;
     207              :     };
     208              : 
     209              :     static void writeVehicle(OutputDevice& out, const std::vector<Charge>& chargeSteps, int iStart, int iEnd, double charged);
     210              : 
     211              :     /// @brief Charging station's nominal charging power per vehicle
     212              :     double myNominalChargingPower = 0;
     213              : 
     214              :     /// @brief The maximal charging power available to serve all charging vehicles (value <= 0 take no effect)
     215              :     double myTotalChargingPower = 0;
     216              : 
     217              :     /// @brief Efficiency of the charging station
     218              :     double myEfficiency = 0;
     219              : 
     220              :     /// @brief Allow charge in transit
     221              :     bool myChargeInTransit;
     222              : 
     223              :     /// @brief Charge Delay
     224              :     SUMOTime myChargeDelay = 0;
     225              : 
     226              :     /// @brief charge type
     227              :     const ChargeType myChargeType;
     228              : 
     229              :     /// @brief waiting time
     230              :     SUMOTime myWaitingTime = 0;
     231              : 
     232              :     /// @brief Check if in the current TimeStep chargingStation is charging a vehicle
     233              :     bool myChargingVehicle = false;
     234              : 
     235              :     /// @brief total energy charged by this charging station
     236              :     double myTotalCharge = 0;
     237              : 
     238              :     /// @brief parkingArea the charging station is placed on
     239              :     const MSParkingArea* myParkingArea = nullptr;
     240              : 
     241              :     /// @brief map with the charges of this charging station (key = vehicleID)
     242              :     std::map<std::string, std::vector<Charge> > myChargeValues;
     243              :     /// @brief order vehicles by time of first charge
     244              :     std::vector<std::string> myChargedVehicles;
     245              : 
     246              :     /// @brief map with the Batteries charged by this charging station (key = vehicleID)
     247              :     std::map<std::string, MSDevice_Battery*> myChargedBatteries;
     248              : 
     249              :     /// @brief Event for checking at every time-step if myTotalPower has been exceeded
     250              :     Command* myTotalPowerCheckEvent;
     251              : 
     252              : 
     253              : private:
     254              :     /// @brief Invalidated copy constructor.
     255              :     MSChargingStation(const MSChargingStation&) = delete;
     256              : 
     257              :     /// @brief Invalidated assignment operator.
     258              :     MSChargingStation& operator=(const MSChargingStation&) = delete;
     259              : };
        

Generated by: LCOV version 2.0-1