SUMO - Simulation of Urban MObility
LaneArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2018 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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
29 #include <microsim/MSNet.h>
31 #include "LaneArea.h"
32 
33 
34 namespace libsumo {
35 // ===========================================================================
36 // static member initializations
37 // ===========================================================================
40 
41 
42 // ===========================================================================
43 // static member definitions
44 // ===========================================================================
45 std::vector<std::string>
47  std::vector<std::string> ids;
49  return ids;
50 }
51 
52 
53 int
55  std::vector<std::string> ids;
57 }
58 
59 
60 int
61 LaneArea::getJamLengthVehicle(const std::string& detID) {
63 }
64 
65 
66 double
67 LaneArea::getJamLengthMeters(const std::string& detID) {
69 }
70 
71 
72 double
73 LaneArea::getLastStepMeanSpeed(const std::string& detID) {
74  return getDetector(detID)->getCurrentMeanSpeed();
75 }
76 
77 
78 std::vector<std::string>
79 LaneArea::getLastStepVehicleIDs(const std::string& detID) {
80  return getDetector(detID)->getCurrentVehicleIDs();
81 }
82 
83 
84 double
85 LaneArea::getLastStepOccupancy(const std::string& detID) {
86  return getDetector(detID)->getCurrentOccupancy();
87 }
88 
89 
90 double
91 LaneArea::getPosition(const std::string& detID) {
92  return getDetector(detID)->getStartPos();
93 }
94 
95 
96 std::string
97 LaneArea::getLaneID(const std::string& detID) {
98  return getDetector(detID)->getLane()->getID();
99 }
100 
101 
102 double
103 LaneArea::getLength(const std::string& detID) {
104  const MSE2Collector* const e2 = getDetector(detID);
105  return e2->getLength();
106 }
107 
108 
109 int
110 LaneArea::getLastStepVehicleNumber(const std::string& detID) {
111  return getDetector(detID)->getCurrentVehicleNumber();
112 }
113 
114 
115 int
116 LaneArea::getLastStepHaltingNumber(const std::string& detID) {
117  return getDetector(detID)->getCurrentHaltingNumber();
118 }
119 
120 
122 
123 
125 LaneArea::getDetector(const std::string& id) {
127  if (e2 == nullptr) {
128  throw TraCIException("Lane area detector '" + id + "' is not known");
129  }
130  return e2;
131 }
132 
133 
134 std::shared_ptr<VariableWrapper>
136  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
137 }
138 
139 
140 bool
141 LaneArea::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
142  switch (variable) {
143  case TRACI_ID_LIST:
144  return wrapper->wrapStringList(objID, variable, getIDList());
145  case ID_COUNT:
146  return wrapper->wrapInt(objID, variable, getIDCount());
148  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
150  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
152  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
154  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
155  case JAM_LENGTH_VEHICLE:
156  return wrapper->wrapInt(objID, variable, getJamLengthVehicle(objID));
157  case JAM_LENGTH_METERS:
158  return wrapper->wrapDouble(objID, variable, getJamLengthMeters(objID));
159  case LAST_STEP_OCCUPANCY:
160  return wrapper->wrapDouble(objID, variable, getLastStepOccupancy(objID));
161  case VAR_POSITION:
162  return wrapper->wrapDouble(objID, variable, getPosition(objID));
163  case VAR_LANE_ID:
164  return wrapper->wrapString(objID, variable, getLaneID(objID));
165  case VAR_LENGTH:
166  return wrapper->wrapDouble(objID, variable, getLength(objID));
167  default:
168  return false;
169  }
170 }
171 
172 
173 }
174 
175 
176 /****************************************************************************/
#define LAST_STEP_MEAN_SPEED
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:199
const MSLane * getLane() const
Returns the lane the reminder works on.
virtual bool wrapInt(const std::string &objID, const int variable, const int value)=0
#define VAR_LENGTH
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
static std::string getLaneID(const std::string &detID)
Definition: LaneArea.cpp:97
int getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
static double getPosition(const std::string &detID)
Definition: LaneArea.cpp:91
#define VAR_POSITION
An areal detector corresponding to a sequence of consecutive lanes.
Definition: MSE2Collector.h:80
int size() const
Returns the number of stored items within the container.
T get(const std::string &id) const
Retrieves an item.
double getLength() const
Returns the length of the detector.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
double getStartPos() const
Returns the begin position of the detector.
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:200
#define JAM_LENGTH_METERS
const std::string & getID() const
Returns the id.
Definition: Named.h:78
virtual bool wrapString(const std::string &objID, const int variable, const std::string &value)=0
void insertIDs(std::vector< std::string > &into) const
static int getLastStepVehicleNumber(const std::string &detID)
Definition: LaneArea.cpp:110
static double getJamLengthMeters(const std::string &detID)
Definition: LaneArea.cpp:67
static double getLength(const std::string &detID)
Definition: LaneArea.cpp:103
double getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
static int getIDCount()
Definition: LaneArea.cpp:54
#define TRACI_ID_LIST
#define JAM_LENGTH_VEHICLE
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: LaneArea.cpp:141
static double getLastStepMeanSpeed(const std::string &detID)
Definition: LaneArea.cpp:73
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:52
static int getJamLengthVehicle(const std::string &detID)
Definition: LaneArea.cpp:61
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:379
Definition: Edge.cpp:30
virtual bool wrapDouble(const std::string &objID, const int variable, const double value)=0
#define LAST_STEP_VEHICLE_NUMBER
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: LaneArea.cpp:135
#define LAST_STEP_VEHICLE_ID_LIST
static std::vector< std::string > getIDList()
Definition: LaneArea.cpp:46
double getCurrentJamLengthInMeters() const
Returns the length of all jams in meters.
static ContextSubscriptionResults myContextSubscriptionResults
Definition: LaneArea.h:69
static SubscriptionResults mySubscriptionResults
Definition: LaneArea.h:68
static int getLastStepHaltingNumber(const std::string &detID)
Definition: LaneArea.cpp:116
static double getLastStepOccupancy(const std::string &detID)
Definition: LaneArea.cpp:85
#define LAST_STEP_OCCUPANCY
#define ID_COUNT
#define VAR_LANE_ID
virtual bool wrapStringList(const std::string &objID, const int variable, const std::vector< std::string > &value)=0
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
double getCurrentOccupancy() const
Returns the current detector occupancy.
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
Definition: LaneArea.cpp:79
#define LAST_STEP_VEHICLE_HALTING_NUMBER
alternative tag for e2 detector
static MSE2Collector * getDetector(const std::string &detID)
Definition: LaneArea.cpp:125
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.