SUMO - Simulation of Urban MObility
TraCI_InductionLoop.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // C++ TraCI client API implementation
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
35 #include <microsim/MSNet.h>
36 #include <traci-server/TraCIDefs.h>
37 #include "TraCI_InductionLoop.h"
38 
39 
40 // ===========================================================================
41 // member definitions
42 // ===========================================================================
43 std::vector<std::string>
45  std::vector<std::string> ids;
47  return ids;
48 }
49 
50 
51 int
53  std::vector<std::string> ids;
55 }
56 
57 
58 double
59 TraCI_InductionLoop::getPosition(const std::string& detID) {
60  return getDetector(detID)->getPosition();
61 }
62 
63 
64 std::string
65 TraCI_InductionLoop::getLaneID(const std::string& detID) {
66  return getDetector(detID)->getLane()->getID();
67 }
68 
69 
70 int
72  return getDetector(detID)->getCurrentPassedNumber();
73 }
74 
75 
76 double
77 TraCI_InductionLoop::getLastStepMeanSpeed(const std::string& detID) {
78  return getDetector(detID)->getCurrentSpeed();
79 }
80 
81 
82 std::vector<std::string>
83 TraCI_InductionLoop::getLastStepVehicleIDs(const std::string& detID) {
84  return getDetector(detID)->getCurrentVehicleIDs();
85 }
86 
87 
88 double
89 TraCI_InductionLoop::getLastStepOccupancy(const std::string& detID) {
90  return getDetector(detID)->getCurrentOccupancy();
91 }
92 
93 
94 double
95 TraCI_InductionLoop::getLastStepMeanLength(const std::string& detID) {
96  return getDetector(detID)->getCurrentLength();
97 }
98 
99 
100 double
102  return getDetector(detID)->getTimeSinceLastDetection();
103 }
104 
105 
106 std::vector<TraCIVehicleData>
107 TraCI_InductionLoop::getVehicleData(const std::string& detID) {
108  std::vector<MSInductLoop::VehicleData> vd = getDetector(detID)->collectVehiclesOnDet(MSNet::getInstance()->getCurrentTimeStep() - DELTA_T, true);
109  std::vector<TraCIVehicleData> tvd;
110  for (std::vector<MSInductLoop::VehicleData>::const_iterator vdi = vd.begin(); vdi != vd.end(); ++vdi) {
111  tvd.push_back(TraCIVehicleData());
112  tvd.back().id = vdi->idM;
113  tvd.back().length = vdi->lengthM;
114  tvd.back().entryTime = vdi->entryTimeM;
115  tvd.back().leaveTime = vdi->leaveTimeM;
116  tvd.back().typeID = vdi->typeIDM;
117  }
118  return tvd;
119 
120 }
121 
122 
124 TraCI_InductionLoop::getDetector(const std::string& id) {
126  if (il == 0) {
127  throw TraCIException("Induction loop '" + id + "' is not known");
128  }
129  return il;
130 }
131 
132 
133 /****************************************************************************/
static double getLastStepMeanSpeed(const std::string &detID)
alternative tag for e1 detector
static MSInductLoop * getDetector(const std::string &detID)
int getCurrentPassedNumber() const
Returns the number of vehicles that have passed the detector.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
virtual std::vector< VehicleData > collectVehiclesOnDet(SUMOTime t, bool leaveTime=false) const
Returns vehicle data for vehicles that have been on the detector starting at the given time...
static double getLastStepMeanLength(const std::string &detID)
double getCurrentLength() const
Returns the length of the vehicle on the detector.
const MSLane * getLane() const
Returns the lane the reminder works on.
double getCurrentOccupancy() const
Returns the current occupancy.
static std::vector< std::string > getIDList()
T get(const std::string &id) const
Retrieves an item.
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
std::vector< std::string > getCurrentVehicleIDs() const
Returns the ids of vehicles that have passed the detector.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
double getCurrentSpeed() const
Returns the speed of the vehicle on the detector.
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
void insertIDs(std::vector< std::string > &into) const
static int getLastStepVehicleNumber(const std::string &detID)
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:369
static std::string getLaneID(const std::string &detID)
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:100
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:164
static double getLastStepOccupancy(const std::string &detID)
static double getTimeSinceDetection(const std::string &detID)
static double getPosition(const std::string &detID)
static std::vector< TraCIVehicleData > getVehicleData(const std::string &detID)
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:70
int size() const
Returns the number of stored items within the container.