SUMO - Simulation of Urban MObility
TraCI_Lane.cpp
Go to the documentation of this file.
1 /****************************************************************************/
12 // C++ TraCI client API implementation
13 /****************************************************************************/
14 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
15 // Copyright (C) 2017-2017 DLR (http://www.dlr.de/) and contributors
16 /****************************************************************************/
17 //
18 // This file is part of SUMO.
19 // SUMO is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21 // the Free Software Foundation, either version 3 of the License, or
22 // (at your option) any later version.
23 //
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <microsim/MSNet.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSEdge.h>
39 #include <microsim/MSVehicle.h>
40 #include "TraCI_Lane.h"
41 
42 
43 // ===========================================================================
44 // member definitions
45 // ===========================================================================
46 std::vector<std::string>
48  std::vector<std::string> ids;
49  MSLane::insertIDs(ids);
50  return ids;
51 }
52 
53 
54 int
56  return (int)getIDList().size();
57 }
58 
59 
60 std::string
61 TraCI_Lane::getEdgeID(std::string laneID) {
62  return getLane(laneID)->getEdge().getID();
63 }
64 
65 
66 double
67 TraCI_Lane::getLength(std::string laneID) {
68  return getLane(laneID)->getLength();
69 }
70 
71 
72 double
73 TraCI_Lane::getMaxSpeed(std::string laneID) {
74  return getLane(laneID)->getSpeedLimit();
75 }
76 
77 
78 int
79 TraCI_Lane::getLinkNumber(std::string laneID) {
80  return (int) getLane(laneID)->getLinkCont().size();
81 }
82 
83 
84 std::vector<TraCIConnection>
85 TraCI_Lane::getLinks(std::string laneID) {
86  std::vector<TraCIConnection> v;
87  const MSLane* lane = getLane(laneID);
88  const SUMOTime currTime = MSNet::getInstance()->getCurrentTimeStep();
89  const MSLinkCont& links = lane->getLinkCont();
90  for (MSLinkCont::const_iterator i = links.begin(); i != links.end(); ++i) {
91  MSLink* link = (*i);
92  const std::string approachedLane = link->getLane() != 0 ? link->getLane()->getID() : "";
93  const bool hasPrio = link->havePriority() ? 1 : 0;
94  const double speed = MIN2(lane->getSpeedLimit(), link->getLane()->getSpeedLimit());
95  const bool isOpen = link->opened(currTime, speed, speed, SUMOVTypeParameter::getDefault().length,
97  const bool hasFoe = link->hasApproachingFoe(currTime, currTime, 0, SUMOVTypeParameter::getDefaultDecel()) ? 1 : 0;
98  const std::string approachedInternal = link->getViaLane() != 0 ? link->getViaLane()->getID() : "";
99  const std::string state = SUMOXMLDefinitions::LinkStates.getString(link->getState());
100  const std::string direction = SUMOXMLDefinitions::LinkDirections.getString(link->getDirection());
101  const double length = link->getLength();
102  v.push_back(TraCIConnection(approachedLane, hasPrio, isOpen, hasFoe, approachedInternal, state, direction, length));
103  }
104  return v;
105 }
106 
107 
108 std::vector<std::string>
109 TraCI_Lane::getAllowed(std::string laneID) {
110  SVCPermissions permissions = getLane(laneID)->getPermissions();
111  if (permissions == SVCAll) { // special case: write nothing
112  permissions = 0;
113  }
114  return getVehicleClassNamesList(permissions);
115 }
116 
117 
118 std::vector<std::string>
119 TraCI_Lane::getDisallowed(std::string laneID) {
120  return getVehicleClassNamesList(~(getLane(laneID)->getPermissions())); // negation yields disallowed
121 }
122 
123 
125 TraCI_Lane::getShape(std::string laneID) {
127  const PositionVector& shp = getLane(laneID)->getShape();
128  for (PositionVector::const_iterator pi = shp.begin(); pi != shp.end(); ++pi) {
129  TraCIPosition p;
130  p.x = pi->x();
131  p.y = pi->y();
132  p.z = pi->z();
133  pv.push_back(p);
134  }
135  return pv;
136 }
137 
138 
139 double
140 TraCI_Lane::getWidth(std::string laneID) {
141  return getLane(laneID)->getWidth();
142 }
143 
144 
145 double
146 TraCI_Lane::getCO2Emission(std::string laneID) {
147  return getLane(laneID)->getCO2Emissions();
148 }
149 
150 
151 double
152 TraCI_Lane::getCOEmission(std::string laneID) {
153  return getLane(laneID)->getCOEmissions();
154 }
155 
156 
157 double
158 TraCI_Lane::getHCEmission(std::string laneID) {
159  return getLane(laneID)->getHCEmissions();
160 }
161 
162 
163 double
164 TraCI_Lane::getPMxEmission(std::string laneID) {
165  return getLane(laneID)->getPMxEmissions();
166 }
167 
168 
169 double
170 TraCI_Lane::getNOxEmission(std::string laneID) {
171  return getLane(laneID)->getNOxEmissions();
172 }
173 
174 double
175 TraCI_Lane::getFuelConsumption(std::string laneID) {
176  return getLane(laneID)->getFuelConsumption();
177 }
178 
179 
180 double
181 TraCI_Lane::getNoiseEmission(std::string laneID) {
182  return getLane(laneID)->getHarmonoise_NoiseEmissions();
183 }
184 
185 
186 double
188  return getLane(laneID)->getElectricityConsumption();
189 }
190 
191 
192 double
193 TraCI_Lane::getLastStepMeanSpeed(std::string laneID) {
194  return getLane(laneID)->getMeanSpeed();
195 }
196 
197 
198 double
199 TraCI_Lane::getLastStepOccupancy(std::string laneID) {
200  return getLane(laneID)->getNettoOccupancy();
201 }
202 
203 
204 double
205 TraCI_Lane::getLastStepLength(std::string laneID) {
206  const MSLane* lane = getLane(laneID);
207  double length = 0;
208  const MSLane::VehCont& vehs = lane->getVehiclesSecure();
209  for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
210  length += (*j)->getVehicleType().getLength();
211  }
212  if (vehs.size() > 0) {
213  length = length / (double) vehs.size();
214  }
215  lane->releaseVehicles();
216  return length;
217 }
218 
219 
220 double
221 TraCI_Lane::getWaitingTime(std::string laneID) {
222  return getLane(laneID)->getWaitingSeconds();
223 }
224 
225 
226 double
227 TraCI_Lane::getTraveltime(std::string laneID) {
228  const MSLane* lane = getLane(laneID);
229  double meanSpeed = lane->getMeanSpeed();
230  if (meanSpeed != 0) {
231  return lane->getLength() / meanSpeed;
232  } else {
233  return 1000000.;
234  }
235 }
236 
237 
238 int
240  return (int) getLane(laneID)->getVehicleNumber();
241 }
242 
243 int
245  const MSLane* lane = getLane(laneID);
246  int halting = 0;
247  const MSLane::VehCont& vehs = lane->getVehiclesSecure();
248  for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
249  if ((*j)->getSpeed() < SUMO_const_haltingSpeed) {
250  ++halting;
251  }
252  }
253  lane->releaseVehicles();
254  return halting;
255 }
256 
257 
258 std::vector<std::string>
260  const MSLane* lane = getLane(laneID);
261  std::vector<std::string> vehIDs;
262  const MSLane::VehCont& vehs = lane->getVehiclesSecure();
263  for (MSLane::VehCont::const_iterator j = vehs.begin(); j != vehs.end(); ++j) {
264  vehIDs.push_back((*j)->getID());
265  }
266  lane->releaseVehicles();
267  return vehIDs;
268 }
269 
270 
271 
272 
273 void
274 TraCI_Lane::setAllowed(std::string laneID, std::vector<std::string> allowedClasses) {
275  MSLane* l = const_cast<MSLane*>(getLane(laneID));
278 }
279 
280 
281 void
282 TraCI_Lane::setDisallowed(std::string laneID, std::vector<std::string> disallowedClasses) {
283  MSLane* l = const_cast<MSLane*>(getLane(laneID));
284  l->setPermissions(~parseVehicleClasses(disallowedClasses), MSLane::CHANGE_PERMISSIONS_PERMANENT); // negation yields allowed
286 }
287 
288 
289 void
290 TraCI_Lane::setMaxSpeed(std::string laneID, double speed) {
291  MSLane* l = const_cast<MSLane*>(getLane(laneID));
292  l->setMaxSpeed(speed);
293 }
294 
295 
296 void
297 TraCI_Lane::setLength(std::string laneID, double length) {
298  MSLane* l = const_cast<MSLane*>(getLane(laneID));
299  l->setLength(length);
300 }
301 
302 
303 std::string
304 TraCI_Lane::getParameter(const std::string& laneID, const std::string& param) {
305  return getLane(laneID)->getParameter(param, "");
306 }
307 
308 
309 void
310 TraCI_Lane::setParameter(const std::string& laneID, const std::string& key, const std::string& value) {
311  MSLane* l = const_cast<MSLane*>(getLane(laneID));
312  l->addParameter(key, value);
313 }
314 
315 
316 const MSLane*
317 TraCI_Lane::getLane(const std::string& id) {
318  const MSLane* r = MSLane::dictionary(id);
319  if (r == 0) {
320  throw TraCIException("Lane '" + id + "' is not known");
321  }
322  return r;
323 }
324 
325 
326 /****************************************************************************/
static double getCO2Emission(std::string laneID)
Definition: TraCI_Lane.cpp:146
double x
Definition: TraCIDefs.h:72
static int getLastStepHaltingNumber(std::string laneID)
Definition: TraCI_Lane.cpp:244
double getNOxEmissions() const
Returns the sum of last step NOx emissions.
Definition: MSLane.cpp:2201
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
static void insertIDs(std::vector< std::string > &into)
Adds the ids of all stored lanes into the given vector.
Definition: MSLane.cpp:1403
static double getHCEmission(std::string laneID)
Definition: TraCI_Lane.cpp:158
static double getLength(std::string laneID)
Definition: TraCI_Lane.cpp:67
static std::vector< std::string > getLastStepVehicleIDs(std::string laneID)
Definition: TraCI_Lane.cpp:259
double getFuelConsumption() const
Returns the sum of last step fuel consumption.
Definition: MSLane.cpp:2225
static double getWaitingTime(std::string laneID)
Definition: TraCI_Lane.cpp:221
void setMaxSpeed(double val)
Sets a new maximum speed for the lane (used by TraCI and MSCalibrator)
Definition: MSLane.cpp:1642
static void setAllowed(std::string laneID, std::vector< std::string > allowedClasses)
Definition: TraCI_Lane.cpp:274
const std::string & getString(const T key) const
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
std::vector< std::string > getVehicleClassNamesList(SVCPermissions permissions)
Returns the ids of the given classes, divided using a &#39; &#39;.
static double getElectricityConsumption(std::string laneID)
Definition: TraCI_Lane.cpp:187
static std::string getEdgeID(std::string laneID)
Definition: TraCI_Lane.cpp:61
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
static std::vector< std::string > getIDList()
Definition: TraCI_Lane.cpp:47
double getPMxEmissions() const
Returns the sum of last step PMx emissions.
Definition: MSLane.cpp:2189
double getLength() const
Returns the lane&#39;s length.
Definition: MSLane.h:484
virtual const VehCont & getVehiclesSecure() const
Returns the vehicles container; locks it for microsimulation.
Definition: MSLane.h:379
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
static std::vector< TraCIConnection > getLinks(std::string laneID)
Definition: TraCI_Lane.cpp:85
static double getNoiseEmission(std::string laneID)
Definition: TraCI_Lane.cpp:181
const std::string & getID() const
Returns the id.
Definition: Named.h:66
static StringBijection< LinkState > LinkStates
link states
const SVCPermissions SVCAll
all VClasses are allowed
static void setDisallowed(std::string laneID, std::vector< std::string > disallowedClasses)
Definition: TraCI_Lane.cpp:282
double getWidth() const
Returns the lane&#39;s width.
Definition: MSLane.h:500
static double getWidth(std::string laneID)
Definition: TraCI_Lane.cpp:140
static double getLastStepMeanSpeed(std::string laneID)
Definition: TraCI_Lane.cpp:193
double z
Definition: TraCIDefs.h:72
static StringBijection< LinkDirection > LinkDirections
link directions
static double getNOxEmission(std::string laneID)
Definition: TraCI_Lane.cpp:170
void rebuildAllowedLanes()
Definition: MSEdge.cpp:243
double getCO2Emissions() const
Returns the sum of last step CO2 emissions.
Definition: MSLane.cpp:2165
void setLength(double val)
Sets a new length for the lane (used by TraCI only)
Definition: MSLane.cpp:1649
A 3D-position.
Definition: TraCIDefs.h:71
static double getLastStepLength(std::string laneID)
Definition: TraCI_Lane.cpp:205
A list of positions.
int getVehicleNumber() const
Returns the number of vehicles on this lane (for which this lane is responsible)
Definition: MSLane.h:352
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:492
double getSpeedLimit() const
Returns the lane&#39;s maximum allowed speed.
Definition: MSLane.h:476
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:257
T MIN2(T a, T b)
Definition: StdDefs.h:64
static double getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
static double getTraveltime(std::string laneID)
Definition: TraCI_Lane.cpp:227
SVCPermissions parseVehicleClasses(const std::string &allowedS)
Parses the given definition of allowed vehicle classes into the given containers Deprecated classes g...
double getHCEmissions() const
Returns the sum of last step HC emissions.
Definition: MSLane.cpp:2213
std::vector< MSVehicle * > VehCont
Container for vehicles.
Definition: MSLane.h:91
static int getIDCount()
Definition: TraCI_Lane.cpp:55
void addParameter(const std::string &key, const std::string &value)
Adds a parameter.
const std::string & getParameter(const std::string &key, const std::string &defaultValue) const
Returns the value for a given key.
static std::string getParameter(const std::string &laneID, const std::string &param)
Definition: TraCI_Lane.cpp:304
void setPermissions(SVCPermissions permissions, long transientID)
Sets the permissions to the given value. If a transientID is given, the permissions are recored as te...
Definition: MSLane.cpp:2810
double getElectricityConsumption() const
Returns the sum of last step electricity consumption.
Definition: MSLane.cpp:2237
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition: MSLane.cpp:1371
static std::vector< std::string > getAllowed(std::string laneID)
Definition: TraCI_Lane.cpp:109
double getCOEmissions() const
Returns the sum of last step CO emissions.
Definition: MSLane.cpp:2177
static TraCIPositionVector getShape(std::string laneID)
Definition: TraCI_Lane.cpp:125
static double getLastStepOccupancy(std::string laneID)
Definition: TraCI_Lane.cpp:199
static double getFuelConsumption(std::string laneID)
Definition: TraCI_Lane.cpp:175
static int getLinkNumber(std::string laneID)
Definition: TraCI_Lane.cpp:79
double getHarmonoise_NoiseEmissions() const
Returns the sum of last step noise emissions.
Definition: MSLane.cpp:2249
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Definition: StdDefs.h:56
static void setParameter(const std::string &routeID, const std::string &key, const std::string &value)
Definition: TraCI_Lane.cpp:310
static void setLength(std::string laneID, double length)
Definition: TraCI_Lane.cpp:297
static const MSLane * getLane(const std::string &id)
Definition: TraCI_Lane.cpp:317
long long int SUMOTime
Definition: TraCIDefs.h:52
double getMeanSpeed() const
Returns the mean speed on this lane.
Definition: MSLane.cpp:2149
static double getCOEmission(std::string laneID)
Definition: TraCI_Lane.cpp:152
double y
Definition: TraCIDefs.h:72
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1597
static const long CHANGE_PERMISSIONS_PERMANENT
Definition: MSLane.h:1019
static int getLastStepVehicleNumber(std::string laneID)
Definition: TraCI_Lane.cpp:239
static const SUMOVTypeParameter & getDefault()
return the default parameters, this is a function due to the http://www.parashift.com/c++-faq/static-init-order.html
virtual void releaseVehicles() const
Allows to use the container for microsimulation again.
Definition: MSLane.h:406
double getNettoOccupancy() const
Returns the netto (excluding minGaps) occupancy of this lane during the last step (including minGaps)...
Definition: MSLane.cpp:2121
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A list of positions.
double getWaitingSeconds() const
Returns the overall waiting time on this lane.
Definition: MSLane.cpp:2136
static double getPMxEmission(std::string laneID)
Definition: TraCI_Lane.cpp:164
static std::vector< std::string > getDisallowed(std::string laneID)
Definition: TraCI_Lane.cpp:119
static void setMaxSpeed(std::string laneID, double speed)
Definition: TraCI_Lane.cpp:290
static double getMaxSpeed(std::string laneID)
Definition: TraCI_Lane.cpp:73