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    MSRouteProbe.h
11 /// @author  Michael Behrisch
12 /// @author  Daniel Krajzewicz
13 /// @author  Tino Morenz
14 /// @date    Thu, 04.12.2008
15 /// @version $Id$
16 ///
17 // Writes route distributions at a certain edge
18 /****************************************************************************/
19 #ifndef MSRouteProbe_h
20 #define MSRouteProbe_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <string>
29 #include <microsim/output/MSDetectorFileOutput.h>
30 #include <microsim/MSMoveReminder.h>
31 #include <utils/distribution/RandomDistributor.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class MSEdge;
38 class MSRoute;
39 class MSVehicle;
40 class OutputDevice;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class MSRouteProbe
48  * @brief Writes routes of vehicles passing a certain edge
49  *
50  * This device allows to create route distributions of all vehicles
51  *  running over a certain edge.
52  *
53  * A frequency can be specified to generate the output in certain intervals,
54  *  (e.g. every 900 seconds) and is used via the detector control by
55  *  calling the appropriate methods derived from MSDetectorFileOutput.
56  *
57  * @see MSDetectorFileOutput
58  * @see Named
59  */
60 
61 class MSRouteProbe : public MSDetectorFileOutput, public MSMoveReminder {
62 public:
63     /** @brief Constructor
64      *
65      * @param[in] id The id of the route probe
66      * @param[in] edge The edge where the distribution shall be estimated
67      * @param[in] distID The id of the distribution to add values to
68      * @param[in] lastID The id of the last completed distribution to use for getRoute
69      */
70     MSRouteProbe(const std::string& id, const MSEdge* edge,
71                  const std::string& distID, const std::string& lastID,
72                  const std::string& vTypes);
73 
74 
75     /// @brief Destructor
76     virtual ~MSRouteProbe();
77 
78 
79     /// @name Methods inherited from MSMoveReminder
80     /// @{
81 
82     /** @brief Returns whether the vehicle shall be aware of this entry
83      *
84      * Returns true if the vehicle is in front of the entry, so that it
85      *  may enter it in later steps.
86      *
87      * @param[in] veh The entering vehicle.
88      * @param[in] reason how the vehicle enters the lane
89      * @return False, if vehicle passed the entry, else true.
90      * @see MSMoveReminder::notifyEnter
91      * @see MSMoveReminder::Notification
92      */
93     bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
94     /// @}
95 
96 
97     /// @name Methods inherited from MSDetectorFileOutput.
98     /// @{
99 
100     /** @brief Writes values into the given stream
101      *
102      * This method writes the distribution of routes collected
103      *  in the last interval.
104      * As a side effect the distribution is added to the global
105      *  route distribution container.
106      *
107      * @param[in] dev The output device to write the data into
108      * @param[in] startTime First time step the data were gathered
109      * @param[in] stopTime Last time step the data were gathered
110      * @see MSDetectorFileOutput::writeXMLOutput
111      * @exception IOError If an error on writing occurs (!!! not yet implemented)
112      */
113     void writeXMLOutput(OutputDevice& dev,
114                         SUMOTime startTime, SUMOTime stopTime);
115 
116 
117     /** @brief Opens the XML-output using "detector" as root element
118      *
119      * @param[in] dev The output device to write the root into
120      * @see MSDetectorFileOutput::writeXMLDetectorProlog
121      * @todo What happens with the additional information if several detectors use the same output?
122      * @exception IOError If an error on writing occurs (!!! not yet implemented)
123      */
124     void writeXMLDetectorProlog(OutputDevice& dev) const;
125     /// @}
126 
127     const MSRoute* getRoute() const;
128 
129 private:
130     /// @brief The previous distribution of routes (probability->route)
131     std::pair<std::string, RandomDistributor<const MSRoute*>*> myLastRouteDistribution;
132 
133     /// @brief The current distribution of routes (probability->route)
134     std::pair<std::string, RandomDistributor<const MSRoute*>*> myCurrentRouteDistribution;
135 
136 
137 private:
138     /// @brief Invalidated copy constructor.
139     MSRouteProbe(const MSRouteProbe&);
140 
141     /// @brief Invalidated assignment operator.
142     MSRouteProbe& operator=(const MSRouteProbe&);
143 
144 
145 };
146 
147 #endif
148 
149 /****************************************************************************/
150 
151