Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/ParkingArea.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-2026 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/****************************************************************************/
19// C++ TraCI client API implementation
20/****************************************************************************/
21#include <config.h>
22
24#include <microsim/MSNet.h>
25#include <microsim/MSLane.h>
29#include "Helper.h"
30#include "ParkingArea.h"
31
32
33namespace libsumo {
34// ===========================================================================
35// static member initializations
36// ===========================================================================
37SubscriptionResults ParkingArea::mySubscriptionResults;
38ContextSubscriptionResults ParkingArea::myContextSubscriptionResults;
39
40
41// ===========================================================================
42// static member definitions
43// ===========================================================================
44std::vector<std::string>
45ParkingArea::getIDList() {
46 std::vector<std::string> ids;
47 for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_PARKING_AREA)) {
48 ids.push_back(item.first);
49 }
50 std::sort(ids.begin(), ids.end());
51 return ids;
52}
53
54int
55ParkingArea::getIDCount() {
56 return (int)getIDList().size();
57}
58
59
60std::string
61ParkingArea::getLaneID(const std::string& stopID) {
62 return getParkingArea(stopID)->getLane().getID();
63}
64
65double
66ParkingArea::getStartPos(const std::string& stopID) {
67 return getParkingArea(stopID)->getBeginLanePosition();
68}
69
70double
71ParkingArea::getEndPos(const std::string& stopID) {
72 return getParkingArea(stopID)->getEndLanePosition();
73}
74
75std::string
76ParkingArea::getName(const std::string& stopID) {
77 return getParkingArea(stopID)->getMyName();
78}
79
80int
81ParkingArea::getVehicleCount(const std::string& stopID) {
82 return (int)getParkingArea(stopID)->getStoppedVehicles().size();
83}
84
85std::vector<std::string>
86ParkingArea::getVehicleIDs(const std::string& stopID) {
87 std::vector<std::string> result;
88 for (const SUMOVehicle* veh : getParkingArea(stopID)->getStoppedVehicles()) {
89 result.push_back(veh->getID());
90 }
91 return result;
92}
93
94std::vector<std::string>
95ParkingArea::getAcceptedBadges(const std::string& stopID) {
96 return dynamic_cast<MSParkingArea*>(getParkingArea(stopID))->getAcceptedBadges();
97}
98
99
100void
101ParkingArea::setAcceptedBadges(const std::string& stopID, const std::vector<std::string>& badges) {
102 dynamic_cast<MSParkingArea*>(getParkingArea(stopID))->setAcceptedBadges(badges);
103}
104
105
106std::string
107ParkingArea::getParameter(const std::string& stopID, const std::string& param) {
108 const MSParkingArea* pa = dynamic_cast<const MSParkingArea*>(getParkingArea(stopID));
109 if (param == "capacity") {
110 return toString(pa->getCapacity());
111 } else if (param == "occupancy") {
112 return toString(pa->getOccupancy());
113 } else if (param == "reservationCount") {
114 return toString(pa->getRemoteReservedVehicles().size());
115 } else if (param == "reservationIDs") {
116 std::vector<std::string> ids;
117 for (const SUMOVehicle* veh : pa->getRemoteReservedVehicles()) {
118 ids.push_back(veh->getID());
119 }
120 std::sort(ids.begin(), ids.end());
121 return toString(ids);
122 }
123 return pa->getParameter(param, "");
124}
125
126
128
129
130void
131ParkingArea::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
132 getParkingArea(stopID)->setParameter(key, value);
133}
134
135
137
138
140ParkingArea::getParkingArea(const std::string& id) {
142}
143
144
145std::shared_ptr<VariableWrapper>
146ParkingArea::makeWrapper() {
147 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
148}
149
150
151bool
152ParkingArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
153 switch (variable) {
154 case TRACI_ID_LIST:
155 return wrapper->wrapStringList(objID, variable, getIDList());
156 case ID_COUNT:
157 return wrapper->wrapInt(objID, variable, getIDCount());
158 case VAR_LANE_ID:
159 return wrapper->wrapString(objID, variable, getLaneID(objID));
160 case VAR_POSITION:
161 return wrapper->wrapDouble(objID, variable, getStartPos(objID));
162 case VAR_LANEPOSITION:
163 return wrapper->wrapDouble(objID, variable, getEndPos(objID));
164 case VAR_NAME:
165 return wrapper->wrapString(objID, variable, getName(objID));
166 case VAR_ACCESS_BADGE:
167 return wrapper->wrapStringList(objID, variable, getAcceptedBadges(objID));
169 return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
171 return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
173 paramData->readUnsignedByte();
174 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
176 paramData->readUnsignedByte();
177 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
178 default:
179 return false;
180 }
181}
182
183}
184
185
186/****************************************************************************/
@ SUMO_TAG_PARKING_AREA
A parking area.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:77
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:124
The simulated network and simulation perfomer.
Definition MSNet.h:90
A lane area vehicles can halt at.
int getCapacity() const
Returns the area capacity.
const std::set< const SUMOVehicle * > & getRemoteReservedVehicles() const
int getOccupancy() const
Returns the area occupancy.
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.
C++ TraCI client API implementation.
Representation of a vehicle.
Definition SUMOVehicle.h:63
static MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag type)
Definition Helper.cpp:566
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int VAR_ACCESS_BADGE
TRACI_CONST int VAR_NAME
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:384
TRACI_CONST int VAR_POSITION
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:383
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