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