OO Programming in Java
Class 9 Material
Traffic Lite Controller Problem
Object Model Skeleton
- At initialization each lane is given a Vector of other lanes that conflict with it. Conflicting lanes are those that cannot flow while it is flowing.
- For each heartbeat (about once every 2 seconds) Go thru all lanes and ...
- Create Vector GReq of all lanes that have a GreenRequest. GreenRequests are generated when a 'sensor' is triggered during a stop condition.
- Sort the Vector by time (so it's first come, first serve).
- Create Vector GNext of all lanes that are currently flowing and are not due to be stopped.
- Go thru the sorted GReq and add each of its members to GNext only if the member is not a member of the set of conflicting lanes of any member of GNext.
- Go thru all lanes turning them 'green' if they are a member of the GNext group and 'red' if they are not a member of the GNext group.