Eclipse SUMO - Simulation of Urban MObility
MSChargingStation.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Chargin Station for Electric vehicles
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 
23 #include <config.h>
24 
25 #include <cassert>
28 #include <microsim/MSVehicleType.h>
31 #include <microsim/MSNet.h>
32 #include "MSChargingStation.h"
33 #include "MSTrigger.h"
34 
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 MSChargingStation::MSChargingStation(const std::string& chargingStationID, MSLane& lane, double startPos, double endPos,
41  const std::string& name,
42  double chargingPower, double efficency, bool chargeInTransit, double chargeDelay) :
43  MSStoppingPlace(chargingStationID, std::vector<std::string>(), lane, startPos, endPos, name),
44  myChargingPower(0),
45  myEfficiency(0),
46  myChargeInTransit(chargeInTransit),
47  myChargeDelay(0),
48  myChargingVehicle(false),
49  myTotalCharge(0) {
50  if (chargingPower < 0)
51  WRITE_WARNING("Parameter " + toString(SUMO_ATTR_CHARGINGPOWER) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " is invalid (" + toString(getChargingPower()) + ").")
52  else {
53  myChargingPower = chargingPower;
54  }
55 
56  if (efficency < 0 || efficency > 1) {
57  WRITE_WARNING("Parameter " + toString(SUMO_ATTR_EFFICIENCY) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " is invalid (" + toString(getEfficency()) + ").")
58  } else {
59  myEfficiency = efficency;
60  }
61 
62  if (chargeDelay < 0) {
63  WRITE_WARNING("Parameter " + toString(SUMO_ATTR_CHARGEDELAY) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " is invalid (" + toString(getEfficency()) + ").")
64  } else {
65  myChargeDelay = chargeDelay;
66  }
67 
69  WRITE_WARNING(toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " doesn't have a valid range (" + toString(getBeginLanePosition()) + " < " + toString(getEndLanePosition()) + ").");
70  }
71 }
72 
73 
75 }
76 
77 
78 double
80  return myChargingPower;
81 }
82 
83 
84 double
86  return myEfficiency;
87 }
88 
89 
90 bool
92  return myChargeInTransit;
93 }
94 
95 
96 double
98  return myChargeDelay;
99 }
100 
101 
102 void
103 MSChargingStation::setChargingPower(double chargingPower) {
104  if (chargingPower < 0) {
105  WRITE_WARNING("New " + toString(SUMO_ATTR_CHARGINGPOWER) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " isn't valid (" + toString(chargingPower) + ").")
106  } else {
107  myChargingPower = chargingPower;
108  }
109 }
110 
111 
112 void
114  if (efficency < 0 || efficency > 1) {
115  WRITE_WARNING("New " + toString(SUMO_ATTR_EFFICIENCY) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " isn't valid (" + toString(efficency) + ").")
116  } else {
117  myEfficiency = efficency;
118  }
119 }
120 
121 
122 void
124  myChargeInTransit = chargeInTransit;
125 }
126 
127 
128 void
130  if (chargeDelay < 0) {
131  WRITE_WARNING("New " + toString(SUMO_ATTR_CHARGEDELAY) + " for " + toString(SUMO_TAG_CHARGING_STATION) + " with ID = " + getID() + " isn't valid (" + toString(chargeDelay) + ").")
132  } else {
133  myChargeDelay = chargeDelay;
134  }
135 }
136 
137 
138 void
140  myChargingVehicle = value;
141 }
142 
143 
144 bool
145 MSChargingStation::vehicleIsInside(const double position) const {
146  if ((position >= getBeginLanePosition()) && (position <= getEndLanePosition())) {
147  return true;
148  } else {
149  return false;
150  }
151 }
152 
153 
154 bool
156  return myChargingVehicle;
157 }
158 
159 
160 void
162  std::string status = "";
163  if (battery->getChargingStartTime() > myChargeDelay) {
164  if (battery->getHolder().getSpeed() < battery->getStoppingTreshold()) {
165  status = "chargingStopped";
166  } else if (myChargeInTransit == true) {
167  status = "chargingInTransit";
168  } else {
169  status = "noCharging";
170  }
171  } else {
172  if (myChargeInTransit == true) {
173  status = "waitingChargeInTransit";
174  } else if (battery->getHolder().getSpeed() < battery->getStoppingTreshold()) {
175  status = "waitingChargeStopped";
176  } else {
177  status = "noWaitingCharge";
178  }
179  }
180  // update total charge
181  myTotalCharge += WCharged;
182  // create charge row and insert it in myChargeValues
183  charge C(MSNet::getInstance()->getCurrentTimeStep(), battery->getHolder().getID(), battery->getHolder().getVehicleType().getID(),
184  status, WCharged, battery->getActualBatteryCapacity(), battery->getMaximumBatteryCapacity(),
186  myChargeValues.push_back(C);
187 }
188 
189 
190 void
193  output.writeAttr(SUMO_ATTR_ID, myID);
196  // start writting
197  if (myChargeValues.size() > 0) {
198  // First calculate charge for every vehicle
199  std::vector<double> charge;
200  std::vector<std::pair<SUMOTime, SUMOTime> > vectorBeginEndCharge;
201  SUMOTime firsTimeStep = myChargeValues.at(0).timeStep;
202  // set first value
203  charge.push_back(0);
204  vectorBeginEndCharge.push_back(std::pair<SUMOTime, SUMOTime>(firsTimeStep, 0));
205  // iterate over charging values
206  for (std::vector<MSChargingStation::charge>::const_iterator i = myChargeValues.begin(); i != myChargeValues.end(); i++) {
207  // update chargue
208  charge.back() += i->WCharged;
209  // update end time
210  vectorBeginEndCharge.back().second = i->timeStep;
211  // update timestep of charge
212  firsTimeStep += 1000;
213  // check if charge is continuous. If not, open a new vehicle tag
214  if (((i + 1) != myChargeValues.end()) && (((i + 1)->timeStep) != firsTimeStep)) {
215  // set new firsTimeStep of charge
216  firsTimeStep = (i + 1)->timeStep;
217  charge.push_back(0);
218  vectorBeginEndCharge.push_back(std::pair<SUMOTime, SUMOTime>(firsTimeStep, 0));
219  }
220  }
221  // now write values
222  firsTimeStep = myChargeValues.at(0).timeStep;
223  int vehicleCounter = 0;
224  // open tag for first vehicle and write id and type of vehicle
225  output.openTag(SUMO_TAG_VEHICLE);
226  output.writeAttr(SUMO_ATTR_ID, myChargeValues.at(0).vehicleID);
227  output.writeAttr(SUMO_ATTR_TYPE, myChargeValues.at(0).vehicleType);
229  output.writeAttr(SUMO_ATTR_CHARGINGBEGIN, time2string(vectorBeginEndCharge.at(0).first));
230  output.writeAttr(SUMO_ATTR_CHARGINGEND, time2string(vectorBeginEndCharge.at(0).second));
231  // iterate over charging values
232  for (std::vector<MSChargingStation::charge>::const_iterator i = myChargeValues.begin(); i != myChargeValues.end(); i++) {
233  // open tag for timestep and write all parameters
234  output.openTag(SUMO_TAG_STEP);
235  output.writeAttr(SUMO_ATTR_TIME, time2string(i->timeStep));
236  // charge values
237  output.writeAttr(SUMO_ATTR_CHARGING_STATUS, i->status);
238  output.writeAttr(SUMO_ATTR_ENERGYCHARGED, i->WCharged);
239  output.writeAttr(SUMO_ATTR_PARTIALCHARGE, i->totalEnergyCharged);
240  // charging values of charging station in this timestep
241  output.writeAttr(SUMO_ATTR_CHARGINGPOWER, i->chargingPower);
242  output.writeAttr(SUMO_ATTR_EFFICIENCY, i->chargingEfficiency);
243  // battery status of vehicle
244  output.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, i->actualBatteryCapacity);
245  output.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, i->maxBatteryCapacity);
246  // close tag timestep
247  output.closeTag();
248  // update timestep of charge
249  firsTimeStep += 1000;
250  // check if charge is continuous. If not, open a new vehicle tag
251  if (((i + 1) != myChargeValues.end()) && (((i + 1)->timeStep) != firsTimeStep)) {
252  // set new firsTimeStep of charge
253  firsTimeStep = (i + 1)->timeStep;
254  // update counter
255  vehicleCounter++;
256  // close previous vehicle tag
257  output.closeTag();
258  // open tag for new vehicle and write id and type of vehicle
259  output.openTag(SUMO_TAG_VEHICLE);
260  output.writeAttr(SUMO_ATTR_ID, (i + 1)->vehicleID);
261  output.writeAttr(SUMO_ATTR_TYPE, (i + 1)->vehicleType);
262  output.writeAttr(SUMO_ATTR_TOTALENERGYCHARGED_VEHICLE, charge.at(vehicleCounter));
263  output.writeAttr(SUMO_ATTR_CHARGINGBEGIN, vectorBeginEndCharge.at(vehicleCounter).first);
264  output.writeAttr(SUMO_ATTR_CHARGINGEND, vectorBeginEndCharge.at(vehicleCounter).second);
265  }
266  }
267  // close vehicle tag
268  output.closeTag();
269  }
270  // close charging station tag
271  output.closeTag();
272 }
273 
274 /****************************************************************************/
SUMO_ATTR_TYPE
Definition: SUMOXMLDefinitions.h:381
MSChargingStation::getChargingPower
double getChargingPower() const
Get charging station's charging power.
Definition: MSChargingStation.cpp:79
MSDevice_Battery::getMaximumBatteryCapacity
double getMaximumBatteryCapacity() const
Get the total vehicle's Battery Capacity in kWh.
Definition: MSDevice_Battery.cpp:353
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
MSStoppingPlace
A lane area vehicles can halt at.
Definition: MSStoppingPlace.h:59
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSDevice_Battery::getStoppingTreshold
double getStoppingTreshold() const
Get stopping treshold.
Definition: MSDevice_Battery.cpp:410
MSStoppingPlace::getEndLanePosition
double getEndLanePosition() const
Returns the end position of this stop.
Definition: MSStoppingPlace.cpp:69
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
MSDevice_Battery::getActualBatteryCapacity
double getActualBatteryCapacity() const
Get the actual vehicle's Battery Capacity in kWh.
Definition: MSDevice_Battery.cpp:347
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
MSStoppingPlace::getBeginLanePosition
double getBeginLanePosition() const
Returns the begin position of this stop.
Definition: MSStoppingPlace.cpp:63
MSChargingStation::myChargeInTransit
bool myChargeInTransit
Allow charge in transit.
Definition: MSChargingStation.h:155
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSChargingStation::setChargeDelay
void setChargeDelay(double chargeDelay)
Set charge delay of the charging station.
Definition: MSChargingStation.cpp:129
SUMO_ATTR_MAXIMUMBATTERYCAPACITY
Maxium battery capacity.
Definition: SUMOXMLDefinitions.h:483
MSChargingStation.h
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
MSChargingStation::myChargeValues
std::vector< charge > myChargeValues
vector with the charges of this charging station
Definition: MSChargingStation.h:167
MSDevice_Battery.h
MSChargingStation::charge::WCharged
double WCharged
Definition: MSChargingStation.h:135
MSChargingStation::myChargeDelay
double myChargeDelay
Charge Delay.
Definition: MSChargingStation.h:158
MSChargingStation::~MSChargingStation
~MSChargingStation()
destructor
Definition: MSChargingStation.cpp:74
SUMO_ATTR_TOTALENERGYCHARGED
Definition: SUMOXMLDefinitions.h:533
MSChargingStation::charge
struct to save information for the cahrgingStation output
Definition: MSChargingStation.h:110
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
MSChargingStation::setChargingVehicle
void setChargingVehicle(bool value)
enable or disable charging vehicle
Definition: MSChargingStation.cpp:139
MSVehicleType.h
MSChargingStation::setChargeInTransit
void setChargeInTransit(bool chargeInTransit)
Set charge in transit of the charging station.
Definition: MSChargingStation.cpp:123
MSChargingStation::getEfficency
double getEfficency() const
Get efficiency of the charging station.
Definition: MSChargingStation.cpp:85
MSChargingStation::myTotalCharge
double myTotalCharge
total energy charged by this charging station
Definition: MSChargingStation.h:164
MSChargingStation::setEfficency
void setEfficency(double efficency)
Set efficiency of the charging station.
Definition: MSChargingStation.cpp:113
SUMO_ATTR_CHARGEDELAY
Delay in the charge of charging stations.
Definition: SUMOXMLDefinitions.h:475
SUMO_ATTR_CHARGINGSTEPS
number of steps that a vehicle is charging
Definition: SUMOXMLDefinitions.h:535
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
SUMOVehicle.h
SUMO_ATTR_CHARGINGPOWER
Definition: SUMOXMLDefinitions.h:469
SUMO_TAG_CHARGING_STATION
A Charging Station.
Definition: SUMOXMLDefinitions.h:111
SUMO_ATTR_CHARGINGEND
timesteps in which charging ends
Definition: SUMOXMLDefinitions.h:541
MSChargingStation::writeChargingStationOutput
void writeChargingStationOutput(OutputDevice &output)
write charging station values
Definition: MSChargingStation.cpp:191
MSChargingStation::myEfficiency
double myEfficiency
Efficiency of the charging station.
Definition: MSChargingStation.h:152
SUMO_ATTR_ACTUALBATTERYCAPACITY
Definition: SUMOXMLDefinitions.h:481
MSChargingStation::myChargingPower
double myChargingPower
Charging station's charging power.
Definition: MSChargingStation.h:149
SUMO_TAG_STEP
trigger: a step description
Definition: SUMOXMLDefinitions.h:157
MSVehicleDevice::getHolder
SUMOVehicle & getHolder() const
Returns the vehicle that holds this device.
Definition: MSVehicleDevice.h:74
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSDevice_Battery
Battery device for electric vehicles.
Definition: MSDevice_Battery.h:45
MSTrigger.h
SUMO_ATTR_TOTALENERGYCHARGED_VEHICLE
total energy charged into a single vehicle
Definition: SUMOXMLDefinitions.h:537
SUMO_TAG_VEHICLE
description of a vehicle
Definition: SUMOXMLDefinitions.h:119
SUMO_ATTR_TIME
trigger: the time of the step
Definition: SUMOXMLDefinitions.h:676
MSChargingStation::myChargingVehicle
bool myChargingVehicle
Check if in the current TimeStep chargingStation is charging a vehicle.
Definition: MSChargingStation.h:161
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
SUMO_ATTR_CHARGING_STATUS
Definition: SUMOXMLDefinitions.h:513
MSChargingStation::MSChargingStation
MSChargingStation(const std::string &chargingStationID, MSLane &lane, double startPos, double endPos, const std::string &name, double chargingPower, double efficency, bool chargeInTransit, double chargeDelay)
constructor
Definition: MSChargingStation.cpp:40
MSChargingStation::setChargingPower
void setChargingPower(double chargingPower)
Set charging station's charging power.
Definition: MSChargingStation.cpp:103
MSChargingStation::isCharging
bool isCharging() const
Return true if in the current time step charging station is charging a vehicle.
Definition: MSChargingStation.cpp:155
SUMO_ATTR_EFFICIENCY
Eficiency of the charge in Charging Stations.
Definition: SUMOXMLDefinitions.h:471
MSChargingStation::vehicleIsInside
bool vehicleIsInside(const double position) const
Check if a vehicle is inside in the Charge Station.
Definition: MSChargingStation.cpp:145
SUMO_ATTR_PARTIALCHARGE
energy provied by charging station at certain timestep
Definition: SUMOXMLDefinitions.h:543
config.h
MSChargingStation::addChargeValueForOutput
void addChargeValueForOutput(double WCharged, MSDevice_Battery *battery)
add charge value for output
Definition: MSChargingStation.cpp:161
SUMO_ATTR_ENERGYCHARGED
tgotal of Energy charged
Definition: SUMOXMLDefinitions.h:519
Named::myID
std::string myID
The name of the object.
Definition: Named.h:133
MSChargingStation::getChargeDelay
double getChargeDelay() const
Get Charge Delay.
Definition: MSChargingStation.cpp:97
MSStoppingPlace.h
MSDevice_Battery::getChargingStartTime
double getChargingStartTime() const
Get charging start time.
Definition: MSDevice_Battery.cpp:383
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
SUMO_ATTR_CHARGINGBEGIN
timestep in which charging begins
Definition: SUMOXMLDefinitions.h:539
MSChargingStation::getChargeInTransit
bool getChargeInTransit() const
Get chargeInTransit.
Definition: MSChargingStation.cpp:91
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.