Eclipse SUMO - Simulation of Urban MObility
MultiEntryExit.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 "MultiEntryExit.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 MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
61  return getDetector(detID)->getVehiclesWithin();
62 }
63 
64 
65 double
66 MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
67  return getDetector(detID)->getCurrentMeanSpeed();
68 }
69 
70 
71 std::vector<std::string>
72 MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
73  return getDetector(detID)->getCurrentVehicleIDs();
74 }
75 
76 
77 int
78 MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
79  return getDetector(detID)->getCurrentHaltingNumber();
80 }
81 
82 
84 
85 
87 MultiEntryExit::getDetector(const std::string& id) {
88  MSE3Collector* e3 = dynamic_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
89  if (e3 == nullptr) {
90  throw TraCIException("Multi entry exit detector '" + id + "' is not known");
91  }
92  return e3;
93 }
94 
95 
96 std::shared_ptr<VariableWrapper>
98  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
99 }
100 
101 
102 bool
103 MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
104  switch (variable) {
105  case TRACI_ID_LIST:
106  return wrapper->wrapStringList(objID, variable, getIDList());
107  case ID_COUNT:
108  return wrapper->wrapInt(objID, variable, getIDCount());
110  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
112  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
114  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
116  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
117  default:
118  return false;
119  }
120 }
121 
122 
123 }
124 
125 
126 /****************************************************************************/
MultiEntryExit.h
MSE3Collector::getCurrentHaltingNumber
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
Definition: MSE3Collector.cpp:551
MSE3Collector::getVehiclesWithin
int getVehiclesWithin() const
Returns the number of vehicles within the area.
Definition: MSE3Collector.cpp:557
libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
Definition: TraCIConstants.h:525
libsumo::MultiEntryExit::getIDList
static std::vector< std::string > getIDList()
Definition: MultiEntryExit.cpp:45
MSNet::getDetectorControl
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:399
libsumo::MultiEntryExit::myContextSubscriptionResults
static ContextSubscriptionResults myContextSubscriptionResults
Definition: MultiEntryExit.h:66
MSNet.h
MSDetectorControl.h
MSE3Collector
A detector of vehicles passing an area between entry/exit points.
Definition: MSE3Collector.h:60
NamedObjectCont::insertIDs
void insertIDs(std::vector< std::string > &into) const
Definition: NamedObjectCont.h:123
libsumo::VariableWrapper
Definition: Subscription.h:132
libsumo::MultiEntryExit::getLastStepVehicleIDs
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
Definition: MultiEntryExit.cpp:72
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:204
libsumo::MultiEntryExit::handleVariable
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: MultiEntryExit.cpp:103
libsumo::LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
Definition: TraCIConstants.h:519
MSE2Collector.h
MSE3Collector::getCurrentVehicleIDs
std::vector< std::string > getCurrentVehicleIDs() const
Returns the number of vehicles within the area.
Definition: MSE3Collector.cpp:563
libsumo::MultiEntryExit::mySubscriptionResults
static SubscriptionResults mySubscriptionResults
Definition: MultiEntryExit.h:65
libsumo
Definition: Edge.cpp:29
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
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::TRACI_ID_LIST
TRACI_CONST int TRACI_ID_LIST
Definition: TraCIConstants.h:498
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:50
MSE3Collector::getCurrentMeanSpeed
double getCurrentMeanSpeed() const
Returns the mean speed within the area.
Definition: MSE3Collector.cpp:545
libsumo::MultiEntryExit::getDetector
static MSE3Collector * getDetector(const std::string &detID)
Definition: MultiEntryExit.cpp:87
libsumo::ID_COUNT
TRACI_CONST int ID_COUNT
Definition: TraCIConstants.h:501
libsumo::TraCIException
Definition: TraCIDefs.h:89
libsumo::MultiEntryExit::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: MultiEntryExit.cpp:97
libsumo::MultiEntryExit::getLastStepHaltingNumber
static int getLastStepHaltingNumber(const std::string &detID)
Definition: MultiEntryExit.cpp:78
libsumo::MultiEntryExit::getLastStepMeanSpeed
static double getLastStepMeanSpeed(const std::string &detID)
Definition: MultiEntryExit.cpp:66
SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
Definition: SUMOXMLDefinitions.h:75
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
libsumo::MultiEntryExit
Definition: MultiEntryExit.h:46
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
config.h
libsumo::LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
Definition: TraCIConstants.h:513
libsumo::MultiEntryExit::getLastStepVehicleNumber
static int getLastStepVehicleNumber(const std::string &detID)
Definition: MultiEntryExit.cpp:60
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:203
libsumo::MultiEntryExit::getIDCount
static int getIDCount()
Definition: MultiEntryExit.cpp:53