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    Command_SaveTLSSwitches.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @date    06 Jul 2006
14 /// @version $Id$
15 ///
16 // Writes information about the green durations of a tls
17 /****************************************************************************/
18 #ifndef Command_SaveTLSSwitches_h
19 #define Command_SaveTLSSwitches_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <string>
28 #include <map>
29 #include <utils/common/Command.h>
30 #include <microsim/traffic_lights/MSTLLogicControl.h>
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class MSTrafficLightLogic;
37 class OutputDevice;
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
43 /**
44  * @class Command_SaveTLSSwitches
45  * @brief Writes information about the green durations of a tls
46  *
47  * @todo Revalidate this - as tls are not seting the link information directly ater being switched, the computed information may be delayed
48  */
49 class Command_SaveTLSSwitches : public Command {
50 public:
51     /** @brief Constructor
52      *
53      * @param[in] tlls The logic to write state of
54      * @param[in] od The output device to write the state into
55      */
56     Command_SaveTLSSwitches(const MSTLLogicControl::TLSLogicVariants& logics,
57                             OutputDevice& od);
58 
59 
60     /// @brief Destructor
61     ~Command_SaveTLSSwitches();
62 
63 
64     /// @name Derived from Command
65     /// @{
66 
67     /** @brief Writes the output if a change occurred
68      *
69      * Called in each tme step, this class computes which link have red
70      *  since the last tls switch and writes the information about their
71      *  green duration into the given stream.
72      *
73      * Information whether a link had green and since when is stored in
74      *  "myPreviousLinkStates".
75      *
76      * @param[in] currentTime The current simulation time
77      * @return Always DELTA_T (will be executed in next time step)
78      * @see Command
79      */
80     SUMOTime execute(SUMOTime currentTime);
81     /// @}
82 
83 
84 private:
85     /// @brief The device to write to
86     OutputDevice& myOutputDevice;
87 
88     /// @brief The traffic light logic to use
89     const MSTLLogicControl::TLSLogicVariants& myLogics;
90 
91     /// @brief Storage for prior states; map from signal group to last green time begin
92     std::map<int, SUMOTime> myPreviousLinkStates;
93 
94 
95 private:
96     /// @brief Invalidated copy constructor.
97     Command_SaveTLSSwitches(const Command_SaveTLSSwitches&);
98 
99     /// @brief Invalidated assignment operator.
100     Command_SaveTLSSwitches& operator=(const Command_SaveTLSSwitches&);
101 
102 };
103 
104 
105 #endif
106 
107 /****************************************************************************/
108 
109