1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    RODFNet.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Eric Nicolay
13 /// @author  Michael Behrisch
14 /// @date    Thu, 16.03.2006
15 /// @version $Id$
16 ///
17 // A DFROUTER-network
18 /****************************************************************************/
19 #ifndef RODFNet_h
20 #define RODFNet_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/options/OptionsCont.h>
29 #include <utils/common/StdDefs.h>
30 #include <utils/common/SUMOTime.h>
31 #include <router/ROEdge.h>
32 #include <router/RONet.h>
33 #include "RODFDetector.h"
34 #include "RODFRouteDesc.h"
35 #include "RODFRouteCont.h"
36 
37 
38 // ===========================================================================
39 // class definitions
40 // ===========================================================================
41 /**
42  * @class RODFNet
43  * @brief A DFROUTER-network
44  */
45 class RODFNet : public RONet {
46 public:
47     /** @brief Constructor
48      * @param[in] amInHighwayMode Whether search for following edges shall stop at slow edges
49      */
50     RODFNet(bool amInHighwayMode);
51 
52 
53     /// @brief Destructor
54     ~RODFNet();
55 
56 
57     void buildApproachList();
58 
59     void computeTypes(RODFDetectorCon& dets,
60                       bool sourcesStrict) const;
61     void buildRoutes(RODFDetectorCon& det, bool keepUnfoundEnds, bool includeInBetween,
62                      bool keepShortestOnly, int maxFollowingLength) const;
63     double getAbsPos(const RODFDetector& det) const;
64 
65     void buildEdgeFlowMap(const RODFDetectorFlows& flows,
66                           const RODFDetectorCon& detectors,
67                           SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
68 
69     void revalidateFlows(const RODFDetectorCon& detectors,
70                          RODFDetectorFlows& flows,
71                          SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
72 
73 
74     void removeEmptyDetectors(RODFDetectorCon& detectors,
75                               RODFDetectorFlows& flows);
76 
77     void reportEmptyDetectors(RODFDetectorCon& detectors,
78                               RODFDetectorFlows& flows);
79 
80     void buildDetectorDependencies(RODFDetectorCon& detectors);
81 
82     void mesoJoin(RODFDetectorCon& detectors, RODFDetectorFlows& flows);
83 
84     bool hasDetector(ROEdge* edge) const;
85     const std::vector<std::string>& getDetectorList(ROEdge* edge) const;
86 
getMaxSpeedFactorPKW()87     double getMaxSpeedFactorPKW() const {
88         return myMaxSpeedFactorPKW;
89     }
90 
getMaxSpeedFactorLKW()91     double getMaxSpeedFactorLKW() const {
92         return myMaxSpeedFactorLKW;
93     }
94 
getAvgSpeedFactorPKW()95     double getAvgSpeedFactorPKW() const {
96         return myAvgSpeedFactorPKW;
97     }
98 
getAvgSpeedFactorLKW()99     double getAvgSpeedFactorLKW() const {
100         return myAvgSpeedFactorLKW;
101     }
102 
103 protected:
104     void revalidateFlows(const RODFDetector* detector,
105                          RODFDetectorFlows& flows,
106                          SUMOTime startTime, SUMOTime endTime, SUMOTime stepOffset);
107     bool isSource(const RODFDetector& det,
108                   const RODFDetectorCon& detectors, bool strict) const;
109     bool isFalseSource(const RODFDetector& det,
110                        const RODFDetectorCon& detectors) const;
111     bool isDestination(const RODFDetector& det,
112                        const RODFDetectorCon& detectors) const;
113 
114     ROEdge* getDetectorEdge(const RODFDetector& det) const;
115     bool isSource(const RODFDetector& det, ROEdge* edge,
116                   ROEdgeVector& seen, const RODFDetectorCon& detectors,
117                   bool strict) const;
118     bool isFalseSource(const RODFDetector& det, ROEdge* edge,
119                        ROEdgeVector& seen, const RODFDetectorCon& detectors) const;
120     bool isDestination(const RODFDetector& det, ROEdge* edge, ROEdgeVector& seen,
121                        const RODFDetectorCon& detectors) const;
122 
123     void computeRoutesFor(ROEdge* edge, RODFRouteDesc& base, int no,
124                           bool keepUnfoundEnds,
125                           bool keepShortestOnly,
126                           ROEdgeVector& visited, const RODFDetector& det,
127                           RODFRouteCont& into, const RODFDetectorCon& detectors,
128                           int maxFollowingLength,
129                           ROEdgeVector& seen) const;
130 
131     void buildDetectorEdgeDependencies(RODFDetectorCon& dets) const;
132 
133     bool hasApproaching(ROEdge* edge) const;
134     bool hasApproached(ROEdge* edge) const;
135 
136     bool hasInBetweenDetectorsOnly(ROEdge* edge,
137                                    const RODFDetectorCon& detectors) const;
138     bool hasSourceDetector(ROEdge* edge,
139                            const RODFDetectorCon& detectors) const;
140 
141     struct IterationEdge {
142         int depth;
143         ROEdge* edge;
144     };
145 
146 protected:
147     class DFRouteDescByTimeComperator {
148     public:
149         /// Constructor
DFRouteDescByTimeComperator()150         explicit DFRouteDescByTimeComperator() { }
151 
152         /// Destructor
~DFRouteDescByTimeComperator()153         ~DFRouteDescByTimeComperator() { }
154 
155         /// Comparing method
operator()156         bool operator()(const RODFRouteDesc& nod1, const RODFRouteDesc& nod2) const {
157             return nod1.duration_2 > nod2.duration_2;
158         }
159     };
160 
161 private:
162     /// @brief comparator for maps using edges as key, used only in myDetectorsOnEdges to make tests comparable
163     struct idComp {
operatoridComp164         bool operator()(ROEdge* const lhs, ROEdge* const rhs) const {
165             return lhs->getID() < rhs->getID();
166         }
167     };
168 
169     /// @brief Map of edge name->list of names of this edge approaching edges
170     std::map<ROEdge*, ROEdgeVector > myApproachingEdges;
171 
172     /// @brief Map of edge name->list of names of edges approached by this edge
173     std::map<ROEdge*, ROEdgeVector > myApproachedEdges;
174 
175     mutable std::map<ROEdge*, std::vector<std::string>, idComp> myDetectorsOnEdges;
176     mutable std::map<std::string, ROEdge*> myDetectorEdges;
177 
178     bool myAmInHighwayMode;
179     mutable int mySourceNumber, mySinkNumber, myInBetweenNumber, myInvalidNumber;
180 
181     /// @brief List of ids of edges that shall not be used
182     std::vector<std::string> myDisallowedEdges;
183 
184 
185     bool myKeepTurnarounds;
186 
187     /// @brief maximum speed factor in measurements
188     double myMaxSpeedFactorPKW;
189     double myMaxSpeedFactorLKW;
190     double myAvgSpeedFactorPKW;
191     double myAvgSpeedFactorLKW;
192 
193 };
194 
195 
196 #endif
197 
198 /****************************************************************************/
199 
200