UserPreferences

UsingNetLogo


This page is a how-to introduction to [WWW]Netlogo, a free software tool for implementing cellular automata and agent-based models.
ConcreteNetLogoForAbstractThinkers

1. Netlogo basics

  1. Netlogo is a tool for implementing simple agent-based simulations and cellular automata. You define the actors and the rules governing their behavior and interactions, and let Netlogo show you the consequences when those actors follow those rules over and over again.

  2. You define agents by defining...

    1. ...their number and kinds.

    2. ...what variables are associated with them.

    3. ...their appearance in the interface.

    4. ...their behavior, including...

      1. ...their creation (incl. initial attributes) and destruction.

      2. ...their effects on other agents.

      3. ...when and how their attributes change.

  3. You create the interface by defining...

    1. ...buttons, sliders, monitors, plots.

    2. ...the number of cells defining the two-dimensional recteangular space.

2. Language basics

  1. Languages are easily learned by example. Look at these NetLogoExamples.

  2. Agents.

    1. Patches: stationary, the main actors in CAs.

    2. Turtles: mobile, important if you need dynamic or nonlocal interaction.

    3. Agent-specific variables, different among individuals: use patches-own and turtles-own

    4. Breeds: you can define turtles with different variables and behavior, and name them as different "breeds."

    5. Patches and agents are treated similarly, but there are slight vocabulary differences. For one thing, built-in patch variables' names begin with p.

  3. Buttons, sliders, switches: allow user to invoke procedures (buttons), set numerical variables (sliders), set booleans (switches).

    1. Define and position these elements under the Interface tab.

    2. It's a good idea to do the interface early, as a way of thinking through the structure of the model.

  4. Procedures.

    1. Allow programs to be as modular as you want

    2. Order doesn't matter.

  5. Tasks

    1. Use ask agentset [tasks]

  6. Assignment

    1. set variable value

    2. Value can be literal, another variable, or reporter.

  7. Flow control

    1. if TEST [TASKS]

    2. ifelse TEST [TASKS-IF-TRUE][TASKS-IF-FALSE]

    3. while [TEST][TASKS]

  8. Agentsets

    1. with -- narrow agentset to agents that satisfy a T/F test

    2. patch-at and turtles-at -- specify patch or turtle at some location defined relative to current agent

    3. neighbors and neighbors4 -- agentset consisting of 8 or 4 nearest neighbors

3. Example: Parity CA

  1. Cell states: on/off (1/0).

  2. Transition rule:

    1. 4 von Neumann neighbors

    2. Odd number on --> on B. Even number on --> off

  3. Want step-by-step instructions? Try BuildingTheParityModelInNetLogo.

4. Example: Spatial Prisonner's Dilemma

  1. Can spatiality lead to the evolution of cooperation?

  2. Cell states: defect (0), cooperate (1).

  3. Payoffs

    1. Focal 0, neighbor 0 --> 0

    2. Focal 1, neighbor 1 --> 1

    3. Focal 1, neighbor 0 --> 0

    4. Focal 0, neighbor 1 --> p, where p > 1

    5. Total payoff is total of eight interactions with neighbors, plus with self.

  4. Transition: Focal takes strategy of neighbor (eight plus self) with highest payoff.

  5. Color code.

  6. You'll need this:

 ask patches [
        if max values-from neighbors[payoff] > payoff [
            set next-strategy (current-strategy-of max-one-of neighbors[payoff])
        ]
 ]

5. Strategies

  1. Design first, and refine as you go.

  2. Synchronization.

    1. Use blocks to synchronize.

    2. Use new-X variables to prevent mixing old and new states.

  3. Debugging.

    1. Use show to see values in Command window.

    2. if statements get parentheses, with and while get square brackets.

    3. Use indentation and comments to organize your code.

6. Example programs