NetLogo banner

Home
Download
Help
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo Models Library:
IABM Textbook/chapter 5

(back to the library)

Traffic Basic Adaptive

[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web

ACKNOWLEDGMENT

This model is from Chapter Five of the book "Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo", by Uri Wilensky & William Rand.

  • Wilensky, U. & Rand, W. (2015). Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo. Cambridge, MA. MIT Press.

This model is in the IABM Textbook folder of the NetLogo Models Library. The model, as well as any updates to the model, can also be found on the textbook website: http://www.intro-to-abm.com/.

WHAT IS IT?

This model models the movement of cars on a highway. Each car follows a simple set of rules: it slows down (decelerates) if it sees a car close ahead, and speeds up (accelerates) if it doesn't see a car ahead. The model extends the Traffic Basic model, from the social science section of the NetLogo models library, by having cars adapt their acceleration to try and maintain a smooth flow of traffic.

An agent that can change its strategy based on prior experience is an adaptive agent. Unlike conventional agents, which will always do the same thing when presented with the same circumstances, adaptive agents can make different decisions if given the same set of inputs. In the Traffic Basic model, cars do not always take the same action; they operate differently based on the cars around them by either slowing down or speeding up. However, regardless of what has happened to the cars in the past (i.e., whether they got stuck in traffic jams or not) they will continue to take the same actions in the same conditions in the future. To be truly adaptive, agents need to be able to change not only their actions in time, but also their strategies. They must be able to change how they act because they have encountered a similar situation in the past and can react differently this time based on their past experience. In other words, the agents learn from their past experience and change their behavior in the future to account for this learning.

In this model, cars use the best acceleration they have found so far unless they are in a tick where they are exploring a new acceleration value, as specified by ticks-between-tests. Over time, the cars keep a weighted average of the speed they are able to maintain at the best acceleration; if the new acceleration allows for a faster speed, the cars will then switch to using that new acceleration. This average for the best acceleration weighs the past historical speeds higher (0.9) than the present speed (0.1), accounting for the fact that you can occasionally get spurious results (noise). Thus, it is better to rely on a large amount of data than one particular data point. However, the code still allows the best acceleration to change, which means even if the environment were to change (e.g., more cars on the road, longer road, etc.) the car could adapt to the new situation.

HOW TO USE IT

Click on the SETUP button to set up the cars.

Set the NUMBER-OF-CARS slider to change the number of cars on the road.

Click on GO to start the cars moving. Note that they wrap around the world as they move, so the road is like a continuous loop.

The INIT-ACCELERATION slider controls the rate at which cars initially accelerate (speed up) when there are no cars ahead.

When a car sees another car right in front, it matches that car's speed and then slows down a bit more. How much slower it goes than the car in front of it is controlled by the DECELERATION slider.

Click on ADAPTIVE-GO to see how the results change when the cars are adapting to the environment around them, by changing their acceleration.

ADAPTIVE-GO employs the TICKS-BETWEEN-TESTS slider. This slider controls how frequently the model tests to see if it has found a better acceleration.

There are five monitors:

  • BEST ACCELERATION displays the acceleration that the model believes leads to the fastest moving traffic. This is only used in ADAPTIVE-GO mode.

  • CURRENT ACCELERATION displays the current value of the cars' acceleration. This only changes when in ADAPTIVE-GO mode.

  • RED CAR SPEED displays the speed of one randomly selected car, which is colored red.

  • AVG SPEED displays the average speed of the cars.

  • SPEED-TO-BEAT displays the speed that AVG SPEED needs to beat when a test occurs for the model to think its found a better acceleration. This is only used in ADAPTIVE-GO mode.

The CAR SPEEDS plot plots the minimum, maximum and average speed of the cars. If the PLOT-RED-CAR? switch is on, it also plots the speed of the red car.

The SPEED TO BEAT VS AVG SPEED plot compares the average speed of the cars to the speed to beat over time. This is only used in ADAPTIVE-GO mode.

THINGS TO NOTICE

Traffic Basic explored how traffic jams can start from small disturbances. The goal of Traffic Basic Adaptive is to examine how this changes when the cars are actively trying to avoid traffic jams. Does the behavior of the cars and jams visibly change when they are adapting? Is there a difference in the plot of the fastest, slowest, average and red cars, compared to the Traffic Basic model plot?

In Traffic Basic changing the Acceleration and Deceleration could affect the model dramatically. What role does the INIT-ACCELERATION slider in this model play versus the ACCELERATION slider in the original model? Does it affect the results as much? How about the DECELERATION slider? Has its effect changed?

THINGS TO TRY

The purpose of the TICKS-BETWEEN-TESTS slider is to allow the speed to stabilize between changes to acceleration. What happens if you set TICKS-BETWEEN-TESTS to 1, thereby not giving the speed a chance to stabilize?

Can you find a better value for TICKS-BETWEEN-TESTS than the default value for the model? A good way to do that would be to design a BehaviorSpace experiment that tries many possible values of TICKS-BETWEEN-TESTS and checks how long it takes (if ever) for the cars to reach an average speed of 1.0. You would need to have multiple repetitions for each value, however, because the randomness in the model can lead to different results from one run to another.

EXTENDING THE MODEL

In this version of the model, the acceleration is the same for all agents, and agents are trying to maximize the average speed of all cars. Without looking at the "Traffic Basic Adaptive Individuals" model, can you modify the model so all cars have their own acceleration and are trying to maximize their individual speed?

In the adaptive-go procedure, we compare the speed-to-beat with the mean [ speed ] of turtles. That gives us the mean speed at the current tick, but what if we looked instead at the mean speed for all ticks since the previous test? Would that help the cars achieve faster speed?

NETLOGO FEATURES

The behavior of the CAR SPEEDS plot is conditional on the value of the PLOT-RED-CAR? switch. This is achieved by using a simple if-condition in the update commands of the "red car" plot pen:

if plot-red-car? [ plotxy ticks [ speed ] of sample-car ]

Notice the use of plotxy ticks ... instead of just plot .... Since the plot pen may not be updated right from the start, we need to make sure we plot the right x value, namely ticks.

RELATED MODELS

  • "Traffic Basic": a simple model of the movement of cars on a highway.

  • "Traffic Basic Utility": a version of "Traffic Basic" including a utility function for the cars.

  • "Traffic Basic Adaptive Individuals": a version of "Traffic Basic Adaptive" where each car adapts individually, instead of all cars adapting in unison.

  • "Traffic 2 Lanes": a more sophisticated two-lane version of the "Traffic Basic" model.

  • "Traffic Intersection": a model of cars traveling through a single intersection.

  • "Traffic Grid": a model of traffic moving in a city grid, with stoplights at the intersections.

  • "Traffic Grid Goal": a version of "Traffic Grid" where the cars have goals, namely to drive to and from work.

  • "Gridlock HubNet": a version of "Traffic Grid" where students control traffic lights in real-time.

  • "Gridlock Alternate HubNet": a version of "Gridlock HubNet" where students can enter NetLogo code to plot custom metrics.

The traffic models from chapter 5 of the IABM textbook demonstrate different types of cognitive agents: "Traffic Basic Utility" demonstrates utility-based agents, "Traffic Grid Goal" demonstrates goal-based agents, and "Traffic Basic Adaptive" and "Traffic Basic Adaptive Individuals" demonstrate adaptive agents.

HOW TO CITE

This model is part of the textbook, “Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo.”

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:

Please cite the textbook as:

  • Wilensky, U. & Rand, W. (2015). Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo. Cambridge, MA. MIT Press.

COPYRIGHT AND LICENSE

Copyright 2008 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

(back to the NetLogo Models Library)