Adaptation

Social systems are complex because agents can change their behavior to improve their fitness. For example, a person might learn carpentry, quit smoking, loose weight, get a hair cut, or dilate his pupils.

Strictly speaking, these types of changes should be called learning or acclimation, as adaptation normally refers to evolutionary adaptation.

Actors and Roles

An actor might play many roles in his lifetime. Keanu Reeves, for example, has played the roles of Ted, Neo, and Buddha. In a supply chain an agent may play the role of producer sometimes and consumer other times. A business man may play the role of "honest businessman" sometimes and crook other times. Parent, spouse, child, employee, boss, teacher, student, leader, follower, etc. are examples of the roles we all play.

In NetLogo the role of a turtle can be a simple type tag:

turtles own [
   role
]

Of course the tag can be changed dynamically:

ask turtle 10 [set role "teacher"]

The update-turtle procedure uses the role attribute to dispatch to a role-appropriate task:

to update-turtle
   if role = "teacher" [
      teach
      stop
   ]
   if role = "student" [
      learn
      stop
   ]
   if role = "manager" [
      manage
      stop
   ]
   ; etc.
]

Although NetLogo doesn't support polymorphism, which would allow us to add tasks and roles without changing the update-turtle procedure, it does have a limited form of reflection. We begin by defining a global dispatch table called tasks:

set tasks (list
      (list "teacher" "teach")
      (list "manager" "manage")
      (list "student" "learn"))

We also provide a utility for looking up tasks:

to-report lookup-task [state]
   foreach tasks [
      if state = first ? [
         report first butfirst ?
      ]
   ]
   report "sleep" ; a do nothing procedure
end

Finally, we use NetLogo's run procedure to execute the appropriate task:

to update-turtle
  let task lookup-task role
  run task
end

Of course this could be made even simpler if a turtle's role was replaced by his current task:

to update-turtle
  run task
end

Treating procedures and functions as data is a trick from functional programming. This is also similar to the Pluggable Adapter Design pattern.

Note 1: In some systems, such as Jade, roles are called "behaviours"(sic.)

Note 2: Roles/behaviors are similar to strategies in the Strategy Design Pattern, or maybe peers in the Bridge Design Pattern. The Actor-Role distinction is the basic idea behind the Actor-Role Analysis Pattern.

Climbing Mount Enlightenment

In the previous example the roles/behaviors available to an actor were pre-defined. But where do behaviors come from in the first place? The answer is that they are adaptations (in the broad sense of the word). Through competitions with other agents, we learn new behaviors.

Learn.nlogo is a simple example of learning by imitation. Turtles move around Mount Enlightenment trying to find its summit (which has its origin at the center of the screen, of course). Turtle t picks a random neighbor within its field of vision. If the neighbor is at a higher level of consciousness, then t sets his heading for the heading of his new guru and takes one step forward.

Note that a turtle can know the altitude (i.e., "level of enlightenment") of another turtle, but doesn't know the altitude of any patch. In other words, a turtle only knows the altitude of a patch if there's a turtle standing on it. Or to put it another way, if we all knew where the best place to be was, we'd all be there by now. On the other hand, it's easy for Bill to see that Tom is doing better than he is and therefore he should start studying, emulating, and/or worshipping Tom.

One twist is that some turtles are innovators. Sometimes, when an innovator spots a neighbor at a higher level, it might set its heading to a random number rather than simply follow this neighbor.

In a more complex model, turtles might get ahead by competing rather than emulating. This is explored in Tournaments.