Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDetectorFileOutput.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
22// Base of value-generating classes (detectors)
23/****************************************************************************/
24#include <config.h>
25
28#include <microsim/MSEdge.h>
29#include <microsim/MSRoute.h>
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39
41 const std::string& vTypes,
42 const std::string& nextEdges,
43 const int detectPersons) :
44 Named(id),
45 myDetectPersons(detectPersons) {
46 const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
47 myVehicleTypes.insert(vt.begin(), vt.end());
48 for (const std::string& edgeID : StringTokenizer(nextEdges).getVector()) {
49 const MSEdge* e = MSEdge::dictionary(edgeID);
50 if (e) {
51 myNextEdges.push_back(e);
52 } else {
53 throw ProcessError("Unknown edge '" + edgeID + "' given as nextEdges in detector '" + id + "'");
54 }
55 }
56}
57
58
59bool
61 if (veh.isVehicle() == detectPersons()) {
62 return false;
63 }
64 if (!myVehicleTypes.empty() && myVehicleTypes.count(veh.getVehicleType().getOriginalID()) == 0) {
66 bool typeMatches = false;
67 for (auto vTypeDist : vTypeDists) {
68 if (myVehicleTypes.count(vTypeDist) > 0) {
69 typeMatches = true;
70 break;
71 }
72 }
73 if (!typeMatches) {
74 return false;
75 }
76 }
77 if (!myNextEdges.empty()) {
81 if (veh.isVehicle()) {
82 const SUMOVehicle& v = dynamic_cast<const SUMOVehicle&>(veh);
83 it = v.getCurrentRouteEdge();
84 end = v.getRoute().end();
85 } else if (veh.isPerson()) {
86 const MSTransportable& p = dynamic_cast<const MSTransportable&>(veh);
87 route = p.getCurrentStage()->getEdges();
88 it = route.begin() + p.getRoutePosition();
89 end = route.end();
90 }
91 for (const MSEdge* e : myNextEdges) {
92 it = std::find(it, end, e);
93 if (it == end) {
94 if (e != veh.getNextEdgePtr()) {
95 //std::cout << SIMTIME << " det=" << getID() << " veh=" << veh.getID() << " e=" << e->getID() << " vehNext=" << Named::getIDSecure(veh.getNextEdgePtr()) << "\n";
96 return false;
97 }
98 }
99 }
100 }
101 return true;
102}
103
104bool
106 //std::cout << getID() << " p=" << p.getID() << " veh=" << Named::getIDSecure(p.getVehicle()) << "\n";
107 if (p.getVehicle() == nullptr) {
108 const int dirCode = dir < 0 ? 2 : dir;
109 //std::cout << " dir=" << dir << " dirCode=" << dirCode << " myDetectPersons=" << myDetectPersons << "\n";
110 if ((dirCode & myDetectPersons) == 0) {
111 // person walking in wrong direction or not walking at all
112 return false;
113 }
114 } else {
115 const SUMOVehicleClass svc = p.getVehicle()->getVClass();
116 int vClassCode;
117 if ((svc & SVC_PUBLIC_CLASSES) != 0) {
118 vClassCode = (int)PersonMode::PUBLIC;
119 } else if ((svc & SVC_BICYCLE) != 0) {
120 vClassCode = (int)PersonMode::BICYCLE;
121 } else if ((svc & SVC_TAXI) != 0) {
122 vClassCode = (int)PersonMode::TAXI;
123 } else {
124 vClassCode = (int)PersonMode::CAR;
125 }
126 if ((vClassCode & myDetectPersons) == 0) {
127 // person riding in the wrong vehicle
128 return false;
129 }
130 }
131 return true;
132}
133
134
135
136/****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
ConstMSEdgeVector::const_iterator MSRouteIterator
Definition MSRoute.h:57
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PUBLIC_CLASSES
public transport
@ SVC_TAXI
vehicle is a taxi
bool vehicleApplies(const SUMOTrafficObject &veh) const
Checks whether the detector measures vehicles of the given type.
std::vector< const MSEdge * > myNextEdges
The upcoming edges to filter by (empty means no filtering)
const int myDetectPersons
Whether pedestrians shall be detected instead of vehicles.
MSDetectorFileOutput(const std::string &id, const std::string &vTypes, const std::string &nextEdges="", const int detectPersons=false)
Constructor.
bool personApplies(const MSTransportable &p, int dir) const
std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
A road/street connecting two junctions.
Definition MSEdge.h:77
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition MSEdge.cpp:1047
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:185
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:378
MSRouteIterator end() const
Returns the end of the list of edges to pass.
Definition MSRoute.cpp:79
virtual ConstMSEdgeVector getEdges() const
the edges of the current stage
Definition MSStage.cpp:113
MSStage * getCurrentStage() const
Return the current stage.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
int getRoutePosition() const
return the index of the edge within the route
const std::set< std::string > getVTypeDistributionMembership(const std::string &id) const
Return the distribution IDs the vehicle type is a member of.
const std::string & getOriginalID() const
Returns the id of the original vehicle type if this is a vehicle specific type, the id otherwise.
Base class for objects which have an id.
Definition Named.h:54
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual bool isPerson() const
Whether it is a person.
virtual SUMOVehicleClass getVClass() const =0
Returns the object's access class.
virtual const MSEdge * getNextEdgePtr() const =0
returns the next edge (possibly an internal edge)
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual const ConstMSEdgeVector::const_iterator & getCurrentRouteEdge() const =0
Returns an iterator pointing to the current edge in this vehicles route.
virtual const MSRoute & getRoute() const =0
Returns the current route.
std::vector< std::string > getVector()
return vector of strings