Try to get the caterpillars to form a rolling swarm.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. You can get Java from here.

powered by NetLogo

view/download model file: caterpillar.nlogo

WHAT IS THIS?

Some social caterpillars can move in a strange formation called a rolling swarm. Basically, they assemble into a kind of moving conveyor belt, made out of caterpillars. By riding on this conveyor belt, the caterpillars can give themselves a speed boost. You can see this happening in this video by Destin at Smarter Every Day and read about it on my blog.

But why do they work together? I implemented a simple model, suggested by my friend Deepak Iyer, to show how seemingly co-operative behavior can emerge out of simple, selfish rules. Here’s how it works.

That’s the one key rule. The remaining rules just model the physics of this world:

In this model, there’s no organizing force that makes these caterpillars organize. Surprisingly, through blind comeptition, they end up co-operating and helping each other out. This is an example of an emergent phenomenon, where “more is different”.

HOW TO USE IT

THINGS TO NOTICE

THINGS TO TRY

THIS IS AWESOME. WHERE CAN I LEARN MORE?

Here’s my blog post on the science of these swarming caterpillars

And here’s an incredible article by Ed Yong on the science of swarming

HOW CAN I MAKE THIS BETTER?

HOW CAN I BUILD THIS?

I created this model in NetLogo by modifying the code for the following model of traffic:
* Wilensky, U. (1997). NetLogo Traffic Basic model. http://ccl.northwestern.edu/netlogo/models/TrafficBasic. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
* Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT

Copyright 2013 Aatish Bhatia. Based on the NetLogo Traffic Basic model (1997) by 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 http://creativecommons.org/licenses/by-nc-sa/3.0/

CODE

globals [ sample-car ]
turtles-own [ speed speed-limit speed-min ]

to setup
  clear-all
  ask patches [ setup-road ]
  setup-cars
  reset-ticks
  ;watch sample-car
end

to setup-road  ;; patch procedure
  if (pycor < 5) and (pycor > -5) [ set pcolor white ]
end

to setup-cars
  set-default-shape turtles "caterpillar"
  crt number-of-caterpillars [
    set color green
    set size 3
    set xcor random-xcor
    set ycor -4
    set heading  90
    ;;; set initial speed to be 1 and speed limit to be 5
    set speed  1
    set speed-limit  5
    set speed-min  1
    separate-cars
  ]
    set sample-car one-of turtles
  ask sample-car [ set color red ]

end

;collision detection and climb function
;so we don't end up with any two cars on the same patch
to separate-cars  ;; turtle procedure
  let other-cars-here one-of other turtles-here
  let car-above one-of turtles-on patch-at 0 1
    
  if any? other turtles-here and (car-above = nobody)
    [ 
      ;match speed
      ;set speed [speed] of other-cars-here
      ;move one step up
      left 90
      forward 1
      right 90
      ;increment speed by one
      set speed speed + 1
      ;repeat if needed
      separate-cars
      ]

  ;prevents pileups when there isn't space to move up
  if any? other turtles-here and (car-above != nobody)
    [ 
      ;match speed
      set speed [speed] of other-cars-here
      back 1
      separate-cars
      ]

end

to fall  ;; turtle procedure
  ;check to see if there is anyone below
  let car-below one-of turtles-on patch-at 0 -1
  ;if not, and you're above the ground level
  if (car-below = nobody) and (ycor > -4)
    [ ;fall one step down
      rt 90
      fd 1
      lt 90
      ;reduce speed by one step
      set speed speed - 1
      ;repeat if needed
      fall ]
end


to go

  ask turtles [

   ; if there is a car ahead of you, exceed its speed    
    let car-ahead one-of turtles-on patch-ahead range
    if (car-ahead != nobody) 
      [ set speed [speed + 1] of car-ahead ]
  
   ; if not, slow down to minimum speed 
    let car-below one-of turtles-on patch-at 0 -1
    if (car-ahead = nobody) and (ycor = -4) ;(car-below = nobody)
      [ set speed speed-min ]
    if (car-ahead = nobody) and (car-below != nobody)
      [ set speed [speed + 1] of car-below ]
 
    ; don't slow down below speed minimum or speed up beyond speed limit
    ;if speed < speed-min  [ set speed speed-min ]
    if speed > speed-limit   [ set speed speed-limit ]

    ;increment position
    fd speed 
]  

ask turtles [
    ;collision detection
    separate-cars
]

ask turtles [   
    ;fall function
    fall
]


tick
end