Class TrafCOD
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.opentrafficsim.trafficcontrol.AbstractTrafficController
-
- org.opentrafficsim.trafficcontrol.trafcod.TrafCOD
-
- All Implemented Interfaces:
Serializable
,EventListener
,EventListenerInterface
,EventProducerInterface
,Identifiable
,Drawable
,InvisibleObjectInterface
,ActuatedTrafficController
,TrafficController
public class TrafCOD extends AbstractTrafficController implements ActuatedTrafficController, EventListenerInterface
TrafCOD evaluator. TrafCOD is a language for writing traffic control programs. A TrafCOD program consists of a set of rules that must be evaluated repeatedly (until no more changes occurr) every time step. The time step size is 0.1 seconds.Copyright (c) 2013-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version Oct 5, 2016
- Author:
- Wouter Schakel
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Fields inherited from interface org.opentrafficsim.trafficcontrol.TrafficController
BEING_CLONED, NO_STREAM, OFF, RUNNING, SHUTTING_DOWN, STARTING_UP, TRAFFIC_LIGHT_CHANGED, TRAFFICCONTROL_CONFLICT_GROUP_CHANGED, TRAFFICCONTROL_CONTROLLER_CREATED, TRAFFICCONTROL_CONTROLLER_EVALUATING, TRAFFICCONTROL_CONTROLLER_WARNING, TRAFFICCONTROL_SET_TRACING, TRAFFICCONTROL_STATE_CHANGED, TRAFFICCONTROL_TRACED_VARIABLE_UPDATED, TRAFFICCONTROL_VARIABLE_CREATED
-
-
Constructor Summary
Constructors Constructor Description TrafCOD(String controllerName, URL trafCodURL, OTSSimulatorInterface simulator, Container display, BufferedImage displayBackground, List<String> displayObjectLocations)
Construct a new TrafCOD traffic light controller.TrafCOD(String controllerName, List<String> trafCODRules, OTSSimulatorInterface simulator, BufferedImage displayBackground, List<String> displayObjectLocations)
Construct a new TrafCOD traffic light controller.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkConsistency()
Check the consistency of the traffic control program and perform initializations that require a completely built network.InvisibleObjectInterface
clone(OTSSimulatorInterface newSimulator, Network newNetwork)
Container
getDisplayContainer()
Retrieve the Swing (for now) container in which the controller displays its current state.String
getFullId()
SimulatorInterface<Time,Duration,SimTimeDoubleUnit>
getSimulator()
Retrieve the simulator.Serializable
getSourceId()
int
getStructureNumber()
Retrieve the structure number.static List<String>
loadTextFromURL(URL url)
Read a text from a URL and convert it to a list of strings.void
notify(EventInterface event)
String
toString()
void
traceVariable(String variableName, int stream, boolean trace)
Switch tracing of one variable on or off.void
traceVariablesOfStream(int stream, boolean trace)
Switch tracing of all variables of a particular traffic stream, or all variables that do not have an associated traffic stream on or off.void
updateDetector(String detectorId, boolean detectingGTU)
Tell the traffic controller that the state of a detector has changed.-
Methods inherited from class org.opentrafficsim.trafficcontrol.AbstractTrafficController
getId
-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.djutils.event.EventProducerInterface
addListener, addListener, addListener, addListener, getEventTypesWithListeners, hasListeners, numberOfListeners, removeListener
-
Methods inherited from interface org.opentrafficsim.trafficcontrol.TrafficController
getId
-
-
-
-
Constructor Detail
-
TrafCOD
public TrafCOD(String controllerName, URL trafCodURL, OTSSimulatorInterface simulator, Container display, BufferedImage displayBackground, List<String> displayObjectLocations) throws TrafficControlException, SimRuntimeException, IOException
Construct a new TrafCOD traffic light controller.- Parameters:
controllerName
- String; name of this TrafCOD traffic light controllertrafCodURL
- URL; the URL of the TrafCOD rulessimulator
- OTSSimulatorInterface; the simulation enginedisplay
- Container; if non-null, a controller display is constructed and shown in the supplied containerdisplayBackground
- BufferedImage; background for controller display imagedisplayObjectLocations
- List<String>; list of sensors and traffic lights and their locations on thedisplayBackGround
- Throws:
TrafficControlException
- when a rule cannot be parsedSimRuntimeException
- when scheduling the first evaluation event failsIOException
- when loading the TrafCOD rules from the URL fails
-
TrafCOD
public TrafCOD(String controllerName, List<String> trafCODRules, OTSSimulatorInterface simulator, BufferedImage displayBackground, List<String> displayObjectLocations) throws TrafficControlException, SimRuntimeException
Construct a new TrafCOD traffic light controller.- Parameters:
controllerName
- String; name of this TrafCOD traffic light controllertrafCODRules
- List<String>; the TrafCOD rulessimulator
- OTSSimulatorInterface; the simulation enginedisplayBackground
- BufferedImage; background for controller display imagedisplayObjectLocations
- List<String>; list of sensors and traffic lights and their locations on thedisplayBackGround
- Throws:
TrafficControlException
- when a rule cannot be parsedSimRuntimeException
- when scheduling the first evaluation event fails
-
-
Method Detail
-
loadTextFromURL
public static List<String> loadTextFromURL(URL url) throws IOException
Read a text from a URL and convert it to a list of strings.- Parameters:
url
- URL; the URL to open and read- Returns:
- List<String>; the lines read from the URL (trimmed).
- Throws:
IOException
- when opening or reading the URL failed.
-
checkConsistency
public void checkConsistency() throws SimRuntimeException, TrafficControlException
Check the consistency of the traffic control program and perform initializations that require a completely built network.- Throws:
SimRuntimeException
- when the simulation model is not an OTSModelInterfaceTrafficControlException
- when a required traffic light or sensor is not present in the network
-
getSimulator
public SimulatorInterface<Time,Duration,SimTimeDoubleUnit> getSimulator()
Retrieve the simulator.- Returns:
- SimulatorInterface<Time, Duration, SimTimeDoubleUnit>
-
getStructureNumber
public int getStructureNumber()
Retrieve the structure number.- Returns:
- int; the structureNumber
-
updateDetector
public void updateDetector(String detectorId, boolean detectingGTU)
Tell the traffic controller that the state of a detector has changed.- Specified by:
updateDetector
in interfaceActuatedTrafficController
- Parameters:
detectorId
- String; id of the detectordetectingGTU
- boolean;
-
traceVariablesOfStream
public void traceVariablesOfStream(int stream, boolean trace)
Switch tracing of all variables of a particular traffic stream, or all variables that do not have an associated traffic stream on or off.- Parameters:
stream
- int; the traffic stream number, orTrafCOD.NO_STREAM
to affect all variables that do not have an associated traffic streamtrace
- boolean; if true; switch on tracing; if false; switch off tracing
-
traceVariable
public void traceVariable(String variableName, int stream, boolean trace)
Switch tracing of one variable on or off.- Parameters:
variableName
- String; name of the variablestream
- int; traffic stream of the variable, orTrafCOD.NO_STREAM
to select a variable that does not have an associated traffic streamtrace
- boolean; if true; switch on tracing; if false; switch off tracing
-
notify
public void notify(EventInterface event) throws RemoteException
- Specified by:
notify
in interfaceEventListenerInterface
- Throws:
RemoteException
-
getFullId
public String getFullId()
- Specified by:
getFullId
in interfaceInvisibleObjectInterface
-
getDisplayContainer
public Container getDisplayContainer()
Retrieve the Swing (for now) container in which the controller displays its current state.- Specified by:
getDisplayContainer
in interfaceActuatedTrafficController
- Returns:
- Container; the display of the current state; may return null!
-
clone
public final InvisibleObjectInterface clone(OTSSimulatorInterface newSimulator, Network newNetwork) throws NetworkException
- Specified by:
clone
in interfaceInvisibleObjectInterface
- Throws:
NetworkException
-
getSourceId
public Serializable getSourceId()
- Specified by:
getSourceId
in interfaceEventProducerInterface
- Specified by:
getSourceId
in classEventProducer
-
-