Line data Source code
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 : /****************************************************************************/
14 : /// @file MSDetectorFileOutput.cpp
15 : /// @author Christian Roessel
16 : /// @author Daniel Krajzewicz
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @author Jakob Erdmann
20 : /// @date 2004-11-23
21 : ///
22 : // Base of value-generating classes (detectors)
23 : /****************************************************************************/
24 : #include <config.h>
25 :
26 : #include <utils/common/StringTokenizer.h>
27 : #include <microsim/MSVehicleType.h>
28 : #include <microsim/MSEdge.h>
29 : #include <microsim/MSRoute.h>
30 : #include <microsim/MSVehicleControl.h>
31 : #include <microsim/transportables/MSTransportable.h>
32 : #include <utils/vehicle/SUMOTrafficObject.h>
33 : #include <utils/vehicle/SUMOVehicle.h>
34 : #include "MSDetectorFileOutput.h"
35 :
36 : // ===========================================================================
37 : // method definitions
38 : // ===========================================================================
39 :
40 54305 : MSDetectorFileOutput::MSDetectorFileOutput(const std::string& id,
41 : const std::string& vTypes,
42 : const std::string& nextEdges,
43 54305 : const int detectPersons) :
44 : Named(id),
45 54305 : myDetectPersons(detectPersons) {
46 108610 : const std::vector<std::string> vt = StringTokenizer(vTypes).getVector();
47 : myVehicleTypes.insert(vt.begin(), vt.end());
48 108926 : for (const std::string& edgeID : StringTokenizer(nextEdges).getVector()) {
49 322 : const MSEdge* e = MSEdge::dictionary(edgeID);
50 322 : if (e) {
51 316 : myNextEdges.push_back(e);
52 : } else {
53 12 : throw ProcessError("Unknown edge '" + edgeID + "' given as nextEdges in detector '" + id + "'");
54 : }
55 54305 : }
56 54317 : }
57 :
58 :
59 : bool
60 499478597 : MSDetectorFileOutput::vehicleApplies(const SUMOTrafficObject& veh) const {
61 499478597 : if (veh.isVehicle() == detectPersons()) {
62 : return false;
63 : }
64 498531073 : if (!myVehicleTypes.empty() && myVehicleTypes.count(veh.getVehicleType().getOriginalID()) == 0) {
65 287268 : std::set<std::string> vTypeDists = MSNet::getInstance()->getVehicleControl().getVTypeDistributionMembership(veh.getVehicleType().getOriginalID());
66 : bool typeMatches = false;
67 229581 : 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 498387447 : if (!myNextEdges.empty()) {
78 : MSRouteIterator it;
79 : MSRouteIterator end;
80 : ConstMSEdgeVector route;
81 202128 : if (veh.isVehicle()) {
82 4868 : const SUMOVehicle& v = dynamic_cast<const SUMOVehicle&>(veh);
83 4868 : it = v.getCurrentRouteEdge();
84 4868 : end = v.getRoute().end();
85 197260 : } else if (veh.isPerson()) {
86 197260 : const MSTransportable& p = dynamic_cast<const MSTransportable&>(veh);
87 197260 : route = p.getCurrentStage()->getEdges();
88 197260 : it = route.begin() + p.getRoutePosition();
89 : end = route.end();
90 : }
91 262404 : for (const MSEdge* e : myNextEdges) {
92 202128 : it = std::find(it, end, e);
93 202128 : if (it == end) {
94 167584 : if (e != veh.getNextEdgePtr()) {
95 : //std::cout << SIMTIME << " det=" << getID() << " veh=" << veh.getID() << " e=" << e->getID() << " vehNext=" << Named::getIDSecure(veh.getNextEdgePtr()) << "\n";
96 141852 : return false;
97 : }
98 : }
99 : }
100 202128 : }
101 : return true;
102 : }
103 :
104 : bool
105 361088 : MSDetectorFileOutput::personApplies(const MSTransportable& p, int dir) const {
106 : //std::cout << getID() << " p=" << p.getID() << " veh=" << Named::getIDSecure(p.getVehicle()) << "\n";
107 361088 : if (p.getVehicle() == nullptr) {
108 361088 : const int dirCode = dir < 0 ? 2 : dir;
109 : //std::cout << " dir=" << dir << " dirCode=" << dirCode << " myDetectPersons=" << myDetectPersons << "\n";
110 361088 : if ((dirCode & myDetectPersons) == 0) {
111 : // person walking in wrong direction or not walking at all
112 : return false;
113 : }
114 : } else {
115 0 : const SUMOVehicleClass svc = p.getVehicle()->getVClass();
116 : int vClassCode;
117 0 : if ((svc & SVC_PUBLIC_CLASSES) != 0) {
118 : vClassCode = (int)PersonMode::PUBLIC;
119 0 : } else if ((svc & SVC_BICYCLE) != 0) {
120 : vClassCode = (int)PersonMode::BICYCLE;
121 0 : } else if ((svc & SVC_TAXI) != 0) {
122 : vClassCode = (int)PersonMode::TAXI;
123 : } else {
124 : vClassCode = (int)PersonMode::CAR;
125 : }
126 0 : if ((vClassCode & myDetectPersons) == 0) {
127 : // person riding in the wrong vehicle
128 : return false;
129 : }
130 : }
131 : return true;
132 : }
133 :
134 :
135 :
136 : /****************************************************************************/
|