1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2010-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    MSSOTLPolicyBasedTrafficLightLogic.h
11 /// @author  Alessio Bonfietti
12 /// @author  Riccardo Belletti
13 /// @date    2014-03-20
14 /// @version $Id$
15 ///
16 // The class for SOTL Policy-based logics
17 /****************************************************************************/
18 
19 #ifndef MSSOTLPOLICYBASEDTRAFFICLIGHTLOGIC_H_
20 #define MSSOTLPOLICYBASEDTRAFFICLIGHTLOGIC_H_
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 //#define SWARM_DEBUG
28 #include <utils/common/SwarmDebug.h>
29 #include "MSSOTLPolicy.h"
30 #include "MSSOTLTrafficLightLogic.h"
31 
32 /**
33  * @class MSSOTLPolicyBasedTrafficLightLogic
34  * @brief A self-organizing traffic light logic based on a particular policy
35  *
36  * This traffic light logic is used to wrap the logic of a self-organizing
37  * low-level policy into a functional traffic light logic. It's role is to
38  * use a low-level policy without an high-level policy to command it.
39  */
40 
41 class MSSOTLPolicyBasedTrafficLightLogic: public MSSOTLTrafficLightLogic {
42 public:
43     /**
44      * @brief Constructor without sensors passed
45      * @param[in] tlcontrol The tls control responsible for this tls
46      * @param[in] id This traffic light id
47      * @param[in] programID This tls' sub-id (program id)
48      * @param[in] logicType This tls' type (static, actuated etc.)
49      * @param[in] phases Definitions of the phases
50      * @param[in] step The initial phase index
51      * @param[in] delay The time to wait before the first switch
52      * @param[in] parameters Parameters defined for the tll
53      */
54     MSSOTLPolicyBasedTrafficLightLogic(MSTLLogicControl& tlcontrol,
55                                        const std::string& id, const std::string& programID, const TrafficLightType logicType,
56                                        const Phases& phases, int step, SUMOTime delay,
57                                        const std::map<std::string, std::string>& parameters,
58                                        MSSOTLPolicy* policy);
59 
60     /**
61      * @brief Constructor with sensors passed
62      * @param[in] tlcontrol The tls control responsible for this tls
63      * @param[in] id This tls' id
64      * @param[in] programID This tls' sub-id (program id)
65      * @param[in] logicType This tls' type (static, actuated etc.)
66      * @param[in] phases Definitions of the phases
67      * @param[in] step The initial phase index
68      * @param[in] delay The time to wait before the first switch
69      * @param[in] parameters Parameters defined for the tll
70      * @param[in] sensors The already defined sensor logic
71      */
72     MSSOTLPolicyBasedTrafficLightLogic(MSTLLogicControl& tlcontrol,
73                                        const std::string& id, const std::string& programID, const TrafficLightType logicType,
74                                        const Phases& phases, int step, SUMOTime delay,
75                                        const std::map<std::string, std::string>& parameters,
76                                        MSSOTLPolicy* policy, MSSOTLSensors* sensors);
77 
78     ~MSSOTLPolicyBasedTrafficLightLogic();
79 
getPolicy()80     MSSOTLPolicy* getPolicy() {
81         return myPolicy;
82     }
83 
84     /** @brief Returns the type of the logic as a string
85     * @return The type of the logic
86     */
getLogicType()87     const std::string getLogicType() const {
88         return "policyBasedTrafficLightLogic";
89     }
90     /// @}
91 
92 //	virtual bool canRelease(SUMOTime elapsed, bool thresholdPassed, const MSPhaseDefinition* stage, int vehicleCount) throw ()=0;
93 
94 protected:
95 
96     /*
97      * @brief Contains the logic to decide the phase change
98      */
99     bool canRelease();
100 
101     /*
102      * This member has to contain the switching logic for SOTL policies
103      */
104     int decideNextPhase();
105 
106 private:
107     MSSOTLPolicy* myPolicy;
108 };
109 
110 #endif /* MSSOTLPOLICYBASEDTRAFFICLIGHTLOGIC_H_ */
111