Think Complexity SECOND EDITION Complexity Science and Computational Modeling Allen B Downey Think Complexity by Allen B Downey Copyright © 2018 Allen B Downey All rights reserved Printed in the United States of America Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O’Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://oreilly.com/safari) For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com Acquisitions Editor: Rachel Roumeliotis Developmental Editor: Michele Cronin Production Editor: Kristen Brown Copyeditor: Charles Roumeliotis Proofreader: Kim Cofer Indexer: Allen B Downey Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest March 2012: First Edition August 2018: Second Edition Revision History for the Second Edition 2018-07-11: First release See http://oreilly.com/catalog/errata.csp?isbn=9781492040200 for release details The O’Reilly logo is a registered trademark of O’Reilly Media, Inc Think Complexity, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work Use of the information and instructions contained in this work is at your own risk If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights Think Complexity is available under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License The author maintains an online version at http://greenteapress.com/wp/think-complexity-2e/ 978-1-492-04020-0 [LSI] Preface Complexity science is an interdisciplinary field—at the intersection of mathematics, computer science and natural science—that focuses on complex systems, which are systems with many interacting components One of the core tools of complexity science is discrete models, including networks and graphs, cellular automatons, and agent-based simulations These tools are useful in the natural and social sciences, and sometimes in arts and humanities For an overview of complexity science, see https://thinkcomplex.com/complex Why should you learn about complexity science? Here are a few reasons: Complexity science is useful, especially for explaining why natural and social systems behave the way they Since Newton, math-based physics has focused on systems with small numbers of components and simple interactions These models are effective for some applications, like celestial mechanics, and less useful for others, like economics Complexity science provides a diverse and adaptable modeling toolkit Many of the central results of complexity science are surprising; a recurring theme of this book is that simple models can produce complicated behavior, with the corollary that we can sometimes explain complicated behavior in the real world using simple models As I explain in Chapter 1, complexity science is at the center of a slow shift in the practice of science and a change in what we consider science to be Studying complexity science provides an opportunity to learn about diverse physical and social systems, to develop and apply programming skills, and to think about fundamental questions in the philosophy of science By reading this book and working on the exercises you will have a chance to explore topics and ideas you might not encounter otherwise, practice programming in Python, and learn more about data structures and algorithms Features of this book include: Technical details Most books about complexity science are written for a popular audience They leave out technical details, which is frustrating for people who can handle them This book presents the code, the math, and the explanations you need to understand how the models work Further reading Throughout the book, I include pointers to further reading, including original papers (most of which are available electronically) and related articles from Wikipedia and other sources Jupyter notebooks For each chapter I provide a Jupyter notebook that includes the code from the chapter, additional examples, and animations that let you see the models in action Exercises and solutions At the end of each chapter I suggest exercises you might want to work on, with solutions For most of the links in this book I use URL redirection This mechanism has the drawback of hiding the link destination, but it makes the URLs shorter and less obtrusive Also, and more importantly, it allows me to update the links without updating the book If you find a broken link, please let me know and I will change the redirection Who Is This Book For? The examples and supporting code for this book are in Python You should know core Python and be familiar with its object-oriented features, specifically using and defining classes If you are not already familiar with Python, you might want to start with Think Python, which is appropriate for people who have never programmed before If you have programming experience in another language, there are many good Python books to choose from, as well as online resources I use NumPy, SciPy, and NetworkX throughout the book If you are familiar with these libraries already, that’s great, but I will also explain them when they appear I assume that the reader knows some mathematics: I use logarithms in several places, and vectors in one example But that’s about it Changes from the First Edition For the second edition, I added two chapters, one on evolution, the other on the evolution of cooperation In the first edition, each chapter presented background on a topic and suggested experiments the reader could run For the second edition, I have done those experiments Each chapter presents the implementation and results as a worked example, then suggests additional experiments for the reader For the second edition, I replaced some of my own code with standard libraries like NumPy and NetworkX The result is more concise and more efficient, and it gives readers a chance to learn these libraries Also, the Jupyter notebooks are new For every chapter there are two notebooks: one contains the code from the chapter, explanatory text, and exercises; the other contains solutions to the exercises Finally, all supporting software has been updated to Python (but most of it runs unmodified in Python 2) Using the Code All code used in this book is available from a Git repository on GitHub: https://thinkcomplex.com/repo If you are not familiar with Git, it is a version control system that allows you to keep track of the files that make up a project A collection of files under Git’s control is called a “repository” GitHub is a hosting service that provides storage for Git repositories and a convenient web interface The GitHub home page for my repository provides several ways to work with the code: You can create a copy of my repository by pressing the Fork button in the upper right If you don’t already have a GitHub account, you’ll need to create one After forking, you’ll have your own repository on GitHub that you can use to keep track of code you write while working on this book Then you can clone the repo, which means that you copy the files to your computer Or you can clone my repository without forking; that is, you can make a copy of my repo on your computer You don’t need a GitHub account to this, but you won’t be able to write your changes back to GitHub If you don’t want to use Git at all, you can download the files in a ZIP file using the green button that says “Clone or download” I developed this book using Anaconda from Continuum Analytics, which is a free Python distribution that includes all the packages you’ll need to run the code (and lots more) I found Anaconda easy to install By default it does a user-level installation, not system-level, so you don’t need administrative privileges And it supports both Python and Python You can download Anaconda from https://continuum.io/downloads The repository includes both Python scripts and Jupyter notebooks If you have not used Jupyter before, you can read about it at https://jupyter.org There are three ways you can work with the Jupyter notebooks: Run Jupyter on your computer If you installed Anaconda, you can install Jupyter by running the following command in a terminal or Command Window: $ conda install jupyter Before you launch Jupyter, you should cd into the directory that contains the code: $ cd ThinkComplexity2/code And then start the Jupyter server: $ jupyter notebook When you start the server, it should launch your default web browser or create a new tab in an open browser window Then you can open and run the notebooks Run Jupyter on Binder Binder is a service that runs Jupyter in a virtual machine If you follow this link, https://thinkcomplex.com/binder, you should get a Jupyter home page with the notebooks for this book and the supporting data and scripts You can run the scripts and modify them to run your own code, but the virtual machine you run them in is temporary If you leave it idle, the virtual machine disappears along with any changes you made View notebooks on GitHub GitHub provides a view of the notebooks you can can use to read the notebooks and see the results I generated, but you won’t be able to modify or run the code Good luck, and have fun! Allen B Downey Professor of Computer Science Olin College of Engineering Needham, MA Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates emphasis, keystrokes, menu options, URLs, and email addresses Bold Used for new terms where they are defined Constant width Used for program listings, as well as within paragraphs to refer to filenames, file extensions, and program elements such as variable and function names, data types, statements, and keywords Constant width bold Shows commands or other text that should be typed literally by the user O’Reilly Safari Safari (formerly Safari Books Online) is a membership-based training and reference platform for enterprise, government, educators, and individuals Members have access to thousands of books, training videos, Learning Paths, interactive tutorials, and curated playlists from over 250 publishers, including O’Reilly Media, Harvard Business Review, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Adobe, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kaufmann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, and Course Technology, among others For more information, please visit http://oreilly.com/safari How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) To comment or ask technical questions about this book, send email to bookquestions@oreilly.com For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Contributor List If you have a suggestion or correction, please send email to downey@allendowney.com If I make a change based on your feedback, I will add you to the contributor list (unless you ask to be omitted) Let me know what version of the book you are working with, and what format If you include at least part of the sentence the error appears in, that makes it easy for me to search Page and section numbers are fine, too, but not quite as easy to work with Thanks! John Harley, Jeff Stanton, Colden Rouleau and Keerthik Omanakuttan are Computational Modeling students who pointed out typos Jose Oscar Mur-Miranda found several typos Phillip Loh, Corey Dolphin, Noam Rubin and Julian Ceipek found typos and made helpful suggestions Sebastian Schöner sent two pages of corrections! Philipp Marek sent a number of corrections Jason Woodard co-taught Complexity Science with me at Olin College, introduced me to NK models, and made many helpful suggestions and corrections instrumentalism, Different Models for Different Purposes, Instrumentalism interaction, Complexity Engineering island, Reaction-Diffusion isolation, Complexity Engineering itertools module, Implementing the Sand Pile J James, William, Emergence and Free Will Jupyter, Changes from the First Edition, Using the Code justification, Complexity Science K Kansas, Stanley Milgram Kauffman, Stuart, Simulating Evolution kernel, Implementing Life, Diffusion, Percolation Kosko, Bart, Complexity Thinking Kuhn, Thomas, Complexity Thinking, Exercises L lambda calculus, Universality Langton, Chris, Exercises Langton’s Ant, Exercises Laplace, Pierre-Simon, Determinism Laplace’s Demon, Determinism Life class, Exercises LifeViewer class, Exercises linear, The Axes of Scientific Models linear congruential generator, Randomness linear time, Analysis of Graph Algorithms linregress, Fractals linspace, Traffic Jams list comprehension, Probability of Connectivity, Social Network Data, Phase Change The Little Book of Semaphores, Dijkstra’s Algorithm loadtext, Social Network Data local connection, Stanley Milgram local information, Boids log-log axis, Heavy-Tailed Distributions log-log scale, Fractals, Exercises logarithm, Probability of Connectivity, Heavy-Tailed Distributions, Cumulative Distributions, Pink Noise logic, Complexity Thinking lognormal distribution, Wealth Inequality logspace, The WS Experiment long tail, Critical Systems M magnitude, The Boid Algorithm, The Boid Algorithm Mandelbrot, Benoit, Exercises maneuverability, Arbitration many-valued logic, Complexity Thinking Massachusetts, Stanley Milgram mathematical proof, What Kind of Explanation Is That?, Explanatory Models mathematics, What Is This a Model Of? McGrayne, Sharon Bertsch, Complexity Thinking mean, Probability of Connectivity, The WS Experiment, Phase Change, The Boid Algorithm, Results melee, The Tournament meme, Reductionism and Holism Methuselah, Conway’s Conjecture migration, Migration and Wave Behavior Milgram, Stanley, Stanley Milgram minimum, Implementing Sugarscape model, Complexity Thinking, Explanatory Models modeling, Complexity Science modulus operator, Implementing CAs Moore neighborhood, Conway’s GoL morphogenesis, Diffusion movie actor data, Barabási-Albert Model mushroom, Instrumentalism mutation, Mutation N NaN, Clustering, Implementation of Schelling’s Model nanmean, Clustering, Segregation, Evidence of Evolution natural law, Complexity Science, Emergence neighbor node, Connected Graphs neighborhood, Wolfram’s Experiment, Conway’s GoL, Implementing Life, Percolation, Schelling’s Model network average clustering coefficient, Clustering NetworkX, Who Is This Book For?, NetworkX, Breadth-First Search, Social Network Data, Barabási-Albert Model, Generating BA Graphs A New Kind of Science, Randomness, Universality, Emergence Newtonian mechanics, Determinism node, What Is a Graph?, NetworkX noise, Pink Noise, Random Perturbation nondeterministic, A Simple CA nonlinear, The Axes of Scientific Models nonzero, Implementation of Schelling’s Model, No Differentiation normal accident theory, SOC, Causation, and Prediction normal distribution, Wealth Inequality Not a Number, Clustering, Implementation of Schelling’s Model NumPy, Who Is This Book For?, Generating ER Graphs, Probability of Connectivity, WS Graphs, Clustering, The WS Experiment, Social Network Data, Social Network Data, Implementing CAs, Cross-Correlation, CA Tables, Exercises, Implementing Life, Implementing Life, Reaction-Diffusion, Percolation, Phase Change, Implementing the Sand Pile, Heavy-Tailed Distributions, Fractals, Implementation of Schelling’s Model, Implementation of Schelling’s Model, Segregation, Implementing Sugarscape, Traffic Jams, The Boid Algorithm, Fitness Landscape, No Differentiation, Evidence of Evolution, Differential Survival, Mutation, Simulating Evolution of Cooperation, The Tournament, Results O objective, Complexity Thinking objectivity, Exercises observable, Explanatory Models one, two, many, The Axes of Scientific Models ones, Reaction-Diffusion orbit, What Kind of Explanation Is That? order of growth, Analysis of Graph Algorithms, Exercises oscillator, Life Patterns P pad, Exercises parameter, Watts and Strogatz, Exercises parity, Implementing CAs path, What Is a Graph?, Connected Graphs path length, Watts and Strogatz, Shortest Path Lengths peer-to-peer architecture, Complexity Engineering percolating cluster, Percolation percolation, Physical Modeling, Percolation, Fractals and Percolation Models performance error, Exercises period, Randomness, Exercises permutation, Implementing Sugarscape Perrow, Charles, SOC, Causation, and Prediction perturbation, Sand Piles Pew Research Center, Evolution phase change, Phase Change phenotype, Fitness Landscape physical law, Complexity Thinking physical model, What Is This a Model Of? pink noise, Self-Organized Criticality, Critical Systems, Pink Noise planetary motion, Complexity Science, What Kind of Explanation Is That? Pmf, Heavy-Tailed Distributions PMF object, Degree pop, Breadth-First Search Popper, Karl, Falsifiability, Exercises population pressure, Exercises postulated entity, Realism power, Pink Noise power law, Heavy-Tailed Distributions, Critical Systems, Heavy-Tailed Distributions power spectrum, Pink Noise prediction, Falsifiability, SOC, Causation, and Prediction predictive model, Different Models for Different Purposes preferential attachment, Barabási-Albert Model, Explanatory Models prevalence, Reductionism and Holism principle of computational equivalence, Universality Prisoner’s Dilemma, Prisoner’s Dilemma PRNG, Randomness probability mass function, Degree probability of connectivity, Probability of Connectivity problem of altruism, The Problem of Nice proof, Complexity Science, The Changing Criteria of Science, What Kind of Explanation Is That?, Explanatory Models proof by induction, Dijkstra’s Algorithm proximate cause, SOC, Causation, and Prediction pseudo-random number generator, Randomness pseudoscience, The Changing Criteria of Science puffer train, Conway’s Conjecture, Implementing Life pyplot module, Implementing CAs Python, Who Is This Book For? Q quadratic, Analysis of Graph Algorithms quantum mechanics, Determinism queue, Breadth-First Search R r-pentomino, Conway’s Conjecture racism, Complexity Science, Schelling’s Model radioactive decay, Determinism randint, Implementing Life, Implementing the Sand Pile, Implementation of Schelling’s Model random, WS Graphs, Social Network Data, Implementing Life, Reaction-Diffusion, Percolation, Implementing the Sand Pile, Implementation of Schelling’s Model, Implementation of Schelling’s Model, Implementing Sugarscape, Traffic Jams, Fitness Landscape, No Differentiation, Differential Survival, Mutation, Simulating Evolution of Cooperation random edge, Random Graphs random graph, Random Graphs, Watts and Strogatz random module, Exercises random walk, Phase Change randomness, Randomness rational, Prisoner’s Dilemma rational agent model, The Problem of Nice reachable node, Connected Graphs reaction-diffusion, Reaction-Diffusion reactive, Exercises read-write head, Universality, Exercises realism, Different Models for Different Purposes, Realism realistic model, What Is This a Model Of? red noise, Pink Noise reductionism, Different Models for Different Purposes, Reductionism and Holism, Exercises register, Universality regular graph, Watts and Strogatz, Ring Lattice Rényi, Afréd, Random Graphs replicator, Reductionism and Holism, Summary repository, Using the Code representing graphs, What Is a Graph? reproduction, Evolution, Simulating Evolution Resnick, Mitchell, Traffic Jams retaliation, Results rewire, Watts and Strogatz, WS Graphs Reynolds, Craig, Boids rich get richer, Barabási-Albert Model ring lattice, Ring Lattice, Exercises road network, What Is a Graph? robust, Exercises rule, A Simple CA Rule 110, Spaceships, Exercises, Migration and Wave Behavior Rule 18, Classifying CAs, Fractals Rule 20, Fractals Rule 30, Randomness, Exercises Rule 50, Wolfram’s Experiment, Fractals rule table, Wolfram’s Experiment S sampling frequency, The Sound of Sand sand pile model, Sand Piles, Pink Noise, Reductionism and Holism SandPile, Implementing the Sand Pile scale-free network, Barabási-Albert Model scaling, Fractals Schelling, Thomas, Complexity Science, Schelling’s Model Schelling’s model, Emergence scientific realism, Realism SciPy, Who Is This Book For?, Implementing Life, Fractals, The Sound of Sand, Implementation of Schelling’s Model search, Complexity Engineering Searle, John, Exercises segregation, Complexity Science, Complexity Science, Schelling’s Model, Segregation, Exercises self-organized criticality, Self-Organized Criticality, Reductionism and Holism, Exercises self-similarity, Critical Systems The Selfish Gene, Reductionism and Holism set, Connected Graphs Sharon, Massachusetts, Stanley Milgram shortcut, Emergence shortest path, Shortest Path Lengths, Dijkstra’s Algorithm shuffle, Implementing Sugarscape Sierpiński triangle, Classifying CAs signal, Pink Noise simple rules, Determinism, Exercises simplification, Complexity Science simulation, Evolution, Simulation, The Simulation simulation-based model, What Kind of Explanation Is That? single source sand pile, Exercises single source shortest path, Dijkstra’s Algorithm six degrees, Stanley Milgram, Explanatory Models slice, Reaction-Diffusion slice operator, Implementing CAs small world experiment, Stanley Milgram small world network, Watts and Strogatz small world phenomenon, Exercises small world property, Barabási-Albert Model SNAP, Social Network Data SOC, Self-Organized Criticality, Critical Systems, Reductionism and Holism, Exercises social network, What Is a Graph?, Stanley Milgram social psychology, The Problem of Nice space, Herds, Flocks, and Traffic Jams spaceship, Spaceships, Exercises, Life Patterns, Migration and Wave Behavior special creation, Falsifiability speciation, Speciation, Speciation spherical cow, The Axes of Scientific Models stack, Connected Graphs, Breadth-First Search state, A Simple CA, Wolfram’s Experiment, Sand Piles stationary, Wealth Inequality stochastic, The Axes of Scientific Models stock market, SOC, Causation, and Prediction strategy, Simulating Evolution of Cooperation Strogatz, Steven, The Changing Criteria of Science, Watts and Strogatz strong AI, Exercises The Structure of Scientific Revolutions, Complexity Thinking subjective, Complexity Thinking sufficiency theorem, Summary Sugarscape, Sugarscape, Implementing Sugarscape Superego, Instrumentalism survival, Evolution, Simulating Evolution Sync, The Changing Criteria of Science synchronization, The Changing Criteria of Science system, Explanatory Models system reply, Exercises T tape, Universality tautology, Universality TFT, Prisoner’s Dilemma Tournaments, Simulating Evolution of Cooperation theory, Complexity Thinking, Realism theory choice, Exercises theory of evolution, Evolution The Theory That Would Not Die, Complexity Thinking thinkplot module, Degree, Cumulative Distributions thinkstats2 module, Heavy-Tailed Distributions time step, A Simple CA tit for tat, Prisoner’s Dilemma Tournaments toad, Life Patterns top-down, Complexity Engineering toppling threshold, Implementing the Sand Pile tournament, Prisoner’s Dilemma Tournaments, The Tournament traffic jam, Traffic Jams transpose, Heavy-Tailed Distributions, Fractals triangle of influence, Wolfram’s Experiment tuple, Implementation of Schelling’s Model Turing complete, Spaceships, Game of Life, Conway’s GoL, Conway’s Conjecture Turing machine, Universality, Exercises, Exercises Turing, Alan, Universality, Exercises, Diffusion turmite, Exercises Turtles, Termites and Traffic Jams, Traffic Jams U uint8, Implementing CAs, Implementing Life ultimate cause, SOC, Causation, and Prediction unbounded, Conway’s GoL uncertainty, Complexity Thinking undirected graph, What Is a Graph? uniform, Traffic Jams universal, Game of Life, Conway’s GoL universal common descent, Falsifiability universal gravitation, What Kind of Explanation Is That? universality, Spaceships, Universality, Conway’s Conjecture unpackbits, CA Tables unstable, Critical Systems V variability, Summary Vector, Boids velocity, The Boid Algorithm vertex, What Is a Graph? VPython, Boids vstack, Implementing Sugarscape W Watts, Duncan, Watts and Strogatz Watts-Strogatz graph, WS Graphs, Social Network Data, WS Model wave, Migration and Wave Behavior weak ties, Explanatory Models, Exercises wealth, Sugarscape weight, What Is a Graph? weighted sum, Arbitration Welch’s method, The Sound of Sand where, Implementation of Schelling’s Model, Fitness Landscape white noise, Pink Noise Wichita, Kansas, Stanley Milgram window, Cross-Correlation, Implementing Life Wolfram, Stephen, Cellular Automatons, Emergence WS model, Cumulative Distributions X xenophobia, Complexity Science, Schelling’s Model XOR, Mutation, Speciation Z zeros, Implementing CAs zip, Generating BA Graphs, Implementation of Schelling’s Model, Simulating Evolution of Cooperation About the Author Allen B Downey is a professor of Computer Science at Olin College and the author of a series of free, open-source textbooks related to software and data science, including Think Python, Think Bayes, and Think Complexity, published by O’Reilly Media His blog, Probably Overthinking It, features articles on Bayesian probability and statistics He holds a Ph.D in computer science from U.C Berkeley, and M.S and B.S degrees from MIT He lives near Boston, MA with his wife and two daughters Colophon The animal on the cover of Think Complexity is a black eagle (Ictinaetus malayensis), the only species in its genus They are found in tropical Asia, namely parts of Burma, India, southern China, Taiwan, and the Malay peninsula These eagles prefer wooded mountainous terrain, roosting and building large nests (3 to feet wide) high in the trees These birds have black plumage (as their common name states; though juvenile eagles are dark brown), yellow feet, and a short curved beak Black eagles are large birds averaging to feet long, with a massive wingspan of feet In flight, the eagles are distinctive not only for their color and size, but the slow gliding pace at which they move above the canopy Breeding season occurs sometime between November and May (depending on latitude) The eagles carry out aerial displays of a steep dive followed by an ascent, all at high speed Mating pairs will also chase each other among the trees They typically only lay one or two eggs at a time The diet of the black eagle is made up of small mammals (which they will capture from the ground), as well as smaller birds and eggs In fact, black eagles are voracious nest predators, and have a unique hunting habit—picking up an entire nest of prey and carrying the eggs or nestlings away to its own perch to eat later Because the black eagle’s talons are less sharply curved than other birds of prey, it is easier for them to accomplish this Many of the animals on O’Reilly covers are endangered; all of them are important to the world To learn more about how you can help, go to animals.oreilly.com The cover image is from Meyers Klein Lexicon The cover fonts are URW Typewriter and Guardian Sans The text font is Adobe Minion Pro; the heading font is Adobe Myriad Condensed; and the code font is Dalton Maag’s Ubuntu Mono .. .Think Complexity SECOND EDITION Complexity Science and Computational Modeling Allen B Downey Think Complexity by Allen B Downey Copyright © 2018... sometimes in arts and humanities For an overview of complexity science, see https://thinkcomplex.com/complex Why should you learn about complexity science? Here are a few reasons: Complexity science is... tools of complexity science is discrete models, including networks and graphs, cellular automatons, and agent-based simulations These tools are useful in the natural and social sciences, and sometimes