Summary
Specification
for CS 4478 Project: Traffic Light Control System
Manual
The traffic lights
design for cross junction
Discussion
Conclusion
Reference
City
traffic light control system is proposed for the project given by the Object-Oriented
Programming course. In this proposal, three classes, i.e. RoadNode, Junction,
and Car are employed. The definitions and associated "Component, Responsibility,
Collaborator (CRC)" cards are explained. Some designs, especially concerning
Junction and RoadNode are reported in detail. This program simulates a
simple city roads' map and a clock, containing time- and space- distribution
of objects. Consequently, the class Accident is suggested. Some further
development after the completion of this project is discussed.
The specifications quoted by Professor Li have been closely followed. A clock is also included. In addition, one specification concerning accidents is added.
The Major Specifications are:
- A city traffic map layout must be carefully designed
based on the city's picture provided for this project so that the user
may view the traffic animation properly.
- Each junction must accordingly have its own set of
traffic lights. (
Cross or T )
- Each set traffic lights must be able to show red, flashing
green, green,
and yellow lights.
- The traffic light rules for incoming cars
are:
Red - Stop unless making a right turn (Certain cases)
Flashing Green - Turn Left
Green - Straightforward or right turn
Yellow - straightforward and turn right.
- Sensors record the car arriving and departing from
the junction.
- Only double lanes (one lane per direction) are available
in one road.
- Vehicles reaching a junction may turn in any directions
except reversal.
- The traffic flow is such that a car exiting on a non
ending road node
will go either one step forward or remain at the same
node depending on the availability of the new node. A car exiting on an
ending road node will wait for a traffic signal, and under permitted signal
go to the first node of the associated new road and follow the new direction
moving forward.
- When an intersection is busy, all coming cars will
follow routine
traffic signals to take an action.
- When the intersection is not busy the light turn red-red.
This allows the
light to turn green immediately for the next car to move
straightforward
without requiring to stop.
- In normal circumstances, a moving car must randomly
select its next
possible turn 5 steps before the intersection at which
it will arrive.
- To improve traffic flow at quiet times a message is
sent from the
departure intersection to the next controller. This message
informs the controller that there is a car coming. If the controller is
in red-red state, or there are no "arrived" cars at that controller, the
signal will turn green for that car to pass straightforward without requiring
a stop. If the junction traffic controller is busy, the message will be
ignored.
- The probability that a car will enter the city roads
of our system is to be exponentially distributed. Let u stand for a random
number; m the mean. The exponential distribution is written as
x = - m * ln(u)
- The generated cars must randomly choose an entry among
11 entrances
before entering the city area.
- The present program is able to accept different inputs,
such as the means
of car event generation, time of simulation, and the
pace of animation through associated scroll bars.
- Current average sleep time (micro seconds) for per
generated car is shown in a textField below the Label "<< Rush" after
user clicks "Registration" button.
- A clock with selectable face features.
- User may use the mouse to locate an accident on the
road. Stop and detour signs will appear accordingly. This event will immediately
recorded in a text field with the registration's time, location (x and
y coordinates), roads involved, and associated .I junctions. For simplicity,
only one event happens each time.
- Rules for processing accident are:
-User must point the accident location by using the mouse
locator.
-Stop and detour signs will immediately appear at the
associated intersections.
- Each irrelevant car on the associated roads will either
reverse or continue traveling straightforward and leave the scene of the
accident immediately.
- Thread’s current average sleep time for per generated
car will be shown in a textField, so that user may have a quantitative
idea about the cars’ input.
The clock at the top right corner has a feature-selectable face. By clicking the buttons on the left side, the user may choose Digit, Roman numerals, or bars to indicate the time on its face.
Clicking the "Suspended/Resume" button on the left side of the clock, the user is able to slow down the pace to minimum level or recover the pace. Using the scroll bar "Pace inc.", the user may gradually increase or decrease the pace.
The user may create either a rush hour or a quiet time scene by using the "Rush Hr." scroll bar.
To create an accident, the user must click the "Accident" button, then point and locate the place of accident
By clicking the "Information" button, the user will obtain information about the accident in a text field below. The information includes time, location (map coordinates), and roads and junctions involved. By clicking the same button, user may also find the Thread’s current average sleep time for each generated car. The value is shown in the textField below the "<<Rush Hr" label.
Click the "Release" button to terminate the accident. The emergency signs will disappear, associated roads will be reopened, and junctions will become normal.
In present program, user is allowed
to deal with only one accident each time..
The Traffic lights design for Cross-Junction
In consideration of left turn (big turn), a flashing green signal is added in present design. The traffic lights design in present programming is shown as follows.
Road Orientation | North bound | East bound | South bound | West bound |
Direction Notation |
|
|
|
|
Timing 0 -15 |
|
|
|
|
Timing 16-30 |
|
|
|
|
Timing 31-45 |
|
|
|
|
Timing 46-60 |
|
|
|
|
Timing 61-75 |
|
|
|
|
Timing 76-90 |
|
|
|
|
~G represents flashing green
(alternation of green and white) lights
Normally,
Cars may make right turn ("small turn") when G or Y lights appear.
Cars may go straightforward during G, or Y lights.
Cars may make left turn ("large turn") only during flashing
G.
The information about an accident or event can be recorded immediately in terms of time and location, a class Accident and a linked list of Accident can also be created. This list will maintain information concerning events that occurred in the past, and potentially could be a great help to some organizations, such as the city police department, insurance companies, and so on.
In present program no switch is employed in order to obtain faster computation.
Data array of SIN and COS which are frequently used in maintaining the clock are calculated beforehand and listed in this program for the same purpose.
Locating an accident is limited to
the cases occurring on cross intersections only. Each time a location (coordinates
x and y) is indicated by clicking the mouse, two intersections with minimum
distances to the location are identified, hence the associated roads are
found. However, this kind of technique can go wrong in some other cases.
For example, if an accident occurs near junction 7 on the SW Circle road,
the road between intersection 7 and 8 rather than that between 7 and 11
will be incorrectly identified in terms of the minimum distances (referring
to the layout map on the covering page). In further development of this
program, a certain region associated with a given road should be defined
beforehand, so that the locating principle will be based on the region’s
limits.
Budd (1997) points that "Object-Oriented programming (OOP) is a new way of thinking about the process of decomposing problems and developing programming solution". In the present study, specifications for this project were carefully defined first, in order for the specific goals to be established. On the second step, the problem of city traffic light controls were decomposed into several components (i.e., roads, junctions, cars, and etc.). The third step is that these components were to be recorded in CRC (Components Responsibilities Collaborators) cards, so that the individual responsibilities of every components and the relationship among them can be clarified. These 3 steps are necessary and sufficient conditions for starting to write a successful program.
Definitely, this program can be further
improved on the basis of the classes and components presently established.
The successful completion of this project fully shows the advantages of
OOP.
Budd, T., 1997. An Introduction to Object-Orientation Programming (Second Edition), ADDISON-WESKEY Inc., Reading, pp 452)