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 /****************************************************************************/
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 "MultiEntryExit.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 MultiEntryExit::getLastStepVehicleNumber(const std::string& detID) {
62  return getDetector(detID)->getVehiclesWithin();
63 }
64 
65 
66 double
67 MultiEntryExit::getLastStepMeanSpeed(const std::string& detID) {
68  return getDetector(detID)->getCurrentMeanSpeed();
69 }
70 
71 
72 std::vector<std::string>
73 MultiEntryExit::getLastStepVehicleIDs(const std::string& detID) {
74  return getDetector(detID)->getCurrentVehicleIDs();
75 }
76 
77 
78 int
79 MultiEntryExit::getLastStepHaltingNumber(const std::string& detID) {
80  return getDetector(detID)->getCurrentHaltingNumber();
81 }
82 
83 
85 
86 
88 MultiEntryExit::getDetector(const std::string& id) {
89  MSE3Collector* e3 = dynamic_cast<MSE3Collector*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_ENTRY_EXIT_DETECTOR).get(id));
90  if (e3 == nullptr) {
91  throw TraCIException("Multi entry exit detector '" + id + "' is not known");
92  }
93  return e3;
94 }
95 
96 
97 std::shared_ptr<VariableWrapper>
99  return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
100 }
101 
102 
103 bool
104 MultiEntryExit::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper) {
105  switch (variable) {
106  case TRACI_ID_LIST:
107  return wrapper->wrapStringList(objID, variable, getIDList());
108  case ID_COUNT:
109  return wrapper->wrapInt(objID, variable, getIDCount());
111  return wrapper->wrapInt(objID, variable, getLastStepVehicleNumber(objID));
113  return wrapper->wrapDouble(objID, variable, getLastStepMeanSpeed(objID));
115  return wrapper->wrapStringList(objID, variable, getLastStepVehicleIDs(objID));
117  return wrapper->wrapInt(objID, variable, getLastStepHaltingNumber(objID));
118  default:
119  return false;
120  }
121 }
122 
123 
124 }
125 
126 
127 /****************************************************************************/
MultiEntryExit.h
MSE3Collector::getCurrentHaltingNumber
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
Definition: MSE3Collector.cpp:536
MSE3Collector::getVehiclesWithin
int getVehiclesWithin() const
Returns the number of vehicles within the area.
Definition: MSE3Collector.cpp:542
libsumo::LAST_STEP_VEHICLE_HALTING_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_HALTING_NUMBER
Definition: TraCIConstants.h:523
libsumo::MultiEntryExit::getIDList
static std::vector< std::string > getIDList()
Definition: MultiEntryExit.cpp:46
MSNet::getDetectorControl
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:400
libsumo::MultiEntryExit::myContextSubscriptionResults
static ContextSubscriptionResults myContextSubscriptionResults
Definition: MultiEntryExit.h:67
MSNet.h
MSDetectorControl.h
MSE3Collector
A detector of vehicles passing an area between entry/exit points.
Definition: MSE3Collector.h:58
NamedObjectCont::insertIDs
void insertIDs(std::vector< std::string > &into) const
Definition: NamedObjectCont.h:124
libsumo::VariableWrapper
Definition: Subscription.h:114
libsumo::MultiEntryExit::getLastStepVehicleIDs
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
Definition: MultiEntryExit.cpp:73
libsumo::ContextSubscriptionResults
std::map< std::string, SubscriptionResults > ContextSubscriptionResults
Definition: TraCIDefs.h:205
libsumo::MultiEntryExit::handleVariable
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: MultiEntryExit.cpp:104
libsumo::LAST_STEP_VEHICLE_ID_LIST
TRACI_CONST int LAST_STEP_VEHICLE_ID_LIST
Definition: TraCIConstants.h:517
MSE2Collector.h
MSE3Collector::getCurrentVehicleIDs
std::vector< std::string > getCurrentVehicleIDs() const
Returns the number of vehicles within the area.
Definition: MSE3Collector.cpp:548
libsumo::MultiEntryExit::mySubscriptionResults
static SubscriptionResults mySubscriptionResults
Definition: MultiEntryExit.h:66
libsumo
Definition: Edge.cpp:30
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
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::TRACI_ID_LIST
TRACI_CONST int TRACI_ID_LIST
Definition: TraCIConstants.h:496
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: TraCIDefs.h:51
MSE3Collector::getCurrentMeanSpeed
double getCurrentMeanSpeed() const
Returns the mean speed within the area.
Definition: MSE3Collector.cpp:530
libsumo::MultiEntryExit::getDetector
static MSE3Collector * getDetector(const std::string &detID)
Definition: MultiEntryExit.cpp:88
libsumo::ID_COUNT
TRACI_CONST int ID_COUNT
Definition: TraCIConstants.h:499
libsumo::TraCIException
Definition: TraCIDefs.h:90
libsumo::MultiEntryExit::makeWrapper
static LIBSUMO_SUBSCRIPTION_API std::shared_ptr< VariableWrapper > makeWrapper()
Definition: MultiEntryExit.cpp:98
libsumo::MultiEntryExit::getLastStepHaltingNumber
static int getLastStepHaltingNumber(const std::string &detID)
Definition: MultiEntryExit.cpp:79
libsumo::MultiEntryExit::getLastStepMeanSpeed
static double getLastStepMeanSpeed(const std::string &detID)
Definition: MultiEntryExit.cpp:67
SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
Definition: SUMOXMLDefinitions.h:76
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
libsumo::MultiEntryExit
Definition: MultiEntryExit.h:47
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
config.h
libsumo::LAST_STEP_VEHICLE_NUMBER
TRACI_CONST int LAST_STEP_VEHICLE_NUMBER
Definition: TraCIConstants.h:511
libsumo::MultiEntryExit::getLastStepVehicleNumber
static int getLastStepVehicleNumber(const std::string &detID)
Definition: MultiEntryExit.cpp:61
libsumo::SubscriptionResults
std::map< std::string, TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition: TraCIDefs.h:204
libsumo::MultiEntryExit::getIDCount
static int getIDCount()
Definition: MultiEntryExit.cpp:54