SUMO - Simulation of Urban MObility
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 <libsumo/TraCIDefs.h>
37 #include "InductionLoop.h"
38 
39 
40 // ===========================================================================
41 // member definitions
42 // ===========================================================================
43 namespace libsumo {
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 double
60 InductionLoop::getPosition(const std::string& detID) {
61  return getDetector(detID)->getPosition();
62 }
63 
64 
65 std::string
66 InductionLoop::getLaneID(const std::string& detID) {
67  return getDetector(detID)->getLane()->getID();
68 }
69 
70 
71 int
72 InductionLoop::getLastStepVehicleNumber(const std::string& detID) {
73  return getDetector(detID)->getCurrentPassedNumber();
74 }
75 
76 
77 double
78 InductionLoop::getLastStepMeanSpeed(const std::string& detID) {
79  return getDetector(detID)->getCurrentSpeed();
80 }
81 
82 
83 std::vector<std::string>
84 InductionLoop::getLastStepVehicleIDs(const std::string& detID) {
85  return getDetector(detID)->getCurrentVehicleIDs();
86 }
87 
88 
89 double
90 InductionLoop::getLastStepOccupancy(const std::string& detID) {
91  return getDetector(detID)->getCurrentOccupancy();
92 }
93 
94 
95 double
96 InductionLoop::getLastStepMeanLength(const std::string& detID) {
97  return getDetector(detID)->getCurrentLength();
98 }
99 
100 
101 double
102 InductionLoop::getTimeSinceDetection(const std::string& detID) {
103  return getDetector(detID)->getTimeSinceLastDetection();
104 }
105 
106 
107 std::vector<libsumo::TraCIVehicleData>
108 InductionLoop::getVehicleData(const std::string& detID) {
109  std::vector<MSInductLoop::VehicleData> vd = getDetector(detID)->collectVehiclesOnDet(MSNet::getInstance()->getCurrentTimeStep() - DELTA_T, true);
110  std::vector<libsumo::TraCIVehicleData> tvd;
111  for (std::vector<MSInductLoop::VehicleData>::const_iterator vdi = vd.begin(); vdi != vd.end(); ++vdi) {
112  tvd.push_back(libsumo::TraCIVehicleData());
113  tvd.back().id = vdi->idM;
114  tvd.back().length = vdi->lengthM;
115  tvd.back().entryTime = vdi->entryTimeM;
116  tvd.back().leaveTime = vdi->leaveTimeM;
117  tvd.back().typeID = vdi->typeIDM;
118  }
119  return tvd;
120 
121 }
122 
123 
125 InductionLoop::getDetector(const std::string& id) {
127  if (il == 0) {
128  throw TraCIException("Induction loop '" + id + "' is not known");
129  }
130  return il;
131 }
132 
133 NamedRTree*
135  NamedRTree* t = new NamedRTree();
136  for (const auto& i : MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_INDUCTION_LOOP)) {
137  MSInductLoop* il = static_cast<MSInductLoop*>(i.second);
139  const float cmin[2] = {(float) p.x(), (float) p.y()};
140  const float cmax[2] = {(float) p.x(), (float) p.y()};
141  t->Insert(cmin, cmax, il);
142  }
143  return t;
144 }
145 
146 }
147 
148 /****************************************************************************/
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
Definition: NamedRTree.h:89
alternative tag for e1 detector
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:165
static std::string getLaneID(const std::string &detID)
double x() const
Returns the x-position.
Definition: Position.h:62
A RT-tree for efficient storing of SUMO&#39;s Named objects.
Definition: NamedRTree.h:71
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...
double getCurrentLength() const
Returns the length of the vehicle on the detector.
const MSLane * getLane() const
Returns the lane the reminder works on.
static std::vector< std::string > getIDList()
double getCurrentOccupancy() const
Returns the current occupancy.
static double getLastStepOccupancy(const std::string &detID)
T get(const std::string &id) const
Retrieves an item.
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.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
void insertIDs(std::vector< std::string > &into) const
double y() const
Returns the y-position.
Definition: Position.h:67
static double getTimeSinceDetection(const std::string &detID)
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
static MSInductLoop * getDetector(const std::string &detID)
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:369
Definition: Edge.cpp:31
static int getLastStepVehicleNumber(const std::string &detID)
static std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &detID)
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:100
Position positionAtOffset(double pos, double lateralOffset=0) const
Returns the position at the given length.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
static double getLastStepMeanSpeed(const std::string &detID)
static NamedRTree * getTree()
Returns a tree filled with inductive loop instances.
static double getPosition(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.
static double getLastStepMeanLength(const std::string &detID)