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