Line data Source code
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 : /****************************************************************************/
12 : /// @file TraCI_InductionLoop.cpp
13 : /// @author Daniel Krajzewicz
14 : /// @author Mario Krumnow
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @date 30.05.2012
18 : /// @version $Id$
19 : ///
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 :
33 : #include <microsim/output/MSDetectorControl.h>
34 : #include <microsim/output/MSInductLoop.h>
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>
44 5 : TraCI_InductionLoop::getIDList() {
45 5 : std::vector<std::string> ids;
46 5 : MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_INDUCTION_LOOP).insertIDs(ids);
47 5 : return ids;
48 : }
49 :
50 :
51 : int
52 4 : TraCI_InductionLoop::getIDCount() {
53 4 : std::vector<std::string> ids;
54 4 : return (int)MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_INDUCTION_LOOP).size();
55 : }
56 :
57 :
58 : double
59 1 : TraCI_InductionLoop::getPosition(const std::string& detID) {
60 1 : return getDetector(detID)->getPosition();
61 : }
62 :
63 :
64 : std::string
65 1 : TraCI_InductionLoop::getLaneID(const std::string& detID) {
66 1 : return getDetector(detID)->getLane()->getID();
67 : }
68 :
69 :
70 : int
71 4720 : TraCI_InductionLoop::getLastStepVehicleNumber(const std::string& detID) {
72 4720 : return getDetector(detID)->getCurrentPassedNumber();
73 : }
74 :
75 :
76 : double
77 53 : TraCI_InductionLoop::getLastStepMeanSpeed(const std::string& detID) {
78 53 : return getDetector(detID)->getCurrentSpeed();
79 : }
80 :
81 :
82 : std::vector<std::string>
83 77 : TraCI_InductionLoop::getLastStepVehicleIDs(const std::string& detID) {
84 77 : return getDetector(detID)->getCurrentVehicleIDs();
85 : }
86 :
87 :
88 : double
89 53 : TraCI_InductionLoop::getLastStepOccupancy(const std::string& detID) {
90 53 : return getDetector(detID)->getCurrentOccupancy();
91 : }
92 :
93 :
94 : double
95 53 : TraCI_InductionLoop::getLastStepMeanLength(const std::string& detID) {
96 53 : return getDetector(detID)->getCurrentLength();
97 : }
98 :
99 :
100 : double
101 53 : TraCI_InductionLoop::getTimeSinceDetection(const std::string& detID) {
102 53 : return getDetector(detID)->getTimeSinceLastDetection();
103 : }
104 :
105 :
106 : std::vector<TraCIVehicleData>
107 29 : TraCI_InductionLoop::getVehicleData(const std::string& detID) {
108 29 : std::vector<MSInductLoop::VehicleData> vd = getDetector(detID)->collectVehiclesOnDet(MSNet::getInstance()->getCurrentTimeStep() - DELTA_T, true);
109 29 : std::vector<TraCIVehicleData> tvd;
110 41 : for (std::vector<MSInductLoop::VehicleData>::const_iterator vdi = vd.begin(); vdi != vd.end(); ++vdi) {
111 12 : tvd.push_back(TraCIVehicleData());
112 12 : tvd.back().id = vdi->idM;
113 12 : tvd.back().length = vdi->lengthM;
114 12 : tvd.back().entryTime = vdi->entryTimeM;
115 12 : tvd.back().leaveTime = vdi->leaveTimeM;
116 12 : tvd.back().typeID = vdi->typeIDM;
117 : }
118 29 : return tvd;
119 :
120 : }
121 :
122 :
123 : MSInductLoop*
124 5040 : TraCI_InductionLoop::getDetector(const std::string& id) {
125 5040 : MSInductLoop* il = dynamic_cast<MSInductLoop*>(MSNet::getInstance()->getDetectorControl().getTypedDetectors(SUMO_TAG_INDUCTION_LOOP).get(id));
126 5040 : if (il == 0) {
127 1 : throw TraCIException("Induction loop '" + id + "' is not known");
128 : }
129 5039 : return il;
130 43554 : }
131 :
132 :
133 : /****************************************************************************/
|