The Trafix Home Page

SourceForge Logo
(This page is designed for viewing through Netscape )
The Trafix Logo

A C++ Simulator for modeling Road Traffic



Main SourceForge Trafix Download/Site Index page



Introduction

In working with road traffic simulators, it becomes immediately clear that the traffic research and management community requires an open-source traffic simulator. The simulator should also have a standard general input file format, so that simulations can be easily tested under various simulators for verification. The Open-Source approach allows researchers to test various traffic theories on a standardized software platform in a reliable and reproducible fashion. Further, an inexpensive system can provide smaller municipalities with access to a tool for making their own local road networks and traffic signal timing schemes more efficient. Maximizing traffic throughput and minimizing delay would benefit trade and tourism both domestically and internationally. The possible windfall of benefits is potentially large.

The Trafix simulator was developed by one of the authors in C++ with the GNU gcc compiler under the GNU-Linux operating system. The program was designed to verify the vehicle routing algorithms selected for this hardware simulator study. Trafix is currently in a stage of development which is analogous to the program precursors of fetchmail. An open source program was needed to verify the traffic movement algorithms, and after failing to find an existing solution, Trafix was generated to fill the void. Trafix is now available as a starting point for others who need to test traffic routing algorithms, roadway patterns, etc. Trafix uses Xfig, a freely available, open-source UNIX drawing package, to generate its input files which describe the input road networks. Trafix displays its animated output in X windows as illustrated in Figure 1. The code is written to be modular so that various components can be replaced as the user community requires. The overall modular design concept is over-viewed in Figure 2. Attempts were made to allow the code to be easily changed in the future, altering the current dependence on Xfig input files and X windows output displays. In addition to using Xfig for its input and X windows for output, Trafix employs the Standard Template Library (STLPORT) routines wherever expedient to foster the reuse of code which is intended to both lead to efficiency and reduce errors.

The Trafix Display
Figure 1: The Trafix Display A view of the Trafix simulator is illustrated. Vehicles are moving from the left and bottom lanes to the top and right. Turning decisions at the second intersection depend on the vehicle's randomly assigned destination. Cars, buses, and trucks are animated as different sized and colored boxes..


The Trafix Software
   Structure
Figure 2: The Trafix Software Structure Written to be modular, the Trafix software is composed of three levels. The bottom, physical, level allows Trafix to interface with its input and output systems. As currently written, Trafix reads its input from Xfig files and displays its output to X windows displays. The middle symbolic layer serves as an intermediate level between the simulator and its physical files and converts raw data into conceptual objects. These objects include roads, intersections, and places. The top layer consists of simulation objects which include timelines, road queues, and intersection queues.


At this time, Trafix forks two processes. The first process displays two windows, each containing maps. One window holds input map symbols which have been used to generate the simulation, and the second, illustrated in Figure 1, depicts the background map for the animated traffic display. This first process is intended to eventually migrate into a more suitable user interface as community interest materializes. The second process handles the animation of the vehicle traffic. The animation is visible only on the single graphic map display. Trafix simulates car, bus and truck traffic moving through intersections and along roads.

Creating Input Traffic Networks

Initially, Trafix has been designed to model straight roads which run either north-south, or east-west. The algorithms to associate vehicles with roads requires these straight lines and will need modification to allow roads to be input as splines or curves.

Running the Simulator

Trafix simulations are created, currently, by generating a traffic network map using XFig. Trafix contains XFig library objects for 3 different types of intersections, and for 2 types of places. Trafix maps contain source places where vehicles are generated and injected into the traffic network. The second type of place included in the Trafix library are destination or sink places where vehicles exit from the traffic simulation network. The three types of intersection are two-way, three-way, and four-way. Intersections of higher degree can be developed by coupling two or more intersections with small road segments. Currently, all intersection signals are set to be stop signs. Roads are drawn as straight line segments connecting the center points of places to the pads on the intersections. The center pads on intersections are not active, so roads must connect to the edge pads on the intersections. Only one road must connect to each pad on an intersection and all intersection pads and all traffic network places must be connected. If not, Trafix will flag errors. Play with the provided test examples in the data subdirectory to get a feel for current Trafix road networks.

Place and intersection attributes can be added by using XFig comments. Trafix reads the comment lines associated with Library objects and has its own syntax for intersection and place attributes.

The Trafix XFig
  Library Elements
Figure 3: The Trafix XFig Library Trafix contains three types of intersections and two types of places. Attributes of the intersections and places can be modified by editing and adding XFig comments which contain properties. Current properties include signal type and speed limit for intersections and statistical distributions and arrival rates for vehicle sources.


For example, the following attributes are used to describe a three way intersection. The speed limit within the intersection is 20 miles per hour, and the intersection is governed by stop sign signals.

    # (place_type intersection)
    # (intersection_type three_way)
    # (signal_type stop_sign)
    # (speed_limit (20 miles_per_hour))

Using Xfig, a user creates traffic road networks by connecting places and intersections with roads (lines in XFig). A sample traffic road network is illustrated in Figure 4. The current Trafix object library consists of two, three, and four-way intersections as illustrated in Figure 3, along with source and destination nodes. Roads consist of drawn lines. Object characteristics are included in the object comments as shown in the preceding example. A road speed limit can be set by adding a speed attribute in the drawn road line comment. Xfig comments are not visible by default, but can be accessed using the Edit tool on the Editing modes tool bar. Object names are set either by including a name attribute in the object comments or by creating a compound consisting of a text object with the desired name along with the selected object to receive the name. Using compounds to add names to objects allows the name to be visible on the drawn map as illustrated in Figure 4. Intersections are composed of boxes. Intersections of degree greater than four must be made by combinations of smaller intersections. Roads to and from the intersection must end inside of the intersections associated peripheral boxes, one road per peripheral box. Source nodes, which generate vehicles, are represented by triangles, and destination nodes, represented by circles, are vehicle sinks. Roads leading to or exiting from a source or sink must have one end within the source or destination object.

Trafix Input  Environment
Figure 4: Trafix Input Environment The Trafix input environment incorporates Xfig, an open source drawing package. Xfig allows user generated libraries of objects, which Trafix supplies. For Trafix, the current library consists of two, three, and four-way intersections, along with source and destination nodes. Roads consist of drawn lines. Object characteristics are included in the object comments. A road speed limit can be set by adding a speed attribute in the drawn road line comment. Xfig comments are not visible by default, but can be accessed using the Edit tool on the Editing modes tool bar. Object names are set either by including a name attribute in the object comments or by creating a compound consisting of a text object with the desired name along with the selected object to receive the name. Using compounds to add names to objects allows the name to be visible on the drawn map. Intersections of degree greater than four must be made by combinations of smaller intersections. Intersections are composed of boxes. Roads to and from the intersection must end inside of the intersections associated peripheral boxes, one road per peripheral box. Source nodes, which generate vehicles, are represented by triangles, and destination nodes, represented by circles, are vehicle sinks. Roads leading to or exiting from a source or sink must have one end within the source or destination object.


At the moment, Trafix runs the XFig network file named road_map.fig in its /data subdirectory. To run the xfig simulator, download the example and launch the application executable from its /bin directory. The network can be changed by renaming the example XFig file and creating a new file in the /data directory. Menus must be added to allow the user to select the desired XFig input file.