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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
29 #include <microsim/MSNet.h>
30 #include <libsumo/TraCIConstants.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) {
126  MSE2Collector* e2 = dynamic_cast<MSE2Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_LANE_AREA_DETECTOR).get(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 /****************************************************************************/
libsumo::LaneArea::getDetector
static MSE2Collector * getDetector(const std::string &detID)
Definition: LaneArea.cpp:125
libsumo::VAR_LANE_ID
TRACI_CONST int VAR_LANE_ID
Definition: TraCIConstants.h:676
libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
Definition: TraCIConstants.h:523
libsumo::LaneArea::myContextSubscriptionResults
static ContextSubscriptionResults myContextSubscriptionResults
Definition: LaneArea.h:69
libsumo::LaneArea::getLastStepMeanSpeed
static double getLastStepMeanSpeed(const std::string &detID)
Definition: LaneArea.cpp:73
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:400
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:616
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:79
NamedObjectCont::insertIDs
void insertIDs(std::vector< std::string > &into) const
Definition: NamedObjectCont.h:124
libsumo::VariableWrapper
Definition: Subscription.h:114
LaneArea.h
libsumo::LaneArea::getIDCount
static int getIDCount()
Definition: LaneArea.cpp:54
SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
Definition: SUMOXMLDefinitions.h:72
libsumo::LaneArea
Definition: LaneArea.h:43
libsumo::JAM_LENGTH_VEHICLE
TRACI_CONST int JAM_LENGTH_VEHICLE
Definition: TraCIConstants.h:535
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:205
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:97
libsumo::LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
Definition: TraCIConstants.h:517
libsumo::LaneArea::getIDList
static std::vector< std::string > getIDList()
Definition: LaneArea.cpp:46
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:110
libsumo
Definition: Edge.cpp:30
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:91
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:117
TraCIConstants.h
libsumo::LaneArea::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: LaneArea.cpp:135
MSDetectorControl::getTypedDetectors
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
Definition: MSDetectorControl.cpp:104
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:141
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:496
libsumo::LaneArea::getJamLengthMeters
static double getJamLengthMeters(const std::string &detID)
Definition: LaneArea.cpp:67
libsumo::LaneArea::getLength
static double getLength(const std::string &detID)
Definition: LaneArea.cpp:103
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:51
libsumo::ID_COUNT
TRACI_CONST int ID_COUNT
Definition: TraCIConstants.h:499
libsumo::VAR_LENGTH
TRACI_CONST int VAR_LENGTH
Definition: TraCIConstants.h:625
libsumo::TraCIException
Definition: TraCIDefs.h:90
libsumo::JAM_LENGTH_METERS
TRACI_CONST int JAM_LENGTH_METERS
Definition: TraCIConstants.h:538
MSMoveReminder::getLane
const MSLane * getLane() const
Returns the lane the reminder works on.
Definition: MSMoveReminder.h:83
libsumo::LaneArea::getLastStepOccupancy
static double getLastStepOccupancy(const std::string &detID)
Definition: LaneArea.cpp:85
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
libsumo::LAST_STEP_MEAN_SPEED
TRACI_CONST int LAST_STEP_MEAN_SPEED
Definition: TraCIConstants.h:514
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:68
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:116
config.h
MSE2Collector::getCurrentVehicleNumber
int getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
Definition: MSE2Collector.cpp:1387
libsumo::LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
Definition: TraCIConstants.h:511
libsumo::LaneArea::getJamLengthVehicle
static int getJamLengthVehicle(const std::string &detID)
Definition: LaneArea.cpp:61
libsumo::LAST_STEP_OCCUPANCY
TRACI_CONST int LAST_STEP_OCCUPANCY
Definition: TraCIConstants.h:520
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSE2Collector::getCurrentVehicleIDs
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
Definition: MSE2Collector.cpp:1400
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:204