1 of 43

NetLogo Workshop Series� �Week 1�Session 1 – NetLogo: Getting Started

Jiin Jung, LU Psychology - jiin.jung@lehigh.edu�

2 of 43

Objectives

  • The History of NetLogo
  • Download NetLogo
  • Know useful resources

3 of 43

Toolkits for ABM

  • Computer language you already know
    • Python
    • Java
  • Or use ABM specific platforms
    • NETLOGO
    • MASON
    • REPAST
    • SWARM
    • ASCAPE
    • ABLE

4 of 43

NetLogo

  • An agent-based modeling language
  • Developed by Uri Wilensky at Northwestern University
  • Most widely used ABM language
  • Super easy to learn

5 of 43

The Logo Turtle

6 of 43

Logo

  • Seymour Papert developed this to teach children how to think from a computational perspective.
  • The Turtle is seen as a metaphor, an "object-to-think-with" (Papert 1980:p. 12).
  • Logo at the time was not yet a multi-agents system
  • A turtle was physical.
  • Then, a virtual turtle was developed within Logo.�

7 of 43

The Logo Turtle

  • The first turtle built was “the yellow turtle”, a tri-cycle moveable robot with a pen (1969).
  • It was connected to the computer via hardwire lines
  • It is controlled by Logo
  • Build at MIT AI Lab by Tom Callahan, Marvin Minsky, and Seymour Papert

8 of 43

The Logo Turtle

  • The first wireless turtle, “Irving” (1972)
  • Children can control Irving.

9 of 43

Let’s Download NetLogo

  • https://www.netlogo.org/
  • Choose the latest version
  • Download and Install

10 of 43

Running NetLogo

  • Run > Programs > NetLogo
  • Or double click on the NetLogo icon if you’ve installed a desktop icon.
  • As NetLogo is coming up, a brief splash bar display should appear looking like this:

11 of 43

The main NetLogo window should come up looking like this:

12 of 43

Let’s create a turtle!

Type codes in Command Center

  • create-turtles 1
  • ask turtles [set size 4]
  • ask turtles [set shape "turtle"]
  • ask turtles [set color brown]
  • ask turtles [forward 10]
  • ask turtles [right 80]
  • ask turtles [forward 15]
  • ask turtles [repeat 5 [fd 10 right 45]]
  • ask turtles [pen-down]
  • ask turtles [fd 10 rt 45]
  • clear-all

13 of 43

Create

buttons

Write codes

Now, programming the actions of a turtle!

14 of 43

While we are taking a break

Write a NetLogo program that generates two different polygons—a triangle and a hexagon based on user input.

15 of 43

Basic Agents

16 of 43

Turtles

  • crt 50 ;; create 50 turtles
  • ask turtles [set size 3]
  • ask turtles [set color red]
  • ask turtles [forward 10]
  • ask turtles [rt 90]
  • ask turtles [die]
  • clear-all ;; clear all the object

17 of 43

Turtles

  • ask turtles [ pen-down]
  • ask turtles [ repeat 10 [fd 10 rt 90]]
  • clear-drawing ;; clear draws

18 of 43

Patches

  • ask patches [set pcolor pxcor * pycor]
  • crt 100
  • ask turtles [setxy random-xcor random-ycor]
  • ask turtles [set pcolor color]
  • ask patches [set pcolor black]
  • ask turtles [set color pcolor]

19 of 43

Links

  • ask turtles [create-link-with one-of other turtles]
  • ask turtles [set color xcor]
  • ask links [die]
  • ask turtles [create-link-with one-of other turtles in-radius 10]

* Graph Layouts

  • ask turtles [layout-tutte (turtles with [count link-neighbors > 1]) links 15 ]

20 of 43

A Brief History of �Agent-Based Modeling

20

21 of 43

21

22 of 43

John von Neumann’s �universal constructor

22

Artificial Life

A creation which can reproduce itself

23 of 43

Artificial Life

23

“soft” Alife

“hard” ALife

Cellular Automata

Robots

24 of 43

What is “Cellular Automata”?

A collection of cells on a grid, each cell is in one of a finite number of states (e.g., on and off), and changes its state following simple rules based on the states of its neighboring cells.

24

A model consists of a large number of simple components (cells), which are modified only by local interactions, but which acting together can produce global complex behavior.

Stephen Wolfram (1984) Cellular automata as models of complexity

25 of 43

1-dimensional cellular automata

25

26 of 43

You may draw on papers or whiteboards manually, or…

26

27 of 43

Model01: Von Neumann’s Cellular Automata Model

28 of 43

28

NetLogo > Model Library > Cellular Automata > CA 1D Elementary

29 of 43

29

You can run forever….

30 of 43

30

31 of 43

Model02: Conway’s Game of Life

32 of 43

John H. Conway’s Game of Life

  • A best known two-dimensional cellular automata

  • Goals
    • The model should not generate explosive growth
    • The model should generate small initial patterns with chaotic, unpredictable outcomes.
    • The model should be potentially be von Neumann universal constructors.
    • The model should be simple.

32

33 of 43

John H. Conway’s Game of Life

  • Basic setup
    • Each cell is either alive (1) or dead (0)
    • Moore neighborhood of range r=1

  • Rules
    • If there are less than 2 alive neighbors, the cell dies.
    • If there are more than 3 alive neighbors, cell dies.
    • If there are 2 alive neighbors, the cell remains in the states in the state it is in.
    • If there are exactly 3 alive neighbors, the cell becomes alive.

33

34 of 43

John H. Conway’s Game of Life

  • Patterns
    • Still Life
    • Oscillators
    • Spaceships
    • Gemini’ (Andrew J. Wade, 2010) is the first self-replicating structure (universal constructor) engineered in the Game of Life.

34

Block

Boat

Blinker

Pulsar

Glider

35 of 43

Simple rules generate complex patterns.

35

36 of 43

36

37 of 43

Four Classes of CA Behaviors

Class 1. The pattern disappears with time. All initial conditions lead to exactly the same uniform final state . It is entirely predictable, independent of initial state

37

Stephen Wolfram (1984) Cellular automata as models of complexity

CA Rule 248

CA Rule 254

CA Rule 32

38 of 43

Four Classes of CA Behaviors

Class 2. The pattern evolves to a fixed finite size. There are many different possible final states. But all of them consist just of a certain set of simple structures that either remain the same forever or repeat every few steps. You can predict local behavior from local initial state.

38

Stephen Wolfram (1984) Cellular automata as models of complexity

CA Rule 232

39 of 43

Four Classes of CA Behaviors

Class 3. The pattern grows indefinitely at a fixed speed. Class 3 patterns are often found to be self-similar or scale invariant. When parts are magnified they are indistinguisible from the whole – Fractals. The patterns appear random and chaotic.

39

Stephen Wolfram (1984) Cellular automata as models of complexity

CA Rule 30

40 of 43

Four Classes of�CA Behaviors

Class 4. The pattern grows and contracts irregularly. Changes are irregular. Behaviors are effectively unpredictable. The pattern of class 4 appears between class 2 and class 3.

40

CA Rule 110

41 of 43

Four Classes of CA Behaviors

Class 1 Class 2 Class 3 Class 4

Simple Complex

Predictable Unpredictable

42 of 43

Complex systems��Interdisciplinary��Generative�

42

Science with “Agent-Based Modeling”

43 of 43

Discussion questions

Which sport is more complex, soccer vs. basketball?

Is a system more complex or less complex than the sum of parts? Why so? Examples?

Please write a few research questions agent-based modeling can be used.

43