Getting Started with Agent-Based Modeling

min read

Key Takeaways

  • Agent-based modeling is a kind of applied computing that tackles questions asked by researchers across the university.
  • Simulation allows researchers to test theories that are difficult to observe in real life.
  • The most popular software for designing agent-based simulation is free, open source, and easy-to-learn for non-specialists.
  • This tutorial explains why adding agent-based modeling to the suite of software available to faculty and students benefits campus research and learning.

Michael Gavin is assistant professor, English Language and Literature, University of South Carolina.

One of the new computational techniques gaining traction across the social sciences is called "agent-based modeling." Much of its growth can be attributed to the popularization of a new free and open-source program, NetLogo,1 that researchers from various fields can use to develop simulations and share them with students. Agent-based modeling is surprisingly easy to learn, cheap to maintain, and can be used either in the classroom or for academic research. University administrators looking to develop the suite of tools they offer to students and faculty should consider adding software that runs these kinds of simulations, and NetLogo might be a good place to start.

What Is Agent-Based Modeling?

Agent-based modeling — sometimes called individual-based modeling — describes an applied computing technique. ABM creates a simulation in which a field of individual entities are programmed to behave in certain ways. When the simulation runs, researchers watch to see how those entities interact. In practical terms, you can almost think of ABM like a computer game that runs without anybody playing it. Imagine you're a geographer interested in how cities use local resources. You might test your theories by designing a simulation kind of like a Sims game, then running it thousands of times to see if your theories play out in your simulated world.

Computational experiments like these can be useful for testing whether theories are consistent with general patterns we see in the world, especially in situations where you can't test your ideas directly. (In the real world, you can't pollute forests just to see how it affects the water supply. In a computer-generated world, you can.) Simulations like these are used in a wide variety of fields: economics, biology, medicine, management, marketing, logistics, anthropology, political science, and computer science. You can even find people doing agent-based modeling in history and literature departments. This means there's a good chance you have several faculty at your institution working with agent-based simulations. If so, the odds are that they've never met each other.

  • Cutting across the sciences, arts, humanities, and engineering, simulation is one of the most important areas of interdisciplinary work happening at research universities today.

What Is NetLogo?

A number of user-friendly software systems are available for scholars who aren't computer programmers but want to incorporate agent-based simulations into their research. In their textbook Agent-based and Individual-Based Modeling: A Practical Introduction, Steven F. Railsback and Volker Grimm recommend NetLogo.2 NetLogo has a fairly intuitive graphical user interface and an easy-to-learn programming language based on Logo, which you might remember from elementary school. Logo was first designed in the 1960s and became popular in primary and secondary education because it was great for showing students how to think algorithmically. Like its ancestor, NetLogo creates sprites called "turtles" and moves them according to unit operations called "procedures." The turtles circulate in an open field of "patches" — small squares that can be assigned variables that change over time.

Figure 1 shows a screenshot of NetLogo with a single blue turtle. After creating the turtle in the center of the screen, I gave it three simple commands: move forward 5 spaces, turn right 90 degrees, then move forward five more spaces. This makes a simple right angle.

figure 1

Figure 1. One blue turtle programmed in NetLogo

Of course, you don't need to enter the commands one at a time. Setting on autopilot, I can tell the turtle to move and turn over and over again. With just a little randomization, I can make that one turtle generate a beautiful and intricate visual motion display (see the video). When you add in more turtles and just little more complex functionality, the displays can become even more intricate. In the second video, the turtles have been programmed to imprint their colors on their environment. The screen gradually transforms from brown to yellow, with patches of green that appear here and there.

One turtle produces a motion display (12 seconds).

Turtles color their environment (1:00 minute).

With a little imagination, it's not hard to see how to use this technique to simulate ecological and social systems. How do animals affect their surroundings? How do people sort into social groups? How do changes in population affect marriage rates? How will the floor plan of my retail business handle an increase of customers? All of these questions can now easily be tested in silico, using a computer system with graphics that look like they're straight out of the 1980s. (I don't know much about style, but I think NetLogo's retro-chic contributes at least a small part to its appeal.)

The Schelling Segregation Model

To get a sense of how agent-based modeling works, it helps to start with an example. Let me walk you through one of the most famous agent-based models ever made, one designed long before multiagent systems had developed as field of software design.

Economist Thomas C. Schelling was interested in how the basic concepts of microeconomics could be applied to a range of social problems, and, writing in the 1960s, he decided to tackle the problem of racial segregation.3 Segregation was a controversial topic at that time — and, even if the controversy has died down some, most public health specialists and social scientists would agree it remains a major problem today. But what causes racial segregation? Most people don't say they want to live in racially segregated neighborhoods, yet most people do. Why is that?

Schelling designed a simple game using a checkerboard graph. Two types of "chips" are distributed randomly across the board. Every turn, each chip looks at its neighbors. As long as two or three chips are its own color, the chip is happy and doesn't move. However, if the piece is surrounded by strangers (say, a red piece surrounded by blue pieces), it'll be unhappy and move. Schelling used this model to show how societies can develop tightly packed, segregated neighborhoods — not necessarily because people want to live separately, nor even because they want to be in the majority. They just don't want to feel isolated as the only member of their groups. This simple desire — which Schelling thought seemed natural and not closely analogous to racial prejudice — was in and of itself sufficient to explain social sorting.

NetLogo version of Schelling's segregation model (28 seconds).

Uri Wilensky, the designer of NetLogo, created a version of Schelling's model.4 A short video shows how the model works.

In the NetLogo model, the system is controlled by slider bars on the left side. One controls how many agents are in the system. The other, labeled "%-similar-wanted," controls how many same-colored neighbors each turtle wants to have. As you can see in the video, when the desire is set at 30%, each turtle is perfectly comfortable with being in the minority, as long as there's a critical mass of their own kind. Nonetheless, they quickly shuffle into groups and end up with neighbors that are over 70% similar to themselves. If the turtles just want distribution to be even (50-50), as the video shows, they sort into completely separate neighborhoods. Just wanting not to be the minority leads to total segregation.

Models like these are highly abstract. Schelling set aside a number of other questions for the purpose of his analysis. No mention is made, for example, of the role that real-estate agencies, mortgage brokers, and housing agencies played in the formation of neighborhoods. A great essay published recently in The Atlantic details the ways that lenders and real-estate speculators in Chicago profited from segregation.5 A NetLogo model like this could be expanded and adapted to tackle these kinds of issues — and that's exactly the sort of work now underway in universities across the country.

Spanning Disciplines

What's exciting about agent-based simulation — to me as a researcher — is the way it cuts across the disciplines. Models get people talking about how the world works, how we can understand problems, and how we can design solutions. It represents one of the newest and most promising areas of collaboration that bring together IT professionals, computer scientists, social scientists, and students.

Important Resources

NetLogo website (free download)

Agent-based and Individual-based Modeling: A Practical Introduction, by Steven S. Railsback and Volker Grimm (2011)

NetLogo online tutorials and dictionaries

Notes
  1. Uri Wilensky, NetLogo home page, Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL (1999).
  2. Steven S. Railsback and Volker Grimm, Agent-based and Individual-based Modeling: A Practical Introduction (Cambridge, MA: Princeton University Press, 2011).
  3. Thomas C. Schelling, "Dynamic Models of Segregation," Journal of Mathematical Sociology, Vol. 1 (1971), pp. 143–86.
  4. Uri Wilensky, NetLogo, Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL (1999). (Note: To access Wilensky's "Segregation Model," download NetLogo and select the model from the included "Model Library.")
  5. Ta-Nehisi Coates, "The Case for Reparations," The Atlantic, May 22, 2014.