SUMO - Simulation of Urban MObility
TraCI_InductionLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // C++ TraCI client API implementation
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
36 #include <microsim/MSNet.h>
37 #include <traci-server/TraCIDefs.h>
38 #include "TraCI_InductionLoop.h"
39 
40 
41 // ===========================================================================
42 // 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 double
60 TraCI_InductionLoop::getPosition(const std::string& detID) {
61  return getDetector(detID)->getPosition();
62 }
63 
64 
65 std::string
66 TraCI_InductionLoop::getLaneID(const std::string& detID) {
67  return getDetector(detID)->getLane()->getID();
68 }
69 
70 
71 int
73  return getDetector(detID)->getCurrentPassedNumber();
74 }
75 
76 
77 double
78 TraCI_InductionLoop::getLastStepMeanSpeed(const std::string& detID) {
79  return getDetector(detID)->getCurrentSpeed();
80 }
81 
82 
83 std::vector<std::string>
84 TraCI_InductionLoop::getLastStepVehicleIDs(const std::string& detID) {
85  return getDetector(detID)->getCurrentVehicleIDs();
86 }
87 
88 
89 double
90 TraCI_InductionLoop::getLastStepOccupancy(const std::string& detID) {
91  return getDetector(detID)->getCurrentOccupancy();
92 }
93 
94 
95 double
96 TraCI_InductionLoop::getLastStepMeanLength(const std::string& detID) {
97  return getDetector(detID)->getCurrentLength();
98 }
99 
100 
101 double
103  return getDetector(detID)->getTimeSinceLastDetection();
104 }
105 
106 
107 std::vector<TraCIVehicleData>
108 TraCI_InductionLoop::getVehicleData(const std::string& detID) {
109  std::vector<MSInductLoop::VehicleData> vd = getDetector(detID)->collectVehiclesOnDet(MSNet::getInstance()->getCurrentTimeStep() - DELTA_T, true);
110  std::vector<TraCIVehicleData> tvd;
111  for (std::vector<MSInductLoop::VehicleData>::const_iterator vdi = vd.begin(); vdi != vd.end(); ++vdi) {
112  tvd.push_back(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 TraCI_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 
134 /****************************************************************************/
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:169
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
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:66
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:368
static std::string getLaneID(const std::string &detID)
double getPosition() const
Returns the position of the detector on the lane.
Definition: MSInductLoop.h:101
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:71
int size() const
Returns the number of stored items within the container.