Francesca De Min, Aurora Patetta

Computer Science and Simulation for Economics

Project work on

"Traffic dynamics."


The applet requires Java 1.4.1 or higher. It will not run on Windows 95 or Mac OS 8 or 9. Mac users must have OS X 10.2.6 or higher and use a browser that supports Java 1.4. (Safari works, IE does not. Mac OS X comes with Safari. Open Safari and set it as your default web browser under Safari/Preferences/General.) On other operating systems, you may obtain the latest Java plugin from Sun's Java site.

created with NetLogo

view/download model file: traffic_dynamics.nlogo


The model reproduces traffic dynamics in a urban context in order to show interactions between three kinds of agents: buses, cars and people.
Our simulation has the objective to test some scenarios depending on the time-band chosen and on the traffic evolution when we vary global variables like acceleration and deceleration
From the economic point of view the model computes the long-period marginal costs beared by the Transport Society.
Moreover we compare average time spent for a journey using public or private transport and we look to the dynamic of changes in choices assigning them two meanings: on the one hand they represent the advantage gained by the Transport Society, increased every time a person chooses to travel by bus; on the other hand it shows benefits for pollution and the whole social context.


We create a very simple route and we fix up 4 descent bus-stops and 4 ascent bus-stops with different colors (blue and red patches) where the buses stop.
Another agent, belonging to the car breed, runs along the same road.
To avoid crashes agents' speed changes if they see someone ahead.
Moreover we added these instructions: cars can't overtake each other, while they can overtake buses (unless they're in a bus-stop patch and there are already two or more buses in).
Every time a bus or a car completes its journey we compute their time (but only the average ones are plotted in a graph).
The third breed, created near the ascent bus-stop patches, represents people, who can choose whether to take the bus or not (in that case they will use the car, so the model transforms them into cars), comparing journey times.
Initially we put on the road only one bus and a random number of white cars (that depends on the time-band) which represents people who always use the car. In the first run all the people created near the bus stop patches will take the bus, and, at the end of the journey, they see whether it will be convenient to continue travelling by bus or not for the next run, comparing travelling times. If the bus is "too slow" passengers will choose private transport, and they will be transformed into cars (with green color to distinguish them from the previous ones). In order to represent in the world also those people who will always take the bus (for example they don't have the driving licence or the cost of travelling by car is not affordable for them) we add to the buses an internal variable (nd_people, non-dynamic people).
The problem is simplified in this way:
the passenger gets off the bus after that he has made a complete journey in the same patch (bus-stop) where he got on;
people who get on the bus don't change their shape but color (they become white) and position: when the bus comes again in the red patch passengers know if another journey with bus is convenient or not, and so change their features: if they decide to take the bus again they change color into blue; otherwise they become a car.
If otherwise in the previous travel people used the car, if this has been a good choice they continue to be a car; or else, they will use public transport for the next run and so they become people (and their color is violet).
In each moment we can know how many people are waiting for the bus and how many are on the bus.
By the interaction between the three kinds of agents we can study if the traffic dynamic will reach or not an equilibrium.


Start the simulation by clicking "setup".
Then, after clicking "go", cars and the bus start running on the road and interact with people who are waiting for the bus in the four bus-stops.


i) "setup": it resets the world. A new simulation can be started and new parameters can be chosen by the user. [quick choice: "S"]

ii) "go": simulation starts and continues until the observer decides to stop it, by pressing a second time this button. Notice that this is a perpetuous command. [quick choice: "G"]


i) "speed_up": it is useful to modify cars and buses speed (it goes from 20 to 99) and it is related to acceleration;

ii) "slow_down": it has the same use of the previous slider, but related to deceleration;

iii) "marginal_cost": it is useful to modify the value of the marginal costs beared by the Transport Society every time a new bus is created and starts running (it goes from 5 to 20).


i) "time_band": the observer can choose among three time bands: ordinary, low and high. By the choice depends the amount of cars, people and consequently buses added in the model;

ii) "capacity": the observer can choose among 3 different values for the capacity of the bus (40, 70 and 120);

iii) "look-ahead": this chooser controls the distance that drivers look ahead (in deciding whether to slow down or speed up)


i) "number of buses": it shows how many buses are running on the street;

ii) "people on bus": it shows how many people are travelling by bus in that moment;

iii) "waiting people": it shows how many people (with the internal variable "on-bus" = 0) are waiting for the bus;

vi) "dynamic agents": it shows how many people and green cars are in the world. This value, once we have setup the world, stays the same;

v) "total cars": it shows how many cars are running in the simulation, and we compute it by the sum of white and green cars;

vi) "green cars": it shows how many green cars are there (green cars represent people who choose private transport instead of travelling by bus);

vii) "average speed cars": it shows the average speed of cars, and it is computed as the mean of cars speeds running in the model;

viii) "average speed buses": it has the same function of the previous monitor, but related to buses;

ix) "average time cars": it shows the average time spent by cars to make a complete journey;

x) "average time buses": like the previous one, but referred to buses;

xi) "long period marginal cost": it shows the total marginal cost beared by the Transport Society in the long run, which is referred to the cost of adding a new bus on the road;

xii) "choice_dynamics": it shows how the dynamic of choices (and changes) between using the public and the private transport behave.


i) "Average Speed": it shows the dynamic of average speed of the two different means of transport, buses and cars;

ii) "Average Time": it shows the dynamic of average time to make a journey of the two agents, buses and cars;

iii) "LP marginal cost": it shows the dynamic of total marginal costs; we can notice that the graph has an ascent scalar trend every time a bus is added.

iv) "choice_dynamics": this linear graph represents the evolution of choices dynamic. We can notice that it can take both positive and negative values.


What can we notice about traffic dynamics? Is it generally true that, depending on the time band chosen, the more cars are in the model, the more the traffic is congested?
We can see that this is true, because the higher is the number of people who are waiting for the bus and the higher is the number of cars on the street, the more the traffic is engorged, so the average time of buses and cars will be increased and the the average speed will be reduced.
In particular, for the next run bus passengers will choose the car, so we will have a higher number of green cars added on the street. This fact will bring to change the choice again because the street will be too full of cars, so the advantage of using the private transport will be wasted.
This effect is highlighted mainly if we choose the high time band, where the number of people and cars is bigger, so the traffic will be congested more rapidly and also more buses will be put on the street.


The observer could find interesting to modify the value of the sliders and choosers, relating to:
- the time band;
- the buses capacity;
- speed-up and slow-down;
- the unit marginal cost.
Moreover the slider "look ahead" has only a tecnical function since it gives to the observer the possibility of choosing the distance that drivers look ahead (in deciding whether to slow down or speed up).


In order to have a more complete economical cost/benefits analysis for the Transport Society we could extend the model by adding a toll that passengers have to pay when they get on the bus, and also the costs beared by the Society given by the oil consumption and bus drivers' salary.
Moreover, we could add some stoplights on the street so as to make the urban model more similar to the real world.


The simulation is inspired to:
- "Traffic Basic"
- "Traffic 2 Lanes"
- "Traffic Grid"
- "Traffic Intersection"
taken from NetLogo Models Library;
and to:
- "Public Investment Benefit"
taken from the "Students' Project Works" created for the course of Computer Science, Simulation and Economics by Professor Pietro Terna.