1 package org.opentrafficsim.trafficcontrol;
2
3 import nl.tudelft.simulation.event.EventListenerInterface;
4 import nl.tudelft.simulation.event.EventProducerInterface;
5 import nl.tudelft.simulation.event.EventType;
6
7 /**
8 * Interface for traffic light controllers.
9 * <p>
10 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11 * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12 * <p>
13 * @version $Revision$, $LastChangedDate$, by $Author$, initial version Oct 14, 2016 <br>
14 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
16 * @author <a href="http://www.transport.citg.tudelft.nl">Wouter Schakel</a>
17 */
18 public interface TrafficController extends EventProducerInterface, EventListenerInterface
19 {
20 /**
21 * Retrieve the Id of the traffic light controller.
22 * @return String; the id of the traffic light controller
23 */
24 public String getId();
25
26 /**
27 * Tell the traffic controller that the state of a detector has changed.
28 * @param detectorId String; id of the detector
29 * @param detectingGTU boolean;
30 */
31 public void updateDetector(String detectorId, boolean detectingGTU);
32
33 /** Traffic controller is starting up. Particular traffic control programs may use additional states not listed here. */
34 final String STARTING_UP = "starting up";
35
36 /** Traffic controller is running. */
37 final String RUNNING = "running";
38
39 /** Traffic controller is shutting down. */
40 final String SHUTTING_DOWN = "shutting down";
41
42 /** Traffic controller is off. */
43 final String OFF = "off";
44
45 /** Constant to select variables that have no associated traffic stream. */
46 public final static int NO_STREAM = -1;
47
48 /**
49 * The <b>timed</b> event type for pub/sub that a newly created traffic controller emits. <br>
50 * Payload: Object[] { String trafficControllerId, String initialState }
51 */
52 EventType TRAFFICCONTROL_CONTROLLER_CREATED = new EventType("TRAFFICCONTROL.CONTROLLER_CREATED");
53
54 /**
55 * The <b>timed</b> event type for pub/sub that a traffic controller emits when it begins the computations to determine its
56 * response to the current input (detector states).<br>
57 * Payload: Object[] { String trafficControllerId }
58 */
59 EventType TRAFFICCONTROL_CONTROLLER_EVALUATING = new EventType("TRAFFICCONTROL.CONTROLLER_EVALUATING");
60
61 /**
62 * The <b>timed</b> event type for pub/sub that a traffic controller uses to convey warnings.<br>
63 * Payload: Object[] { String trafficControllerId, String message }
64 */
65 EventType TRAFFICCONTROL_CONTROLLER_WARNING = new EventType("TRAFFICCONTROL.CONTROLLER_WARNING");
66
67 /**
68 * The <b>timed</b> event for pub/sub emitted by a traffic control machine when it changes state (STARTING_UP, RUNNING,
69 * SHUTTING_DOWN, OFF, etc. The exact set of states may vary depending on the type of traffic control machine. <br>
70 * Payload: Object[] { String trafficControllerId, String oldState, String newState }
71 */
72 EventType TRAFFICCONTROL_STATE_CHANGED = new EventType("TRAFFIC_CONTROL.STATE_CHANGED");
73
74 /**
75 * The <b>timed</b>event that is fired by a traffic control program when a traffic light must change state. <br>
76 * Payload: Object[] { String trafficControllerId, Integer stream, TrafficLightColor newColor }
77 */
78 public static final EventType TRAFFIC_LIGHT_CHANGED = new EventType("TrafficLightChanged");
79
80 /**
81 * The <b>timed</b> event type for pub/sub indicating the creation of a traffic control program variable. <br>
82 * Listeners to this event can send <code>TRAFFICCONTROL_SET_TRACE</code> messages to set the tracing level of a variable.<br>
83 * Payload: Object[] {String trafficControllerId, String variableId, Integer trafficStream, Double initialValue}
84 */
85 EventType TRAFFICCONTROL_VARIABLE_CREATED = new EventType("TRAFFICCONTROL.VARIABLE_CREATED");
86
87 /**
88 * The <b>timed</b> event type that instruct a traffic controller to change the tracing level of a variable. <br>
89 * Payload: Object[] { String trafficControllerId, String variableId, Integer trafficStream, Boolean trace } <br>
90 * Remark 1: an empty string for the variableId sets or clears tracing for all variables associated with the traffic stream. <br>
91 * Remark 2: The stream number <code>NO_STREAM</code> selects variable(s) that are not associated with a particular traffic
92 * stream. <br>
93 * Remark 3: setting the tracing level of a variable changes the amount of
94 * <code>TRAFFICCONTROL_TRACED_VARIABLE_UPDATED</code> events sent to <b>all</b> listeners; i.e. it is not possible to
95 * affect tracing on a per listener basis.
96 */
97 EventType TRAFFICCONTROL_SET_TRACING = new EventType("TRAFFICCONTROL.SET_TRACING");
98
99 /**
100 * The <b>timed</b> event type for pub/sub indicating the update of a traced control program variable. <br>
101 * Payload: Object[] {String trafficControllerId, String variableId, Integer trafficStream, Double oldValue, Double
102 * newValue, String expressionOrDescription} <br>
103 * Remark 1: for variable that are not associated with a particular traffic stream, the trafficStream value shall be
104 * <code>NO_STREAM</code> <br>
105 * Remark 2: if the variable is a timer that has just been initialized; newValue will reflect the duration in seconds
106 */
107 EventType TRAFFICCONTROL_TRACED_VARIABLE_UPDATED = new EventType("TRAFFICCONTROL.VARIABLE_UPDATED");
108
109 /**
110 * The <b>timed</b> event for pub/sub emitted by a traffic control machine when it changes to another conflict group. <br>
111 * Payload: Object[] { String trafficControllerId, String oldConflictGroupStreams, String newConflictGroupStreams } <br>
112 * Remark 1: a conflict group is described as a space-separated list of traffic stream numbers. The traffic streams within a
113 * conflict group should be compatible; i.e. not conflicting. <br>
114 * Remark 2: The value <code>00</code> can be used as a place holder for a stream in a conflict groups that have fewer than
115 * the maximum number of traffic streams that occur in any conflict group.<br>
116 * Remark 3: The very first event of this type may use an empty string for <code>oldConflictGroupStreams</code>.<br>
117 * Remark 4: Some traffic control systems may not operate in a conflict group by conflict group fashion and therefore not
118 * emit these events.
119 */
120 EventType TRAFFICCONTROL_CONFLICT_GROUP_CHANGED = new EventType("TRAFFIC_CONTROL.CONFLICT_GROUP_CHANGED");
121
122 }