Visual Traffic Simulation: Thomas Fotherby
Visual Traffic Simulation: Thomas Fotherby
Thomas Fotherby
June 2002
Individual Project
Final Report
MEng Computing Degree
Department of Computing
Imperial College
Abstract
i
Acknowledgements
I would like to thank my project supervisor, Professor Jeff Magee, for his
help and guidance with this project and in particular for the authorship of
the timing code that I have used. I would also like to thank my second
marker, Susan Eisenbach for her suggestions during the project review. For
programming pointers and design issues I’d like to thank two of my peers in
particular, Fahad Khan and Chloe Cowland.
ii
Contents
1 Introduction 1
1.1 Project Motivation . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Project Objectives . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Project End-Users . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Report overview . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Project Background 6
2.1 Introduction to Simulation . . . . . . . . . . . . . . . . . . . . 6
2.2 Introduction to traffic modelling . . . . . . . . . . . . . . . . 7
2.2.1 Microscopic approaches . . . . . . . . . . . . . . . . . 8
2.2.2 Aggregated Macroscopic approaches . . . . . . . . . . 11
2.2.3 Unsignalised intersection Theory . . . . . . . . . . . . 13
2.2.4 Traffic flow at signalised Intersections . . . . . . . . . 13
2.2.5 Traffic light calculations . . . . . . . . . . . . . . . . . 15
2.3 Introduction to traffic simulation . . . . . . . . . . . . . . . . 17
2.4 Examples of Commercial Traffic modelling and simulation tools. 18
2.5 ITS (Intelligent Transport Systems) . . . . . . . . . . . . . . 21
2.5.1 Signalised junction algorithms . . . . . . . . . . . . . . 25
2.6 Graphics considerations . . . . . . . . . . . . . . . . . . . . . 27
3 Requirements Specification 29
3.1 Road Network Designer . . . . . . . . . . . . . . . . . . . . . 30
3.2 Visual Simulation . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.3 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.4 Further Project Modules . . . . . . . . . . . . . . . . . . . . . 33
iii
iv CONTENTS
5 Evaluation 56
5.1 Analysis of car movement . . . . . . . . . . . . . . . . . . . . 57
5.2 Non-signalled Junctions . . . . . . . . . . . . . . . . . . . . . 58
5.3 Signalled Junctions . . . . . . . . . . . . . . . . . . . . . . . . 59
5.4 Bridges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.5 Gridlock situations . . . . . . . . . . . . . . . . . . . . . . . . 64
5.6 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.7 Design changes . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.8 Design problems and possible solutions . . . . . . . . . . . . . 68
5.9 Usability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
5.10 Proposed Project Extensions . . . . . . . . . . . . . . . . . . 71
6 Conclusion 72
A User Manual 73
A.1 The Goal of the VIS-SIM Project . . . . . . . . . . . . . . . . 73
A.2 The Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
A.2.1 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 74
A.2.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
A.3 The Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
A.3.1 Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 77
A.3.2 Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
B Developer Manual 79
B.1 Extending the car following model . . . . . . . . . . . . . . . 79
B.2 Adding new types of junction . . . . . . . . . . . . . . . . . . 79
B.3 Developing ITS features . . . . . . . . . . . . . . . . . . . . . 80
C Demonstration Website 81
List of Figures
v
vi LIST OF FIGURES
Introduction
This report is intended to document the final year project, “Visual Traffic
Simulation”. It covers the design, development and evaluation of an appli-
cation simulating road traffic using models of common road junctions and
driving behaviour. The background section of this document contains re-
search into traffic-modelling theories needed for the application. The design
and implementation sections describe how the theory can be programmed
into a piece of software. A large part of the project is involved with pro-
gramming a fast and accurate graphical display of the traffic simulation
data. These programming techniques are described in the implementation
section of this document.
1
2 1.2. PROJECT OBJECTIVES
simulation is a record of all the interactions that occur when the different
objects are applied to the same environment.
The project aims to investigate traffic models and fit them into a flexible
graphical user interface to provide a customisable system for the user. The
application should allow a subsection of a road network to be modelling in
a matter of minutes and to be visually presented on the screen in a clear
way. The model can then be animated through time with traffic shown
drawn-to-scale. The application will provide an interface to specify traffic
intensity levels before animation starts or to dynamically change it during
animation. The application will also provide statistical results for any data
that is run on the simulation. Finally, the code to the simulation will be
publicly available, clear and documented to allow users to extend or change
the simulation to fit their modelling criteria.
A large focus of the project is making it accessible and to this end much of
it should run on a standard web browser. This is to keep in the spirit of it
being an educational project to explore and test traffic phenomenon.
The application should be able to be used to test and compare how different
road set-ups influence traffic systems. The project will be a complete self-
contained software product and the “visual” part of the project means it
will contain both a simulation and animation component.
Since there are many accurate commercial simulations currently in use, this
project is best suited as an educational tool. It aims to help people under-
stand the behaviour of traffic in a visual way. The focus of the project will
be in the animation of traffic and the resulting visualisation allows easy in-
terpretation of results to untrained observers. The project will also provide
a simple and quick way to specify the layout of a road-network, and the
ability to dynamically change settings as the animation runs.
A significant part of the project will be available from the web meaning the
general public can access it. As an example of the educational value of the
application I have used it to create an educational web site describing some
traffic phenomenon. This is described in the appendix section. The project
would be most useful to a researcher who wants a pre-built traffic visualisa-
tion that they can modify to test a hypothesis about traffic or to simulate a
new intelligent traffic-light network that they have designed. The graphical
approach to the project would be useful in communicating their results or
methods without the need for knowledge of their particular strategy. The
project could also be used as a graphical front-end to an existing simulation.
The project web site contains additional documentation and is the home of
the on-line applet version of the project.
http://www.doc.ic.ac.uk/~tf98/Project
The source code and an API (in the form of Javadocs) are also available from
this web site. There is also a logbook that documents the project progress
and highlights some of the implementation problems.
4 1.3. PROJECT END-USERS
Conventions
Terminology
Road designer This is the term used to describe the editor section
of the project application that allows road networks
to be created and edited.
Road Network This term describes a series of roads and junctions
connected together. Other terms used are Road In-
frastructure and Road schematics.
Signalled Junction This term describes a junction where traffic is con-
trolled by traffic lights.
VIS-SIM This is the name of the main project application.
VIS-SIM-LITE This is the name of the part of the project application
that runs in a web-browser. It is cut down version of
the main application with many of the file options
missing.
The following is a list of all the acronyms used in this document, and their
relevant expansion.
Project Background
Simulation is used to answer “what if?” questions about things that are
too complex or expensive to test for-real. It can be defined as “a dynamic
representation of some part of the real world achieved by building a com-
puter model and moving it through time” [15]. Traffic systems have always
come under intensive investigation using modelling and simulation. The
model describes a particular abstraction of the proposed or real-world sys-
tem and is built in the initial effort of comprehending the system. There
are four components that, when brought together by a model, result in a
visual simulation (see Fig 2.1). The first component is the data that will be
applied to the model, i.e. the traffic statistics and information. The second
component is the simulation algorithm that calculates vehicle movements
(cars or whatever else e.g. trams, bicycles, pedestrians) with their specific
acceleration and deceleration behaviour. The third component of a visual
simulation is the animation component, representing the simulation results
as movements of vehicles on the computer screen. Thus, simulated traffic
is easy to observe and to evaluate. Validation is the last component, it is
necessary to fit the model and data to real traffic situations. The model
binds the four components and represents the merger of the physical laws of
6
7 2.2. INTRODUCTION TO TRAFFIC MODELLING
the objects involved in traffic systems and the layout of the traffic network.
• Detection of bottlenecks.
The scientific study of traffic flow had its beginnings in the 1930’s with the
application of probability theory of road traffic and the study of models
relating volume and speed and the investigation of performance of traffic
at intersections (Bruce Greenshields 1947) [3]. After World War Two, with
the tremendous increase in use of automobiles and the expansion of the
highway system, there was also a surge in the study of traffic characteristics
and the development of traffic flow theories. The 1950’s saw theoretical
developments based on a variety of approaches, such as car-following model,
traffic wave theory and queueing theory. By 1959 traffic flow theory had
developed to the point where it appeared desirable to hold an international
symposium. Since that time numerous other symposia have been held on a
regular basis dealing with a variety of traffic related topics. In June 1992
the Transportation Research Board Committee of the Theory of Traffic Flow
recommended the writing of an updated document on the state-of-the-art
of traffic theory. The document that they produced contains much of the
underlying theory of today’s traffic modelling techniques, it can be found at
reference [3].
Traffic models fall into two categories: Microscopic approaches and Aggre-
gated macroscopic approaches.
• Response is the magnitude of the reaction from the driver (e.g. de-
acceleration).
where:
Simple models are not very satisfactory because they do not take account
properly for stability. Local stability is concerned with the response of a fol-
lowing vehicle to a fluctuation in the motion of the vehicle directly in front of
it (i.e it is concerned with the localised behaviour between pairs of vehicles).
Non-linear car-following models postulate more complex relationships that
describe stability better. Asymptotic stability is concerned with the manner
in which a fluctuation in the motion of any vehicle is propagated through
a line (platoon) of vehicles (see discussion of traffic waves in following sec-
tions). Asymptotic stability can be approximated by adding to equation
10 2.2. INTRODUCTION TO TRAFFIC MODELLING
ẍn+2 (t + T ) = λ1 [ẋn+1 (t) − ẋn+2 (t)] + λ2 [ẋn (t) − ẋn+2 (t)] [3] (2.3)
From Fig 2.2 it can be seen that the “Human factor” will have an enor-
mous influence to the mathematical models used to describe car-following.
Human factors have been studied extensively in the context of a person-
machine control system, the motor vehicle. The easier measurements are
discrete components of performance, largely centred on neuromuscular and
cognitive time lags. These measurement describe perception-reaction times,
control movement times, responses to the presentation of traffic control de-
vices, handling of hazards, and finally how different segments of the driving
population may differ in performance. There are more difficult human fac-
tors to study such as control performance at steering, braking and speed
control and harder still, lane keeping, car following, overtaking and gap
acceptance.
Microscopic analyses runs into two major difficulties when applied to a street
network. Firstly, each street block and intersection are modelled individu-
ally. A proper accounting of the interactions between adjacent components
(particularly in the case of closely spaced traffic signals) quickly leads to
intractable problems. Secondly, since the analysis is performed for each net-
work component, it is difficult to summarise the results in a meaningful fash-
ion so that the overall network performance can be evaluated. Simulations
help these problems to some degree but often do so by using macroscopic
methods alongside a core microscopic approach.
These variables are used in models that try to characterise traffic streams.
For example, traffic density is related to traffic volume by a relationship
known as the fundamental diagram. The fundamental diagram provides
maximum flow at a critical density value. If density is further increased
(e.g. due to entering traffic), traffic volume decreases and a more or less
severe congestion results.
Early theoretical road traffic studies tried to establish analogies with phys-
ical laws of incompressible fluids. The analogy only worked for high con-
centrations of traffic but the kinematic wave theory helped to model some
traffic phenomena such as bottlenecks and shock waves. Kinematic waves
are pressure waves in fluids. The consideration of a hydrodynamic theory
of traffic, suggested by fluid flow analogies, has proved significant and has
enabled several traffic control practices to be improved [1]. Hydrodynamic
theory is based on three fundamental principles:
2. The law of conservation of mass (the same number of cars enter a road
section as leave it).
slows down slightly, the next has to brake harder, the next harder still, and
so on. This is a case of oscillation with positive feedback. With any luck,
the cycle is broken if one driver has had the sense to leave a bigger gap. In
the worst circumstances the cycle is broken by a crash.[9]
filtering effect relates to the observation that the number of vehicles passing a
signal during one cycle does not exceed some maximum value corresponding
to the signal throughput. The effect of vehicle bunching weakens as the
platoon moves downstream, since vehicles in it travel at various speeds,
spreading over the downstream road section. This phenomenon is called
platoon diffusion or dispersion.
mum green is the maximum green time allowed to a specific phase, beyond
which, even if there are continuous calls for the current phase, green will be
switched to the competing approach.
Signalled junctions take much of the blame for congestion from vehicle
drivers. There has been much research by ITS into computing optimal
conditions for signalled junctions.[13]
Fig 2.5 is a T-junction with 6 routes that a vehicle can take (A-F)[11]
The aim is to find maximum conflict-free sets. First inputs, outputs and
intermediate nodes are drawn (see Fig 2.6).
16 2.2. INTRODUCTION TO TRAFFIC MODELLING
The junction paths can be specified in terms of paths from node to node
(see table below):
A = 1-2-3
B = 1-2-4
C = 3-2-1
D = 3-2-4
E = 4-2-1
F = 4-2-3
Conflict free sets are sets of routes not connected in the conflict diagram.
Maximal conflict free sets: {A,B,E}, {A,C,D}, {A,D,E},{D,E,F}
Digital computer programs to simulate traffic flow have been developed from
1950 onwards. Macroscopic simulations gained interest since the 1960s [1].
Simulations allow the user an opportunity to evaluate alternative strategies
before implementing them in the field. Rural simulations were developed
more slowly that urban simulations because the lower traffic volumes do
not make simulation cost-effective. Traffic simulations were first developed
independently by different countries and often to investigate a small problem
domain. The first simulations were developed on large government and
university mainframe computers. Recent simulations are a combination of
the work of many earlier simulations from many countries and therefore
often cover a much wider problem domain.
Many road traffic simulations have been developed to investigate many dif-
ferent aspects of traffic management. Other traffic simulation applications
exist for air, rail and sea transport but this document only investigates road
simulations. The most popular type of simulations are motorway and urban
systems due to the high traffic densities and problems of congestion making
them the most cost-effective type of traffic-simulation. There are also many
domain specific simulations such as intersection control and environmental
simulations.
Motorway simulations have been popular due to the high traffic densities
and problems of congestion making them the most cost-effective type of
traffic-simulation.
Urban traffic simulators have been used to model urban congestion. They
have to cope with large numbers of vehicles and signalled junctions.
Rural simulators are less common because they are less cost effective than
urban simulators. Rural simulators pay particular attention to models of
road slopes and over-taking behaviour
Traffic signal control is a system for synchronising the timing of any number
of traffic signals in an area, with the aim of reducing stops and overall vehicle
delay or maximising throughput. Traffic signal control varies in complexity,
from simple systems that use historical data to set fixed timing plans, to
adaptive signal control, which optimises timing plans for a network of signals
according to traffic conditions in real-time. With the increase in population
size, historical data for traffic-light timing information becomes obsolete
within a year [13].
Evacuation Simulations
Environmental Simulations
GTRAF (Graphic TRAFfic) was designed to offer the user of the NETSIM
and CORFLO simulation models a graphical means of displaying results.
The package include traffic animation capabilities as well as static displays,
graphs, and “snapshots” of system status at user-specified times. For exam-
ples of graphical displays see Figures 2.9, 2.10, 2.11 and 2.12.
“ITS is the term commonly used to describe the use of electronic systems
for the management of road traffic and other modes of transport to improve
decision making by network operators and users” [4]. New technology avail-
able to councils has the power to increase the efficiency of road systems
and so many councils are introducing intelligent transport systems as pilot
22 2.5. ITS (INTELLIGENT TRANSPORT SYSTEMS)
ITS systems are also being used as electronic payment, access control and
enforcement systems, such as automatic tolling, vehicle recognition and re-
striction. Camera networks are used extensively in ITS systems for traffic
signal and speed enforcement and also for video surveillance.
Many road-junctions today are fitted with an induction loop under the sur-
face of the road that can detect whether a car is above it. An inductive loop
is simply a coil of wire embedded in the road’s surface. Inductive loops work
by detecting a change of inductance caused by large steel objects positioned
in the loops magnetic field. Signal junctions of this kind are called “vehicle-
actuated” because the junction knows where cars are waiting. Simple ad-
vances in technology such as this are the components than are being included
into wider ITS systems. Signals and pelican crossings can be synchronised
by a central computer which carries out continuous calculations to determine
the most efficient settings to assist traffic and pedestrian movements. Traf-
fic management systems can be connected to the internet so commuters can
24 2.5. ITS (INTELLIGENT TRANSPORT SYSTEMS)
tap into real-time traffic data before they leave their driveways [16]. Closed
Circuit Television (CCTV) images can be transferred directly to a central
control room where operators are able to identify causes of congestion and
intervene through control systems. Many councils currently use this system
but ITS systems are trying to develop recognition software used on CCTV
images to automate congestion corrective measures. Fixed traffic cameras
have a constant background and therefore it is easier to detect moving ob-
jects for image recognition techniques. In the event of a system failure, the
system can notify the appropriate engineers and then fall back on baseline
information.
Traffic simulations are used to develop, evaluate and optimise ITS software
systems. Simulations use various methods to try to optimise traffic flow
however it must be considered that traffic data available to a simulation is
only limited by the model provided, however in a real situation it becomes
increasing expensive to get more real-time traffic data. For example many
junctions could be optimised using queue length information however this
may be expensive and difficult to install in practise. Current technology
uses two types of detector: passage and presence [3]. Passage detectors, also
called point or small-area detectors, include a small loop and detect motion
or passage when a vehicle crosses the detector zone. Presence detectors, also
25 2.5. ITS (INTELLIGENT TRANSPORT SYSTEMS)
called area detectors, have a larger loop and detect presence of vehicles in
the detection zone. The information most widely available at a reasonable
cost to signalled junctions is a measurement of cars that pass a particular
point of the road. Simulations should bear this in mind.
The randomisation gives, over a longer time frame, each traffic light about
the same period for green as for red, making busy junctions clog up and free
ones stay green uselessly. This may seem a useless algorithm, but it is fairly
close to what is used in current controllers!
Most Cars. The traffic lights will be initialised to the setting that will
let the most cars pass. This might not mean the best setting, even for one
junction, because junctions do not communicate, and road users on linked
lanes might not be able to proceed because the decision about that lane at
the next traffic light is different. Most Cars relieves the most clogged up
lanes, but does not take into account how full lanes are in comparison with
others.
Hill-Climbing. This heuristic calculates the gain for each waiting road user
per sign per junction input node and sets the lights green for the sign with
the best score. It can work well in simulations but can’t be implemented in
real because of the lack of information about the road-users at junctions.
26 2.5. ITS (INTELLIGENT TRANSPORT SYSTEMS)
Longest Queue. The number of road users waiting for a traffic light to turn
green (not the ones actually on the lane; some of these may be able to move,
and are thus not waiting) are counted, and this decides the combination of
traffic lights to be turned green in the next time slot. This is also useful for
other junctions, because the longest line in a lane has the highest chance of
being full, and so full lanes that impede the movement at other junctions
get dealt with first. Making decisions based on the longest queue is of little
use though when a high number of road users try to follow the same path:
lanes may get full, and, even when being dealt with first, the road users on
these will be stuck because of the next lane being full.
Best First. There are several ways to turn lights green for lanes and of
these the setting with most road users waiting is seen as most rewarding
and chosen. The length and number of lanes of roads decides how many
road users can be on it at the same time, and this decides the combinations
of lanes most often given the go ahead. As a consequence, combinations of
short and narrow (with few lanes) roads might get clogged up and still be
passed over because of larger roads getting preference at their junction.
The gain of each traffic light is determined by the road-users who are in the
waiting queue of this traffic light. Each one of the road-users gives a vote
for red and green, denoted by Q(green) and Q(red), the difference between
them is the benefit for this road-user to put this traffic light to green. All
benefits are summed and form the gain of this traffic light.
Initially the Q values for red and green are set to zero for all possible situa-
tions. When a road-user moves this will change the Q value of that situation.
After a while, when all possible situations have occurred a couple of times,
the system will learn a optimal policy which will result in an increase of
performance.
The Q value for a current situation is calculated by summing over each pos-
27 2.6. GRAPHICS CONSIDERATIONS
sible situation (target) which is reachable for this road-user at this situation.
Per target the chance of reaching this target (from this situation) is multi-
plied by the instant reward plus the reward for reaching the next situation.
This reward of the next situation is subjected to a certain discount factor,
this will make sure that past event won’t influence future decisions to much.
In formula form an example could look like:
P
Q= [P ∗ (R + j ∗ V )] [20]
The on-screen graphics for this project will all be simple 2D line and shape
drawing. Since urban roads often consist of straight-line sections, the graph-
ical algorithms that draw the roads, cars and junctions will make use of
straight-line geometry. The background research needed for this is obtained
by reading graphics API’s and I will rely on past experience with graph-
ics. Much of the calculations will use simple angle geometry and geometry
transformations such as the affine transform. Information for these kind of
calculations can be found in an A-level mathematics textbook and where
used will be described in the design section.
animations by drawing to an off screen image and updating the screen with
the whole image in one go so the viewer can’t see each individual drawing
occur. These sorts of animation considerations are researched by studying
the libraries and API of the programming language used. The design section
of this document will cover the specific implementation in more detail.
The simulation will run according to the model programmed into the ap-
plication. To deliver results to the user it must also collect data generated
as it is run. This data can then be displayed to the user in graphical form
or written to a file for later analysis. XML is a language used to structure
documents and data. It is a standard for saving and loading simple data
files such as road network specifications.
Now that much of the background research has been covered, a require-
ments specification will follow to set out how the researched material will
be included in the project application.
Chapter 3
Requirements Specification
This section of the report will deliver a requirements specification for the
application that was the result of the project. It is a direct guide to the
functionality of the application and also tries to dicuss the reason a particular
requirement was designed. The specification has been modified from the
original to reflect the exact nature of the final piece of software. Changes
from the original specification are documented thoroughly in the relevant
sections of the report.
The project consists of two application components, namely the Road Net-
work Designer and the Visual Simulation. Further to this there is a docu-
mentation component and further project modules.
29
30 3.1. ROAD NETWORK DESIGNER
This section of the application should allow a user to quickly design simple
schematic road diagrams (road networks). They will do this by drawing
“roads” onto an initially blank canvass. It should be imagined that the
design is a sub-section of a larger road network. Cars will therefore enter
and exit at roads which have been drawn to connect to the edge of the
canvass. These roads will be called input and output roads. A car will start
at any input road and can get to any linked output road.
To reduce the scope of the project and to make it quick to use many simplifi-
cations to the real-world must be made. For example the terrain is assumed
to be always flat and only one vehicle dimension should be used initially
(Ford escort dimensions approximately 4.3m by 1.6m).
Two roads should never intersect each other, instead an object should be
placed to define how the roads interact. The object will be called a junc-
tion but maybe a bridge (over or under) or a junction (signalled or non-
signalled). Roundabouts are a common junction but will not be in the
31 3.2. VISUAL SIMULATION
For the application to be quick to use there must be sensible default values.
The default junction will be a signalled junction. There should also be
controls to change values dynamically when the simulation is running.
Before the user moves from a road network design to the visual simulation
they must have specified a valid road network. In a valid road network all
road sections must end at either a junction or the edge of the canvass.
Once a road network design has been created a user should be able to save
it to a file and should be able to load other designs. They should also be
able to specify an image to use as a backdrop to a design.
Each vehicle will behave according to a model. Every detail of the model
must be specified to get the required behaviour of traffic in the road network.
Cars obey a speed limit which is their “top speed”. An example maybe
between 50 and 60 kilometres/hour (31-37mph). When cars enter an input
road they enter at their “top speed” at positions and times according to a set
traffic-model specified by the user. If a car can’t enter the network because
there are other cars blocking the way it should queue at the input. The
user should have access to information about the queue length at any input.
Cars do not take independent decisions. A car travel route and the lane it
32 3.2. VISUAL SIMULATION
Cars will always try to go at their top speed when possible but their speed
is governed by the “car-following model”. The “car-following model” means
a car will travel at its top speed limit unless it is within 10m of another car
and it must de-accelerate to match the other cars speed by the time there
is a 1m distance. A car will stop if it is 1m or less from another car on the
same lane.
At a non-signalled junction cars on the main route are unaffected and travel
as normal according to the car-following model. Cars on the slip roads “pull
up” to the give-way line to check for oncoming traffic. They can then join
the main-route if they aren’t going to obstruct the cars on the main-route.
I.e. there must be a suitably large clear section of traffic on the main route.
This is the gap-acceptance model.
There should be information avaliable to the user about the features of the
simulation. A user should be able to know where a car intends to go by
clicking on a car and being shown its future path. They should be able to
find out the length of a queue at any input and the timing of a set of traffic
lights.
33 3.3. DOCUMENTATION
The most important part of the simulation is the results it generates. There
should be information avaliable for:
The user should be able to request a graph of the current road network. The
graph should show the simulations throughput, average speed and conges-
tion for a particular time period. These results will allow the level of service
of a particular road network to be deduced.
3.3 Documentation
Since this project will be written with a view to being extendable, docu-
mentation of the project application and the project code is particularly
important. There should be two sets of documentation, one for a user and
one for a developer. Documentation for the user should consist of an on-line
users guide with a tutorial and example run-through. Documentation for a
developer should consist of a on-line developers guide, program API (such
as JavaDocs) and on-line viewable commented code. This report also acts
as substantial documentation on background and design.
Given the requirements discussed above the next section of the report will
document how the application has been designed and implemented.
Chapter 4
This design document aims to take the core features of the project applica-
tion and describe the design decisions and implementation details.
The programming language chosen for this project was java (version 1.4).
The main reasoning behind this decision was due to wanting part of the
application to run in a web browser as an applet. Java has a standard
API which is excellent for programming 2D graphics and graphical user
interfaces. An important feature of java is that it is object orientated. This
is extremely important for a highly modular environment like building traffic
system models because of its inheritance and information hiding properties.
4.2 Implementation
34
35 4.3. APPLICATION ARCHITECTURE
parts are smaller but do contain approximately 500 further lines of original
code.
The code was written with extension and maintainence in mind. It is com-
mented with JavaDoc style comments to explain each class and method and
to provide and API to potential future developers.
Main
The project neatly divides into three parts that will be describe separately.
These three parts are analogous to the model view controller design pattern.
The network designer (Controller ) builds and edits a road network (Model ).
The simulation (View ) applies traffic to the model and records results.
The glue between the Editor and the Simulator is a mediator class called
Main that contains the main() method. It contains all the applications
controls such as the buttons and the menu bar. Main also contains the
action listener providing the functionality for the controls. It handles the
switch between the Editor and the Simulator and it directs events generated
by the controls to the interface that is currently deployed. In a switch
Main changes the buttons and menu item available to the user and swaps
the visible panels between the Editor and the Simulator. The mediator
pattern means Main is the only class with detailed knowledge of all the core
application classes thereby increasing maintainability and promoting looser
coupling between these classes.
36 4.4. COMPONENT DESIGN
RoadDesigner
* * 1
Road Junction Popup
InputPopup JunctionPopup
The Editor (Road Designer ) is the section of the application that enables the
user to design a road model. The question arises as to how the model should
be visually represented. Initially I imagined a road network model being
represented as a directed-graph with nodes as junctions and paths between
nodes as road-lanes. The advantages of using directed-graphs might be that
they could show more explicitly which lanes link to which other lanes. There
are also java packages to handle directed-graphs. This idea was rejected in
favour of a representation of the road network using graphics of roads and
junctions so as to provide a more intuitive and natural representation. The
tradeoff is that users aren’t explicitly shown the paths a car can take at a
junction.
Roads
Perhaps the primary algorithm of the application is one which allows the user
to draw roads on the screen. A road is a path with a start and end that the
user can create and extend. More specifically, it has a centre-line dividing
one direction of lanes from the other and it is composed of individual lanes of
any permutation. Java’s GeneralPath object seems perfect for drawing road
37 4.4. COMPONENT DESIGN
y − y1 y2 − y1
=
x − x1 x2 − x1
y2 − y1 ∆y
m= =
x2 − x1 ∆x
y − y1 = m(x − x1 )
The sign of the gradient can be confusing as the screen co-ordinates are in
the 4th quadrant of X-Y co-ordinate space whereas it is usually calculated
in the 1st quadrant of X-Y co-ordinate space.
38 4.4. COMPONENT DESIGN
(x2,y2)
dy
Q x-axis
(x1,y1) dx
∆y
tan(θ) = ∆x
θ = tan−1 (m)
(x3,y3)
Center Line
a2
(x4,y4)
a1
(x1,y1)
b
Bisecting Line
(
(a1 + a2)/2, if (a1 > a2)
b=
(a1 + a2)/2 − 180◦ , otherwise
Q = a1 + (180◦ − b)
D D
sin(Q) = ( H ) ⇒ H = ( sin(a1+(180◦ −b)) )
Given the co-ordinate (x2, y2) of the centre-line bend, (x4, y4) of a road-lane
is defined by:
39 4.4. COMPONENT DESIGN
x4 = x2 ± xH ∗ cos(b)
y4 = y2 ± xH ∗ sin(b)
Junctions
The Junction class has a reference to each road that may be connected to
one of its handles. The junction can calculate Dx by calling a getRoadLeft-
Width() and getRoadRightWidth() methods for each of its connected roads.
40 4.4. COMPONENT DESIGN
D1 D2
Handle1
D8
Handle4 D3
Junction
D7 Handle2
Handle3 D4
D6 D5
This method rotates the junction shape but also updates the point array
that defines the junction corners and handles so that any roads connected
with the junction can be updated with new end coordinates.
lines on the relevant side. Non-signalled junctions are more complex because
they need to show the user which side of the junction has priority (see Fig
4.7). Two sides have priority and the other are drawn with a dotted side line
representing a lack of priority. The priority of the junction goes to the two
sides with the biggest roads. If there is more than two equally large roads
then priority will go to the two roads that were latest modified by the user
(thereby giving control to the user). The yellow centre-line helps to clarify
the decision by joining the two roads with priority.
Line Clipping
Any valid road in the Editor must start and end at either a junction or
the edge of the map (the drawing bounds). Users are working with whole
roads rather than lanes and this means a road may have lanes that don’t
match the drawing bounds (see Fig 4.8 for an example). The lane ends must
either be extended or cut-short. Calculations for this can be done using line
intersection algorithms, either for lines or line segments. The easier case
is if a end segment of a lane intersects the drawing bounds. In which case
it needs cutting-short. Otherwise the lane end segment is imagined to be
42 4.4. COMPONENT DESIGN
infinitely long and intersection is again tested with the drawing bounds. The
problem is that it is unknown which drawing bounds edge to clip to. It can
be calculated by getting all the edge intersection points and using the one
which is closest to the lane end-point. Unfortunately Java doesn’t have a
method to get the intersection point of two lines.
At the intersection point the two lines will have the same value of x and y.
This point can be found by solving the simultaneous equations:
Any set of actions that uses up the users time should be storable and re-
trievable. I did not look further than using an XML method to achieve this.
XML is the standard for structuring data. One particular design advantage
of XML is that it provides inter-operability between heterogeneous systems
thereby increasing the possibility that the project may be useful to others.
43 4.4. COMPONENT DESIGN
*
XMLFileWriter XMLAttributes
The design of XML saving and loading is based on the Chain of Responsi-
bility design pattern. The chain of responsibility pattern allows a number of
classes to attempt to handle a request, without any of them knowing about
the capabilities of the other classes. The save is initiated by the user and
the head of the chain saves itself and passes on the request to the objects it
encapsulates. These objects then save themselves and forward the request
so that it percolates all through the chain and all objects are saved.
Objects only need to know what to save and load and not how to save their
data. The XMLSaver and XMLLoader code handles how saving and loading
works. Each object has to know its XML name, how to save/load its own
data and which children to pass on the save/load request. All objects to
save and load must implement the interface shown in Fig 4.10. The imple-
44 4.4. COMPONENT DESIGN
mentation details of the XML code heavily relies on Java’s string routines
to parse or construct XML documents.
XMLSerializable
+getXMLName(): String
+saveSelf(): XMLElement
+saveChilds(): void
+loadSelf(): void
+loadChilds(): void
In my design of the final XML document, objects are XML Elements (tags
such as <Road></Road>) and an objects data is stored as XML Attributes
inside it’s tag’s (e.g. <Road start=”x,y”>). Encapsulated objects exist
inside their parents tags thereby forming a tree structure.
In addition to saving and loading a road network, the application offers the
user a choice to save as an applet. The end result of this is the generation of
a html page which, if viewed in a browser would show a running simulation of
the current road network. The applet only shows the simulation, it does not
provide any interaction controls. The purpose of this piece of functionality
is to facilite the creation of web-pages describing traffic modelling anotated
with visual animations. See Appendix C for an example.
Usability considerations
When a programmer is also the designer, tester and evaluater usability con-
siderations often get neglected. There are many details incorporated into
the design to try to improve the user interface. Firstly, the application is
solely controlled by the mouse through an iconic graphical user interface.
The interface is split into three areas of control, the currently displayed
panel, an additional control panel and the menu-bar. Any controls that
are inappropriate to the users current actions are disabled and greyed-out
thereby minimising the clutter of controls. Drawing roads is designed to
45 4.4. COMPONENT DESIGN
feel familiar to users who have used applications where lines can be drawn.
Drawn components are aligned with a grid so that a regular layout is made
easier for the user. Drawn components are manipulated by handles. Handles
also snap to the grid and other handles (where relevant). These handles are
highlighted in red when the mouse passes over them to show the user that
they are control points.
Fig 4.11 shows some of the discussed usability features and demonstrates a
question-mark texture which forms when two roads cross without the user
selecting a junction.
4.4.2 Simulation
SimPanel
RoadNetwork
1
1 *
CarGenerator JunctionModel
*
LaneModel
1 GiveWayJunctionModel Sig1JunctionModel
1 CarContainer
*
TurnOffJunctionModel
Car
*
BridgeJunctionModel
*
LaneSection JunctionPath
AdaptiveSig1JunModel Sig2JunctionModel
AdaptiveSig2JunModel
The SimPanel aims to animate vehicles on a road network that was draw
by the user using the RoadDesigner.
cars new location and in the SimPanels tick() method, all the cars are drawn
to a backbuffer. The last action of a tick is that the backbuffer is labeled
with the current frame number and is swapped onto the screen. This design
combines a back-buffering approach to animation with the necessesity of
clearly presenting the time dimension to the user.
The timer runs in its own thread and sleeps by x milliseconds in between
each tick. The user has direct control of the speed of the timer by controlling
x through a slider. The simulation can also be paused by suppressing the
timers ability to tick.
Let x denote the distance in metres between two cars (measured from the
front of one to the back of another, or between the front of one car and a
red light ahead).
k, if x >= L
v= between0andk, if l < x < L
0 if x <= l
In the second case, l < x < L, we’re assuming the car changes speed pro-
portionally to changes in distance, so that v is given by a “linear” function
of x (the graph of v as a function of x is a straight line). This means that
v = mx + c for two constants m and c. These constants can be determined
from the two conditions:
therefore:
k if x >= L
v= mx + c if l < x < L
0 if x <= l
From these, we can solve for m and c in terms of the three fundamental
numbers k, l, and L:
1. v = mx + c
These three numbers (k, l, and L) therefore, completely determine the traffic
behaviour. The design decision to use the simplest model possible allows the
project a wider scope in other aspects, however the model suffers in realistic
factors such as drivers’ reaction times, or limits to how fast a car can brake
or accelerate.
Animation of cars
opposite
tan(α) = adjacent ⇒
whilst: θ = α1 − α2
tan(α1)−tan(α2)
⇒ tan(θ) = 1+tan(α1)∗tan(α2)
m1 −m2
⇒ tan(θ) = 1+m1 ∗m2
θ = 0.5π and m1 ∗ m2 = −1
A cars new location after a moving a certain number of pixels in any direction
can be calculated using the Pythagoras theorem. If θ is the angle between
the x-axis and the direction of the car, then the distance moved is explained
in Fig 4.14.
D y -= D
D*
Sin(Q)
Q Q
x += D*Cos(Q) x -= D*Cos(Q)
Q Q
y +=
D D* D
Sin(Q)
Figure 4.14: Distance car moves given an angle from the x axis
For a car to know how far away it is to another car the distance of two
50 4.4. COMPONENT DESIGN
distance
speed = time
acceleration = ∆ velocity
time
The cars are implemented as sprites, i.e. they are entities that know how
to draw themselves. The drawing of objects is based on the visitor design
pattern. The SimPanel keeps a list of all the cars and iterates through the
list telling each car in the list to draw itself onto the background it supplies.
It is therefore visiting each of the car classes in turn.
Car generation
Often a congested road will block incoming traffic from entering the road
system. In this case the vehicle must be added to a queue at their particular
input. If congestion clears, cars from the queue should enter the network. A
user can check the size of a input queue by clicking the mouse on the input.
51 4.4. COMPONENT DESIGN
Junction models
Modelling the junctions of a road network is the most complex part of the
project. The models need to refect real-life behaviour of traffic at junctions.
This difficulty arises due to the large number of junction formats used on
roads.
One design option could be an interface for users to design their own junc-
tions and save them to a list for later use. The problem is that when objects
need a lot of customising it increases complexity enormously because many
exceptional cases seem to crop-up that need to be catered for. The design
process is also often complex and time consuming for the user (something
this project aims to avoid). An alternative design was to provide less choice
of junctions but to make them much more generic. As an example, if the
user has to design junctions, they’d have to specify one for each permutation
of lanes and turning options and traffic light sets, whereas a generic junction
adapts automatically to any number of lanes and connecting roads.
The best solution would be to implement both choices however due to time
constraints the generic junction approach was taken. This is possible because
it was found the majority of junctions can be modelled from a few generic
cases. It is also the approach that is easiest for the user. The project provides
two types of signalled junctions, one where opposite light sets synchronise so
traffic is given a option to go straight ahead or turn left (but not right), the
other is where any output can be reached but only one side of the junction
is green any any point in time. If other junctions are needed they would
need to be manually programmed into the system for which a development
guide is given (See Appendix B).
Put simply a junction is a link through which cars can get from an input
to a legal output. In the real-world a vehicle driver decides when to enter
a junction and which output to go to. Since they follow traffic signals and
signs at the junction the outcome to their decision can be thought of as
a function of the lane that they are in and the behaviour of the junction.
This is how vehicle behaviour at junctions is modelled in the simulation.
Vehicles are assigned one of the legal output lanes and they are denied
access to the junction unless it is appropriate for them to continue. In the
real-world the driver chooses where to go whereas, in the simulation the
junction effectively chooses where they go by assigning them a output lane.
This is a philosophical design decision based on the observation that when
examining a road system one does not know information on where individual
cars are going however statistical knowledge is known about the proportion
of traffic that go one way or another at a junction.
52 4.4. COMPONENT DESIGN
Bridges. Bridges are not junctions in the real-world but it was convenient
to model them in the same way as junctions because they occur when two
roads cross and the user needs to specify which road is above the other. A
vehicle entering a bridge will always exit it on the same lane. i.e. a bridge
has no extra turning options and never denies access to vehicles.
cars still on the junction on interfering paths. Using these heuristics alone
does not work in a congested environment because cars end up forming a
traffic jam in the middle of the junction. It is therefore necessary to add
rules so that a car won’t enter a junction if the car in front is moving slowly
or if there is no space for it to fit on the other side of the junction. The
lights of the junction signals are contained in sets and each set is given a
green-light time where it will stay green before turning red. The sets are
cycled through as each green-light time passes. The user can set the green-
light time manually.
Type 1. The variation of different junctions is essentially in what the turn-
ing options are for the cars at the junction and therefore also the traffic light
sets that synchronise with each other. The first type of signalled junction
allows vehicles to either go straight on or turn left if they are in the left
lane or turn right if they are in the right lane. The problem is that for this
to be easily implemented only one side of lights at a time turn green, it is
therefore not a realistic approach.
Type 2. The lack of a realistic junction is solved by a signalled junction
where opposite sets of lights synchronise allowing opposite traffic to pass
each other or turn left. The majority of real-world signalled junctions work
in this way.
ITS models
The simulation provides two of the basic constructs of ITS, vehicle actuated
traffic lights and adaptive traffic lights. Vehicle actuated traffic light sets
only turn green if there is a vehicle waiting at them otherwise they skip to
the next step. Adaptive traffic lights use an algorithm to score each traffic
light set based on the number of cars waiting at the lights. green-light time
is deducted from the set with the lowest score and added to the set with the
highest score. A good balance is always met because if a set of lights has
too low a green-light time more cars will end up waiting and this increase
the sets score so that its green-light time is recovered. The change in time
occurs frequently and in small steps. There is also a minimum time for a
light set unless the junction is vehicle actuated. The adaption algorithm is
essentially a hill climbing algorithm, it tries to find the best solution in the
local area.
calculated by dividing the distance the two junctions are apart by the aver-
age speed of a car.
Collecting results
A number of key results are calculated and stored as the simulation is run.
There are three levels of scope for the results. Immediate results are cal-
culated based only on the information of the current frame. Fig 4.15 is a
screenshot showing how the immediate information is displayed on the panel.
Users can suppress this information from showing or from being recorded.
There is also information based on either the last x frames or from the entire
history of the simulation. The statistics panel (see Fig 4.16) gives a snapshot
of the results at a certain frame of the simulation. The snap shot shows the
Throughput of the simulation. This is the number of cars that pass through
the road network per time interval (cars exited / frame number). For a
dynamic update of the simulation data the user can open a graph panel to
see how number of cars, average speed or average congestion changes over
time. The graph will be updated every second.
The next section of the report starts from a finished implementation of the
project application and evaluates it in terms of its strengths and weaknesses.
Chapter 5
Evaluation
This section of the report aims to test and analyse the project application
to determine its strengths and weaknesses and to determine what one can
learn from it. Much of the evaluation is of a qualitative nature however the
application has the capability to produce statistics and graphs that can help
in a more quantitative way.
Traffic modelling and simulation is a vast and complex subject and an area
of active research. Commercial simulations tend to concentrate on limited
areas of the subject and don’t broaden out beyond realistic boundaries. The
objective of this project was clear in that the project would not involve the
kind of accuracy that existing commercial simulations implement but will
provide an easier interface for untrained users. This suggests that validation
tests are less important than usability and visualisation quality.
The scope of the project made it impossible to model all the behaviour that
is needed for a valid traffic simulation. The scale of the roads and vehicles is
simplistic and car accelerations are fixed. The car-following model is linear
and basic, there is no overtaking or lane changing model. Vehicle collisions
are not modelled or tested for, and there is little individual driver behaviour.
There is no model for roundabouts or a tool to specify all junctions. The
users can only set speed limits globally not for each road. There are no
smooth corners, and no non-flat terrain. Traffic is all of one type and there
are no pedestrian crossings. The simulation is therefore not able to take any
accurate measurements of real road-infrastructure situations.
Having discussed some of the project limitations the strong points for the
application will now be outlined. The simulation is extremely flexible al-
56
57 5.1. ANALYSIS OF CAR MOVEMENT
In the simulation road users that spawn at an edge node have not got a
specific destination, they will stay in the same lane until there is a choice
at a junction and then they will be given a path to take. The simulation
uncovered a potential design flaw for junctions. The model of junctions
is such that it is often only the extremity lanes (furthest inside or outside
lanes) that has a choice in which junction path to take. It can be seen from
fig 5.1 that the middle lane doesn’t have a choice in where to go.
This issue doesn’t invalidate the junction model because junctions with roads
of three or more lanes are fairly rare and may well implement the same
behaviour as the simulation.
If cars did have a specific destination their path though the network could
be implemented with Dijkstra’s shortest path algorithm. A large advantage
of this would be that the simulation could calculate the average journey time
for vehicles. This statistic is interesting because it is an example of informa-
tion that a simulation can easy acquire but would be next to impossible to
58 5.2. NON-SIGNALLED JUNCTIONS
(a) Junction paths with roads of (b) Junction paths with roads of
2 lanes 3 lanes
The first type uses a simple gap-acceptance model and is practical in many
situations where cars need to turn onto or off a main road. Priority flow is
unaffected by the junction except the left most lane has the choice of turning
off. Vehicles wanting to turn onto the main road (Vehicles waiting) must
wait until a suitable gap occurs.
The second type only allows one car inside the junction at any one time but
that car has the choice of any junction output. Although this is a flexible
junction it is designed for junctions with a low traffic density and was found
to cause large queues in situations where two cars frequently arrive at the
junction at the same time. The problem is that the junction breaks the flow
of priority traffic as they have to wait for one car at a time to pass through
the junction.
Fig 5.6 demonstrates a test for the two types of non-signalled junctions. The
two road networks were run for 2000 frames and then the graph function was
invoked to help analysis. The one-car-at-a-time give-way junction ended up
59 5.3. SIGNALLED JUNCTIONS
(c) (d)
with an average car speed of 2 kmh−1 and a congestion level of 38%. The
gap acceptance give-way junctions has a higher variance but has an average
car speed of 20 kmh−1 and a congestion level of 6%. The gap acceptance
give-way junction is the only valid option to use in roads that spawn vehicles
at a rate above the time it takes one vehicle to pass through the junction.
They produce a good visualisation of waiting cars nipping out onto the
junction when there is space for them to safely do so.
The first is the more practical case of where opposite sets of lights syn-
chronise allowing traffic to flow past one-another. Right-turns are obviously
60 5.3. SIGNALLED JUNCTIONS
Adaptive junctions make decisions on light times based on the longest queue
at each light-set. The set with the longest queue is given the largest amount
of green-light time. This is often useful if one side is busier than another but
is of little use when a high number of road users try to follow the route: lanes
may get full, and, even when being dealt with the longest, the road users
on these will be stuck because of the next lane being full. These junctions
also have a habit of increasing congestion inside the road network because
if there is a large input queue they facilitate the entry of vehicles. This
will flood the road network and jam it up. There tends to be a threshold
on a road network where beyond a certain frequency of cars entering the
network, it jams up and operates very poorly. The simulation does not
provide delicate enough tools to determine this threshold. The reason for
this threshold is that the input traffic-intensity of one junction will be a
function of the output traffic-intensities of other junctions, however there
is a time lag involved. The more congested a road, the larger the time lag
which allows more cars to enter the network and worsen the problem.
62 5.3. SIGNALLED JUNCTIONS
(a)
Fig 5.4 shows a comparison between a two adaptive and non-adaptive junc-
tions. The adaptive junctions provide a speed up in average speed of 3
kmh−1 and a drop of congestion of 1%. The light times adapting to give
more green light time on the busiest light-sets has reduced the variance of
the average speed graph for adaptive junctions. It should be noted that the
total time period in one light-set cycle is constant, the percentage of that
time for each set varies. This can be seen because the frequency of the two
graphs is the same.
5.4 Bridges
There is really nothing to analyse for bridges, they behave exactly as normal
lanes. They do however increase the scope of the application to model more
situations and improve overall visualisation quality.
While testing the application it was realized that it was often hard to dis-
cover the reason for a gridlock situation. In some cases the simulation would
65 5.5. GRIDLOCK SITUATIONS
Figure 5.5: Vehicles in a gridlock situation (with a cars future path shown)
stop running due to a coding error rather than gridlock. It was found useful
to develop a tool to aim to discover the reason for gridlock. The user can
click on a car and information about the car is displayed on the screen. The
information needed to discover gridlock is where the vehicle is trying to get
to. The future path of the car is drawn onto the screen. Using the future
path of a number of cars that have stopped enables the reason for their
deadlock to be discovered.
It was found that gridlock is more likely to occur when a series of signalled
junctions are placed so that a circular path is possible for a platoon of
vehicles. The closer the junctions are to each other the quicker gridlock
forms. Turn off points are also a good method to help to slow down the
occurrence of gridlock. See Fig 5.6 for an example.
66 5.5. GRIDLOCK SITUATIONS
5.6 Performance
Although the application will run fine on any of the laboratory computers it
was found to be desirable to use machines with processors above 400 MHz.
The performance of the application decreases as it contains more objects.
The Editor becomes slower when using larger road networks because it has
to do more checks for each user event. The situation that is particularly
resource intensive is when a user moves a junction. It this case the new
position of the junction and the 4 connecting roads needs re-calculating
and the computation often can’t keep up with how fast the user moves the
mouse thereby looking jerky. The frame-rate of the simulation decreases as
it contains more cars. The number of cars that still results in a good visual-
isation depends on the machine specification. Using a 1800 MHz processor,
a subjective minimum speed is reached when a road network contains 500
cars.
all the data would enable more extensive results, however it was felt that
it was not necessary due to the performance overhead and higher memory
requirements that would result.
Further modules that were completed in the final application include the
basic constructs of ITS, particularly vehicle-actuated junctions, adaptive
junctions and synchronised junction paths.
When designing many of the geometric algorithms necessary for the Editor
it was found confusing to convert to screen co-ordinates where the top-left
part of the screen is (0, 0). It would be worth considering programming a
conversion function to convert the screen to normal co-ordinates to allow
algorithms to be designed easier.
Some thought was put into how curves could be used in the application to
represent road bends. It has been proven that it is impossible to get parallel
Bezier curves. Since the design for road lanes is that they run parallel to a
centre-line, using Bezier curves would require a huge design shift. It seems
there is a solution easily implemented in openGL but not in the standard
java graphics library. The idea is to represent a road with a single path
(made from lines, Bezier curves, cubic curves etc) that is textured with an
image representing a multi-laned road. This method would be simpler and
faster than my design when using the Editor component of the application,
however it would be tricky to convert this “road image” to lanes used in the
simulation.
69 5.8. DESIGN PROBLEMS AND POSSIBLE SOLUTIONS
During the final stages of the project many problems were experienced get-
ting the application to work as an applet. It was suggested that to ensure a
browser runs the applet in a known version of the Java Virtual Machine the
html page should require a pluggin. The design was for the user to click a
java button that would open up the application in a pop-up window. This
would mean the html page with the button would be quick to load as the
entire applet code would not need downloading until the button is clicked.
It would also help unify the applet with the application. The only difference
would be in the extra class for the applet to display a button and load the
application in a new frame when clicked. The applet also disables many of
the file options like loading and saving. To run the program as an applet it
needs to be packaged up as a JAR archive. If this is done images and other
files such as XML specification files can be accessed if they are inside the
JAR archive. The problem is that in the “save as a applet” option a XML
specification file is created and needs adding to the jar archive for the cur-
rent simulation. A method to programmatically add a file to an archive was
not found and instead a script is created that the user has to run manually.
The script inserts the file into the archive successfully but is not machine
independent. This is something that could be improved upon.
70 5.9. USABILITY
5.9 Usability
During the latter stages of the project a usability test was performed by two
peers following a set of instructions. Ideally it would have been better to
get more people to test the application and for them to be from less of a
computing background. Unfortunately there was not time to implement all
but the most minor comments that they made.
The largest problem that the testers commented on was the move from the
Editor to the Simulation. The button to do this is grayed-out unless there
is a valid road network and the testers often found they did not know why
their road network is not valid. The most common reason why they didn’t
have a valid network was that roads weren’t connected to the edge of the
screen. They suggested a tool to tell the user why their network is not
valid. They were also frustrated by the lack of an undo button. The feature
that they said was the most un-usable was rotating a junction. They said it
was un-intuitive that dragging the mouse upwards would rotate the junction
one-way and down the other way. They suggested the mouse pointer icon
to change to a rotation icon where appropriate and that rotation should be
done by moving the mouse in a circular fashion. Features that they would
most like to see included are smooth corners, different types of traffic and a
zoom in/out function.
The project was written with extension is mind. Extending the traffic models
would be the first thing to do to improve the projects realism and accuracy.
It would be good to use the projects XML component used for loading
and saving to interface with a commercial simulator. In this way it could
provide a graphical front end to an accurate commercial simulation. Other
ideas include:
Now that the project has been evaluated, all that remains is to summerise
the project in a conclusion.
Chapter 6
Conclusion
The results of the project are a set of simple traffic models and algorithms
embedded in a fully independent application that can quickly model sim-
ple urban road networks. The application contains a simulation to animate
user-defined traffic data on a road network and is able to produce intuitive
visualisations of traffic flow. The results of the simulation enable different
road networks to be compared for efficiency. Documentation and back-
ground information also help annotate the project application.
Road simulations are complex programs that have been developed for forty
years. This project did not have the scope to break new ground in traffic
modelling. The limitations of the project also invalidates any accurate-
critical results inferred from using it. This project did however show the
public a simulator that is quick to learn, easy to understand and educational
to use. It is highly accessible and well-engineered, giving it potential for
further development.
72
Appendix A
User Manual
This application presents you with a tool with which you can visualise and
evaluate various city layouts with minimum user input. VIS-SIM is open
source, giving you a tool for the future, that is able to keep up with ad-
vances in traffic technology such as Intelligent Traffic Systems and control
configurations.
You probably are held up by a traffic light once in a while. Ever wondered
whether their controlling mechanisms could not better suit the flow of traffic?
73
74 A.2. THE EDITOR
All facets of the problem are dealt with: map creation, experimenting
with various traffic densities and control algorithms, and statistical anal-
ysis. Moreover, the program is open for future improvement because of its
open source nature.
Map creation is the process of drawing roads and placing junctions to form
a valid infrastructure. Afterwards, the number of lanes on roads, algorithms
for the traffic lights and starting frequencies for road users can be set. Road
users and traffic light changes are not visible in the Editor, only in the
Simulator.
A.2.1 Interface
A.2.2 Usage
When you start the Editor you get a blank map with the draw road button
selected. From here you can either load a map or start one from scratch.
1. From the middle of the drawing area click and drag out an initial road
lane with the mouse.
2. You have drawn a lane-segment.
3. Click on a lane segment control-point (there is one at either end).
Then move the mouse to see where lane will extend to. Click to place
the extension.
4. Drag control-points to re-locate lanes.
5. Now either drag or extend your lane so that both sides are at the edge
of the drawing area.
6. If you have done it right, the button labelled “The Sim” should be
clickable.
7. Click this button and cars will drive along your lane. For the moment
this is quite boring so lets make a better road system.
8. Click the “Editor” button to go back to the Editor.
9. You can reverse the direction of your lane. Click on the “Rotate”
button, Click in the triangle that shows you which direction the lane
is currently pointing, the direction should be reversed. Remember to
go back to road drawing mode by clicking “Draw Road”.
10. To extend a lane into a road, click on a lane-section triangle and drag
out the road up to a maximum of 8 lanes.
11. You can also drag out one side or the other of a road to just multiply
lanes in a particular direction.
12. To join two roads together you can join up the 2 roads endpoints and
they will merge.
13. To delete a section of a road, you can click on the “delete” button and
then click on the road handle you want to delete. Again, make sure
you go back to the road drawing mode afterwards by clicking on the
“Draw Road” button.
14. Roads that you join to the edge of the map will spawn cars. The
spawning frequency determines how busy the road is and how con-
gested a map will get. You set the “busyness” of an input node by
right clicking an input and putting the value you want in the pop-up
box.
Adding Junctions:
76 A.3. THE SIMULATOR
Other Features:
1. If you make a mess of things click the file menu and select “new” to
blank out the drawing canvass.
2. If you are not drawing only editing, use the “select” button and you
can move both junctions and roads.
3. To save the map go to the file menu and select the save option. The
actions are similar to load a map.
4. To use a particular image as a backdrop to the Editor select the “Dis-
play” menu and choose “Load Backdrop”.
The Simulator is where the real exploration of traffic interaction takes place.
In the Simulator window the loaded map is animated with its road users and
the traffic lights show their status. The only changes that can be applied in
the Simulator are those concerning the speed of cars in the system, however
you do have access to statistics that the simulator generates as it runs.
77 A.3. THE SIMULATOR
A.3.1 Interface
A.3.2 Usage
Road users will flow across their lanes, and halt only at red lights or full
lanes. During simulation, you may temporarily put the simulation on hold
with Pause, or reset it with Stop. You can change the speed of the simulation
using the slider-bar. This effectively determines how often the simulation
clock ticks.
Some statistics are shown on the Simulation panel. These can be hidden by
selecting the “Display” menu item and un-checking the “Show Information”
option. For more statistics you can bring up a statistics snapshot which will
give information about that particular frame.
78 A.3. THE SIMULATOR
There is an option to turn off the recording of data. This should be used if
you want the simulation visualisation to run at maximum speed.
Developer Manual
This manual will describe how a developer would go about extending the
VIS-SIM application to include new models or behaviour. It will describe
three extension areas, extending the car-following model, adding new types
of junctions, and developing ITS features. You might find it useful to look
at the code API and the internal code comments which can be found from
the project homepage.
A car is called to calculate it’s new position in the pretick() method that
is generated by the simulation clock. In the current car-following model
a method is called that returns the distance to the next object. There
is also a method to return the speed of the object in front. To change
the car-following model simply replace the existing method called imple-
ment Basic Car Following Model() with the new model. The new model
will need to modify the acceleration, speed and position of the car. Given
an angle and a pixel value there is a method to update the cars graphical
position called setNewPosition(pixelsCanMove,carAngle).
There are two parts to adding a new junction into the system. The first is
the graphical representation of the junctions used in the editor. The second
79
80 B.3. DEVELOPING ITS FEATURES
In the Junction class for the editor you should add a static variable and
name it according to your new junction, you should also increment the
variable defining how many types of junctions there are. If the junction
does not look like a signalled junction then you must add a case into the
drawJunction method that will display the graphics of the junction.
To build the junction model you will need a new class that is a child of
JunctionModel. You must register your new class with the RoadNetwork
class so that when it receives a junction of this type it will instantiate this
new class rather than one of the pre-existing junctions. The new class for
the junction should set up the junction paths from each input lane to any
output lane. It should set up traffic-light sets and determine how light sets
change.
Demonstration Website
As an example of the educational value that the project has potential for, I
have created a demonstration website including applets showing animations
of particular elements of the simulation. For example the traffic phenomenon
of gridlock is explained and then demonstrated in a visualisation.
http://www.doc.ic.ac.uk/~tf98/Project/ExampleWebSite
81
Bibliography
[3] Traffic Flow Theory carried out by Oak Ridge National Laboratory un-
der the guidance of an advisory committee established by Transporta-
tion Research Boards Committee A3A11. (http://www-cta.ornl.
gov/cta/research/trb/tft.html)
82
83 BIBLIOGRAPHY
[15] Drew, D.R. (1968) Traffic flow theory and control. New York:
MacGraw-Hill
[18] Hakkinen S., and Luoma, J. (1991) Traffic psychology (in Finnish).
Publication 534. Espoo: Otatieto Oy.