Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/ChargingStation.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2017-2024 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// C++ TraCI client API implementation
19/****************************************************************************/
20#include <config.h>
21
22#include <microsim/MSNet.h>
23#include <microsim/MSLane.h>
28#include "Helper.h"
29#include "ChargingStation.h"
30
31
32namespace libsumo {
33// ===========================================================================
34// static member initializations
35// ===========================================================================
36
37SubscriptionResults ChargingStation::mySubscriptionResults;
38ContextSubscriptionResults ChargingStation::myContextSubscriptionResults;
39
40// ===========================================================================
41// static member definitions
42// ===========================================================================
43
44std::vector<std::string>
45ChargingStation::getIDList() {
46 std::vector<std::string> ids;
47 for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_CHARGING_STATION)) {
48 ids.push_back(item.first);
49 }
50 std::sort(ids.begin(), ids.end());
51 return ids;
52}
53
54
55int
56ChargingStation::getIDCount() {
57 return (int)getIDList().size();
58}
59
60
61std::string
62ChargingStation::getLaneID(const std::string& stopID) {
63 return getChargingStation(stopID)->getLane().getID();
64}
65
66double
67ChargingStation::getStartPos(const std::string& stopID) {
68 return getChargingStation(stopID)->getBeginLanePosition();
69}
70
71
72double
73ChargingStation::getEndPos(const std::string& stopID) {
74 return getChargingStation(stopID)->getEndLanePosition();
75}
76
77
78std::string
79ChargingStation::getName(const std::string& stopID) {
80 return getChargingStation(stopID)->getMyName();
81}
82
83
84int
85ChargingStation::getVehicleCount(const std::string& stopID) {
86 return (int)getChargingStation(stopID)->getStoppedVehicles().size();
87}
88
89
90std::vector<std::string>
91ChargingStation::getVehicleIDs(const std::string& stopID) {
92 std::vector<std::string> result;
93 for (const SUMOVehicle* veh : getChargingStation(stopID)->getStoppedVehicles()) {
94 result.push_back(veh->getID());
95 }
96 return result;
97}
98
99
100double
101ChargingStation::getChargingPower(const std::string& stopID) {
102 return dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->getChargingPower(true);
103}
104
105
106double
107ChargingStation::getEfficiency(const std::string& stopID) {
108 return dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->getEfficency();
109}
110
111
112double
113ChargingStation::getChargeDelay(const std::string& stopID) {
114 return STEPS2TIME(dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->getChargeDelay());
115}
116
117
118int
119ChargingStation::getChargeInTransit(const std::string& stopID) {
120 return dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->getChargeInTransit();
121}
122
123
124void
125ChargingStation::setChargingPower(const std::string& stopID, double chargingpower) {
126 dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->setChargingPower(chargingpower);
127}
128
129
130void
131ChargingStation::setEfficiency(const std::string& stopID, double efficiency) {
132 dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->setEfficiency(efficiency);
133}
134
135
136void
137ChargingStation::setChargeDelay(const std::string& stopID, double delay) {
138 dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->setChargeDelay(TIME2STEPS(delay));
139}
140
141
142void
143ChargingStation::setChargeInTransit(const std::string& stopID, bool value) {
144 dynamic_cast<MSChargingStation*>(getChargingStation(stopID))->setChargeInTransit(value);
145}
146
147
148std::string
149ChargingStation::getParameter(const std::string& stopID, const std::string& param) {
150 return getChargingStation(stopID)->getParameter(param, "");
151}
152
153
155
156void
157ChargingStation::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
158 getChargingStation(stopID)->setParameter(key, value);
159}
160
161
163
164
166ChargingStation::getChargingStation(const std::string& id) {
168}
169
170
171std::shared_ptr<VariableWrapper>
172ChargingStation::makeWrapper() {
173 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
174}
175
176
177bool
178ChargingStation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
179 switch (variable) {
180 case TRACI_ID_LIST:
181 return wrapper->wrapStringList(objID, variable, getIDList());
182 case ID_COUNT:
183 return wrapper->wrapInt(objID, variable, getIDCount());
184 case VAR_LANE_ID:
185 return wrapper->wrapString(objID, variable, getLaneID(objID));
186 case VAR_POSITION:
187 return wrapper->wrapDouble(objID, variable, getStartPos(objID));
188 case VAR_LANEPOSITION:
189 return wrapper->wrapDouble(objID, variable, getEndPos(objID));
190 case VAR_NAME:
191 return wrapper->wrapString(objID, variable, getName(objID));
193 return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
195 return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
196 case VAR_CS_POWER:
197 return wrapper->wrapDouble(objID, variable, getChargingPower(objID));
199 return wrapper->wrapDouble(objID, variable, getEfficiency(objID));
201 return wrapper->wrapDouble(objID, variable, STEPS2TIME(getChargeDelay(objID)));
203 return wrapper->wrapInt(objID, variable, getChargeInTransit(objID));
205 paramData->readUnsignedByte();
206 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
208 paramData->readUnsignedByte();
209 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
210 default:
211 return false;
212 }
213}
214
215}
216
217/****************************************************************************/
@ CHARGINGSTATION
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define TIME2STEPS(x)
Definition SUMOTime.h:57
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
C++ TraCI client API implementation.
The simulated network and simulation perfomer.
Definition MSNet.h:89
A lane area vehicles can halt at.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
Representation of a vehicle.
Definition SUMOVehicle.h:62
static MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag type)
Definition Helper.cpp:527
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int VAR_NAME
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int VAR_CS_POWER
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
TRACI_CONST int VAR_CS_CHARGE_DELAY
TRACI_CONST int VAR_CS_EFFICIENCY
TRACI_CONST int VAR_CS_CHARGE_IN_TRANSIT
TRACI_CONST int VAR_POSITION
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:337
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS