ALife Somatic Computation

ALife Somatic Computation preview image

1 collaborator


artificial life 

Tagged by Carlos Pedro S. Gonçalves over 3 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 676 times • Downloaded 40 times • Run 0 times
Download the 'ALife Somatic Computation' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


This is a model that combines Artificial Intelligence (AI) and Artificial Life (ALife), introducing an artificial ecosysem inhabited by replicator organisms of two types: plantoids, that mimick plant-like organisms, and m-agents (mobile agents), that mimick animal-like organisms, the later are divided in two more subtypes: cog-0 replicators and cog-1 replicators. Cog-0 replicators are self-replicating agents, whose interface with the environment incorporates Holland's Echo rules. Cog-1 replicators are also modelled as self-replicating agents but that are programmed with basic emotional responses when faced with survival situations.

An earlier version of the model was presented at the seminar Groups, Technology and Creativity ("Grupos, Tecnologia e Criatividade") that took place in ISCTE-IUL (, November 2005.

The main purpose of the model is to address a different approach combining AI and ALife, providing agents with basic reflexive skills and introducing these agents to a survival context in which they have to adapt and coevolve to survival sistuations, thus, one is approaching AI from a perspective of adaptation to survival contexts, intermixing ALife with AI research.

The current model specifically addresses the comparison between self-replicating agents

that have an AI that implements a form of "somatic computation" (soma - body) in which basic emotional responses, taken in parallelism to actual living organisms, are introduced as a way to provide the agents with greater reflexive abilities.

The model provides a contribution to the field of AI and ALife in connection to a neurobiology-based cognitive framework for artificial systems and virtual environments' simulations.

On the other hand, the current model is also aimed at a basis for a simulation support to fundamental research in risk science and complex adaptive systems science, in particular, in what regards the role of elementary emotional responses, and the study of the consequences of these elementary emotional responses for evolution, complexity and adaptation to survival risk.


The model introduces populations of artificial replicators, that is, artificial biological entities that are capable of replicating exact copies of themselves. The artificial world in which these replicators coevolve has the following characteristics:

- The patches form the terrain which can be occupied by a first type of replicator which is inspired in plants, these are called plantoids;

- A second type of replicator is a bug-like artificial creature called a m-agent, that can come in two cognitive types: cog-0 and cog-1, the cog-0 agents do not have emotional responses to survival situations, they limit themselves to be automata that follow the rules based on John Holland's Echo, the cog-1 agents have a "somatic computation" AI, which responds to the organism's internal states and environment, triggering a somatic response that plays a similar role to emotional responses in living organisms in basic survival settings. The neurobiology-based "somatic computation", thus, plays a central role in cog-1's decision-making process.

The plantoids are fixed in the ground and are similar to plants, while the m-agents move around, losing energy when they move and replicate, and, thus, need to replenish their energy by:

(1) Extracting it from plantoids;

(2) Taking it from other m-agents.

Plantoids compete for space in the terrain, whenever a plantoid has more than half of the energy of any of its neighbors it replicates, taking the space previously occupied by its neighbor. The interaction and energy transfer between replicators follows Netlogo's Echo model.

The m-agents can be divided into two general kinds: the cog-0 and the cog-1.

The cog-0 are automata-like artificial creatures that move around on the world's surface and that are not capable of any emotional responses. They are modeled as energy extracting self-replicating automata. The cog-0 are, thus, mechanical, they do not show the sophisticated reflexive responses regarding their survival that is incorporated in cog-1 replicators.

Cog-1 replicators are introduced with a basic drive towards survival in the artificial environment, being capable of producing which can, by parallelism, be defined as basic emotional responses, all of them linked to survival, in particular, we have programmed three types of emotional responses, linked to the cog-1's somatic computation:

- Desire (associated with hunger);

- Desire to replicate;

- Fear, associated with conflict.

These emotional responses are based on work in neurobiology developed by António Damásio (1994, 1999), in which emotions are shown to play important roles in the homeostatic processes that regulate the organism's survival.

In our present case, the cog-1 artificial organisms respond to potentially dangerous situations or to feeding opportunities. In this sense, there is a proximity to the somatic markers role.

Organism's (both cog-1 and cog-0) face, in this version of the replicator's world, three types of survival situations, these correspond to:

(1) Feeding oportunities;

(2) Loss of energy in conflict situations;

(3) Replication;

(4) Moving.

While cog-0 replicators do not have adaptive reflexivity regarding these situations, the cog-1 replicators' AI is capable of adaptive responses that begin with changes in the body (soma) of the replicator: the replicator's body undergoes changes associated with these different situations.

Although the cog-1 replicators do not possess the complex bodies of actual living organisms, their 'artificial bodies' respond, in many instances, with an analogous dynamics inspired in biology.

In the same way as emotions-proper (disgust, fear, happiness, sadness, sympathy and shame) present in actual organisms are linked with life regulation by staving off dangers or helping the organism take advantage of an opportunity, or indirectly by facilitating social relations (Damásio, 2003, p.39), the mimicking of emotional responses that we programmed are also linked with "life" self-regulation.

The desire, associated with hunger, signals the need for nourishment, the onscreen changing colours of the cog-1 replicators represent the visible changes in this desire.

When the organism accumulates enough energy, another desire becomes dominant, the desire to replicate, the replicator, in this instance, becomes pink.

Fear and desire both play a role in conflict. While a cog-0 replicator fights with another replicator independently of the odds in favor or against, the cog-1 replicators respond with fear when the odds are against them and run away.

The fear response, in the model, is a simulated automatic (organic) response of the cog-1 replicator, when faced with a conflict situation.

The cog-1 is capable of evaluating itself and the other and deciding whether or not it should attack. This evaluation takes place in the form of a fear vs desire gauging. The cog-1 has a fear response to conflict and a desire response, if the fear overcomes the desire, it will not attack, avoiding the conflict because the potential prey is too strong, if the desire overcomes the fear, then, even despite the fear the cog-1 attacks.

There are two external simulated 'physiological changes' that occur when a replicator is faced with a fighting situation: if the fear exceeds the desire to feed, the replicator color becomes yellow, if the desire to feed exceeds the fear, the replicator color becomes red (although these colour changes occur, it is difficult to see it in the on-screen simulation because the conflict is very fast and the replicators change colours after the conflict, in the present version of the model, however, these physiological changes do not appear on-screen at all since, because of computing time, we place the no-display at the beginning of the go button procedures and the display at the end, which means that these color changes are programmed physiological changes that are not shown to the user who only sees the configuration at the beginning of a computing round and the configuration at the end of a computing round (computing round marked in this case by a tick)).

In moving, cog-0 and cog-1 are also different: cog-0 move randomly, a cog-1, on the other hand, is capable of evaluating how close it is to death, such that if moving leads to complete energy resource depletion it does not move. Also, when a cog-1 moves it always moves to "greener pastures", that is, to neighboring patches where the corresponding plantoid has the highest amount of energy resources.


The simulation environment is divided in three main sections:

- The Resource Parameters Section

- The Agents' Parameters Section

- The Agent Types Section

We now describe each section in turn.

(1) The Resource Parameters Section

The resource parameters control the plantoids' features and world's surface features, namely we have the following sliders:

A) Replenishment (the replenishment rate)

This slider controls the speed with which a plantoid is able to replenish its resources (replenishment rate) depends on the soil's characteristics, so that there is a different replenishment rate associated with each patch of land.

B) Fountains' capacity

Each patch of land is able to yield energy for the plantoid upon it, this slider controls the maximum energy capacity that a plantoid at a patch of land can have.

C) Genetic diversity

This controls the number of letters of the genetic alphabet (assumed in a numeric scale {0,1,...,N}. The default parameter is left in a four letter code (N=3), the user may change it and study the consequences of different alphabet codes.

(2) Agents' Parameters Section

In the agents' parameters section the user can control the initial number of agents (init-num-replicators), the replication chance (rep-chance), the mutation probability (mutation-p) and the maximum length of the genetic code (max-gen slider).

Each m-agent's genetic code is broken down into two sections, the offense tag and the defense tag, the amount of energy resources that the m-agent must acquire has to equal the length of the genetic code, this implies that the m-agent's reservoir must, at least, be equal to the length of the genetic code, the user can also control for an agent's extra reservoir capacity above the length of the genetic code (slider agent-max-reservoir).

Besides these sliders, there is also a slider "a-c" which controls the initial setup of cognitive types:

"a-c" = 0: all cog-0 agents

"a-c" = 1: 1/2 cog-0 and 1/2 cog-1 agents

"a-c" = 2: all cog-1 agents

A switch can also be used to show the genetic code labels.


The slider a-c controls the m-agent types that are present in the model. If it is set to 0, the model only runs with cog-0 replicators, if it is set to 1 both cog-0 and cog-1 replicators are present, finally, if it is set to 2 only cog-1 replicators are present.

It is interesting to run the model with different values for this slider and see the emerging patterns in terms of the ecosystem's risk profile and complexity.

Another matter is which replicator type has the most advantage in different types of settings. This can be evaluated by setting the a-c slider to 1, which will lead to initially equal populations size of cog-0 and cog-1 replicators. In which setting doe artificial emotional responses provide an advantage?


The model can be extended with respect to the cognitive replicators to include other ranges of emotions and reflexivity.


For further details regarding the model the user may consult the "Code" section, which contains a great number of explanatory notes.

Also the website contains further elements regarding this model including an arXiv link to the corresponding article.


- Wilensky, U. (2005). NetLogo Echo model. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

- Wilensky, U. (1999). NetLogo. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

- Levy S.: Artificial Life: A Report from the Frontier Where Computers Meet Biology. Vintage Books, New York (1992).

- Langton, C. (ed.): Artificial Life: An Overview. MIT, Cambridge (1995).

- Neumann, V.: The General and Logical Theory of Automata. In: Taub, A.H., (ed.) John von Neumann - Collected Works, Design of Computers, Theory of Automata and Numerical Analysis, Vol.5, 288-326, Pergamon Press, Macmillan, New York (1963).

- Holland, J.: Adaptation in Natural and Artificial Systems. MIT Press, Massachusetts (1992).

- Holland, J.: Hidden Order - How Adaptation Builds Complexity. Perseus Books, USA (1996).

- Holland, J.: Signals and Boundaries: Building Blocks for Complex Adaptive Systems. MIT Press, Massachusetts (2012).

- Damásio, A.: Descartes' Error: Emotion, Reason, and the Human Brain. HarperCollins Publishers, New York (1994).

- Damásio, A.: The Feeling of What Happens: Body and Emotion in the Making of Consciousness- Harcourt, San Diego (1999)

- Breazeal, C. and Scassellati, B.: A context-dependent attention system for a social robot. In Dean, T.L.: Proceedings of the Sixteenth International Joint Conference on Artificial Intelligence (IJCAI99). Stockholm, Sweden Vol.2, 1146-1151. Morgan Kaufmann Publishers, San Francisco (1999).

- Kaku, M.: Physics of the Future: How Science Will Shape Human Destiny and Our Daily Lives by the Year 2100. Doubleday, New York, (2011).

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [ replicators ] ; Replicator breed corresponding to mobile agents m-agents

       geneticlist ; A list of the different genetic variants

        ; Patches hold plantoids, each plantoid is a plant-like replicator with a fixed position in the territory
        ; The patches variables below actually correspond to plantoid-related variables
        max-reservoir ; Corresponds to a plantoid's reservoir capacity, defined as: the maximum amount of resources that a plantoid at that patch can generate.
                      ; This variable depends upon the territory characteristics, which means that plantoids with the same genetic code but at different locations can have
                      ; different reservoir capacities (different max-reservoir).

        plantoid-tag ; Corresponds to the plantoid's chromosome. Chromosomes are defined as per Holland's Echo rules: while actual chromosomes have a more complex relation to the
                     ; general structure of an organism, the chromosome in Echo's artificial world is introduced with two fundamental characteristics: the chromosome is the 
                     ; genetic material of the agent and determines the agent's interface and interaction patterns, addressed in the model through tags that define these interactions,
                     ; the tags' contents match the segments of the chromosome's chain. 
        amount-resources ; Corresponds to the amount of resources that a plantoid holds at each time.

        ; Although the plantoids are replicators, in this Netlogo code these are being addressed internally through patch-related variables, since they are fixed in the terrain.
        ; The breed "replicator" is, thus, being applied to mobile agents, or m-agents.
        genetic-code ; Corresponds to a m-agent's entire chromosome chain
        cog ; The "cog" variable defines the cognitive type, there two cognitive types: Cog-0 basic self-replicating automata; Cog-1 agents capable of emotional responses.
        reservoir-capacity ; The maximum amount of energy resources that the m-agent can hold.
        agent-reservoir ; The amount of resources that the m-agent has stored.
        offense ; The m-agent's offense tag (corresponds to a section of the agent's chromosome).
        defense ; The m-agent's defense tag (corresponds to a section of the agent's chromosome).

        ; NOTE: together, the offense and defense tags compose the agent's chromosome.
        rep-thresh; The energy threshold that if exceeded leads the m-agent to replicate.
        ; Variables for agent-environment interactions: used in m-agent feeding interaction with plantoids (m-agens feed from plantoids' energy resources).
        ; Variables for agent-agent interactions: used in m-agent feeding interaction with other m-agents (m-agents feed from other m-agents' energy resources).
        ; Variables related with emotional responses: these are used in cog-1 related procedures and define the cog-1's AI's emotional responses in survival situations:
        fear ; The fear level is triggered in conflict situations in agent-agent feeding interaction (which take place as conflict procedures).

        desire ; Corresponds to the desire to feed variable. 
               ; The desire level is triggered by the m-agent's internal evaluation of its reservoir depletion level and its need to feed.
               ; The desire to feed is involved in deliberation around moving, feeding and conflict situations (agent-agent interactions).

        desire-to-replicate ; The desire to replicate is triggered in replication procedures.
        ; NOTE: none of these AI variables are used in the cog-0 interactions, so that cog-0 is a basic self-replicating automaton, while the cog-1 is programmed with 
        ; an AI capable of emotional responses. It is important to stress that the type of computation performed by cog-1 is a "somatic computation" (soma - body) in which
        ; basic emotion responses, taken in parallelism with living organisms, are introduced as a way to provide the agents with greater reflexive abilities.
        ; The cog-1 AI, thus, is programmed in such a way that an engagement of the whole artificial organism's body is involved in the computation, with physiological responses
        ; programmed into the artificial organism's cognitive ability, in this way we can speak of a "somatic" artificial intelligence.

to setup

set-default-shape replicators "bug"; m-agents shaped as bugs, called in the program code by the breed replicator.

setup-resources ; Sets up the resource fountains conditions and the plantoids profile
setup-m-agents ; Sets up the m-agents

; Auxiliary variables used in plotting procedures
set variants_0 []
set number-of-replicators_0 count replicators

to setup-resources

ask patches [ setup-terrain ] ; Setup the terrain in terms of resource fountain maximum capacity and initial resource level of plantoids.
ask patches [ setup-plantoids ] ; Setup the plantoids' genetic profile.

to setup-terrain

  ; Each plantoid can hold up to a maximum amount of energy resources characteristic of the patch it is at:
  set max-reservoir 1 + random fountains-capacity ; This is patch-specific plantoid procedure:
                                                  ; the maximum amount of energy resources characteristic of the patch (max-reservoir), 
                                                  ; which corresponds to the plantoid's energy reservoir capacity at that patch,
                                                  ; is set randomly with uniform probability between 1 and a maximum level equal to fountains-capacity (global parameter
                                                  ; defining the maximum plantoids' energy reservoir capacity admissible).
  ; Initially the plantoids are at their maximum resource level:
  set amount-resources max-reservoir ; This is a plantoid procedure.
  ; The patches color is set as a function of the amount of resources of the corresponding plantoid:
  set pcolor scale-color green amount-resources 200 0

to setup-plantoids

  ; The plantoids' chromosome chain is set with a length chosen randomly from 1 to max-gen
  ; each letter of the genetic code (defined as a Netlogo list) is taken initially from a random uniform distribution
  ; from a numeric alphabet {0,1,2,..., genetic-diversity}.
  set plantoid-tag n-values (1 + random max-gen) [random (1 + genetic-diversity)] 

to setup-m-agents
  create-replicators init-num-replicators ; Initial number of replicators
    set size 1 ; Each replicator sets its size as 1
    ;; Set the cognitive profile:
    set cog 0 ; The initial cog value is set to 0 in order to be able to replace it depending upon the a-c slider:
    if a-c = 0 [set cog 0] ; a-c slider = 0, means that all m-agents are set with the cognitive profile cog-0.
    if a-c = 2 [set cog 1] ; a-c slider = 2, means that all m-agents are set with the cognitive profile cog-1.
    ; NOTE: The case of a-c = 1 is set in another procedure below.
    ;: Set the genetic profile (each m-agent is born with a given chromosome chain that specifies two tags: an offense tag and
    ;; a defense tag):
    set offense n-values (1 + random max-gen) [random (1 + genetic-diversity)] ; The offense tag
    set defense n-values (1 + random max-gen) [random (1 + genetic-diversity)] ; The defense tag
    set genetic-code sentence offense defense ; The replicator's genetic code
    ;; Set the energy reservoir capacity:
    ; Each m-agent has an energy reservoir capacity which is set to be equal to the length of its genetic code plus a base
    ; reservoir level called agent-max-reservoir.

    set reservoir-capacity agent-max-reservoir + length genetic-code
    ; Initially all replicators have the reservoir at their maximum capacity
    set agent-reservoir reservoir-capacity
    ; Replication threshold for the m-agent equals the length of the m-agent's genetic code, this is involved in replication
    ; procedures: an m-agent only replicates when its energy exceeds the replication threshold (agent-reservoir > rep-thresh)
    set rep-thresh length genetic-code
    ; If the button labels is chosen the genetic-code of each m-agent is shown
    if labels? [set label genetic-code]
    ; Initial position of the m-agent
    setxy random-float world-width random-float world-height

; When a-c = 1 half of the m-agents are set to be of the cog-1 variant, this connects with the previous procedure of assignment of 
; cognitive profiles.

if a-c = 1 [ ask n-of (count turtles / 2) turtles [set cog 1] ]

; Cog-1s' desire to replicate is set to 0 in the initial configuration.
; None of the emotional response variables are applicable in the case of cog-0 m-agent.

ask replicators [ ifelse cog = 1 [set desire-to-replicate 0] [set desire-to-replicate "not applicable"] ]

ask replicators [ if cog = 0 [ set fear "not applicable" set desire "not applicable" ] ] 
ask replicators [ifelse cog = 1 [evaluate-internal-state] [set color green] ]

to go
  ;; First step is energy resource production by the plantoids
  ask patches [produce-resources]
  ;; Second step is resource collection procedures
  ; While cog-0 collect resources form the patch they are at, 
  ; cog-1 evaluate their internal state and their environment 
  ; before collecting resources (before feeding):
  ask replicators 
    if cog = 1 
    [ evaluate-internal-state ; Step 1 of cog-1's deliberation process: the evaluation of their internal state
                              ; this means that the cog-1 becomes aware of its feeding needs.
      evaluate-environment ] ; Step 2 of cog-1's deliberation process: the evaluation of the environment
   resource-collection ; The resource collection/feeding procedures implemented by the replicators.
   ask replicators
      ; Fighting procedures resulting from insufficient energy, this is a predator mode, where m-agent entities search for other
      ; m-agent entities from which to extract energy in a conflict situation
      if (agent-reservoir < max-reservoir) [ fight ] ; Fighting procedures
      replicate ; Replication procedures.
      ; If after fighting and replicating the m-agent's energy reservoir is depleted, then, that m-agent dies:
      if agent-reservoir <= 0 [die]
   ask patches [ if any? replicators-here [ release-poison ] ] ; Plantoids poison release procedure.
   ask patches 
   [ compete ; Competition procedures (define the plantoids' replication rules).
     set pcolor scale-color green amount-resources 200 0 ] ; Patch color defined in terms of the corresponding plantoids' energy resources
   if (not any? replicators) [stop]

to produce-resources
  ; If the maximum reservoir of a plantoid is not filled...
  ifelse max-reservoir - amount-resources > 0 
  ;... the plantoid produces resources by a fixed amount of replenishment rate ("replenishment" slider), otherwise...
  [set amount-resources amount-resources + replenishment ] 
  ;... the resource level continues unchanged (resource depletion can only come from consumption by replicators).
  [set amount-resources amount-resources]

to evaluate-internal-state
  ; The evaluation of internal state corresponds to the evaluation of the agent's energy level
  ; and internal energy requirements, synthesized in an emotional response of desire to feed,
  ; the desire to feed is be defined as an internal response of the agent to the proportion of the
  ; agent's reservoir that is empty called proportion of energy needs,
  ; In the procedure below the desire to feed is set as equal to the proportion of energy needs:
  set desire 1 - (agent-reservoir / reservoir-capacity)
  ; Change in color corresponds to a physiological change in the cog-1's body, depending upon
  ; the desire to feed, thus, the hungrier a cog-1 is, the paler the color is set, darker colors
  ; correspond to cog-1s that have less desire to feed, this is programmed as physiological changes
  ; in their artificial bodies as a consequence of the level of desire to feed:
  set color scale-color color-desire (desire * scale-color-p) scale-color-min scale-color-max

to evaluate-environment
  ; Moving costs one unit of energy, in this case, and if energy reaches zero or below zero
  ; the cog-1 dies. In this case, the cog-1 evaluates how close it is to death, if taking one
  ; step does not lead to energy depletion, then, the cog-1 moves uphil with respect to the 
  ; "amount of resources" plantoid variable, that is, it moves to the patch with the highest
  ; amount of energy resources. After this procedure the cog-1 evaluates again its internal state
  ; which triggers a new desire to feed level.
  if (1 - desire) * reservoir-capacity - 1 > 0 
  [ uphill amount-resources
   evaluate-internal-state ]

to move
  ; This is a universal procedure for both cog-0 and cog-1 agents.
  ; Motion leads to spending resources, so that at each step the agent loses one unit of energy of its reservoir.
  ; Death takes place if the resource is completely depeleted after moving.
  ; If the resource is not depleted a cog-0 replicator moves to a new random location.
  if cog = 0 
  [ set agent-reservoir agent-reservoir - 1
    ifelse agent-reservoir <= 0 [die] [rt random-normal 0 20 fd random-float 1] ] 

  ; A cog-1 replicator evaluates whether or not it should move
  ; if it's resources are depleted by moving the agent stays put and keeps its energy reservoir
  ; intact, otherwise, the cog-1 moves to the patch with an identified greater amount of resources (moving to greener pastures):
  if cog = 1 [ ifelse agent-reservoir - 1 <= 0 [set agent-reservoir agent-reservoir] [uphill amount-resources] ]

to resource-collection
  ; This is a universal procedure for both cog-0 and cog-1 agents.
  ; If the plantoid has energy resources available a chromosome-based scoring for feeding is initiated
  ask replicators [ if amount-resources > 0 [evaluate-scores] ]
  ; If the m-agent needs to feed and the amount of resources in the patch is greater than zero...
  ask replicators [ ifelse (agent-reservoir < reservoir-capacity) and (amount-resources > 0) 
        ;...then, the agent's reservoir level is increased by the amount of resources multiplied by the proportion of environmental score of the agent in relation
        ; to the total environmental score of the other m-agent automata at that location
         [ set agent-reservoir agent-reservoir + amount-resources * (environmental-score / (sum [environmental-score] of replicators-here))
           ; Resources are depleted by the agent's consumption
           set amount-resources amount-resources - amount-resources * (environmental-score / (sum [environmental-score] of replicators-here))           
           ; An agent only consumes up to its maximum reservoir capacity, any additional level of resources extracted is wasted
           ifelse agent-reservoir > max-reservoir [set agent-reservoir max-reservoir] [set agent-reservoir agent-reservoir] ]
        ; If the m-agent does not need to feed or there are no resources at the agent's location, then, the agent does not feed and keeps its reservoir level
        ; at its current level

         [set agent-reservoir agent-reservoir] ]

to evaluate-scores
  ; The scores are set depending upon a matching between the m-agent's interface with the plantoid, this depends upon genetic types:
  ; The comparison is between the plantoid's tag and the m-agent's offense tag which encodes to the m-agent's interface for feeding and for fighting.
  ; A list of matchings is defined so that the distance (measured in absolute value) is calculated between the contents for each offense tag element 
  ; and the corresponding tag element of the plantoid-tag, this is the envrionmental-comp procedure (the computation of the matching of the interface between
  ; the m-agent and the plantoid).

  ; The environmental-score is calculated as: extra-environmental * [0.5 * (n+ - n- + k) + 1], with:
  ; 'extra-environmental' = 0.5 if it is the plantoid that has the longest tag (longer chromosome string with respect to the length of the m-agent's offense chromosome string)
  ; 'extra-environmental' = 1 if it is the m-agent that has the longest tag (longer offense chromosome string with respect to the length of the plantoid's chromosome string)
  ; n+: number of matching letters in a letter-by-letter chromosome string comparison (tag comparison procedure)
  ; n-: number of non-matching letters in the string chromosme string comparison (tag comparison procedure)
  ; k: length of the shorter chromosome string (shorter tag).
  ; Tag comparison procedure:
  ifelse (length plantoid-tag > length offense) ; If the plantoid has a longer tag than the m-agent...
  ; ...the match is made between the m-agent's offense tag and the sublist of the plantoid's tag which
  ; matches in size the m-agent's offense tag, the extra score penalty is set to 0.5 for the m-agent 
  ; because it has the shorter tag:
  [set environmental-comp (map [abs (?1 - ?2)] offense (sublist plantoid-tag 0 (length offense)))
    set extra-environmental 0.5]
  ;... else: the match is made between the sublist of the m-agent's offense tag which matches in size the plantoid's tag
  ; and the plantoid's tag, the extra score penalty is set to 1 (no penalty incurred) for the m-agent because it does not have the
  ; shorter tag:
   [set environmental-comp (map [abs (?1 - ?2)] (sublist offense 0 (length plantoid-tag)) plantoid-tag)
    set extra-environmental 1]
  ; Scoring scheme: 
   set environmental-score extra-environmental * (0.5 * (length filter [? = 0] environmental-comp - length filter [? != 0] environmental-comp + length environmental-comp) + 1)

to fight

  ; A m-agent initiates fighting by looking for another m-agent at a place to fight
  if any? other replicators-here
  [ match-off-def self one-of other replicators-here ; "Choose a pair to attack and fight"

to match-off-def [agent1 agent2] ;; agent1 is the attacker agent2 is the defender.
  ; As a result of a fight the transfer of energy can be from the attacker to the defender or vice-versa.
  let transfer12 0 ;; transfer from 1 to 2 (from attacker to defender).

  let transfer21 0 ;; transfer from 2 to 1 (from defender to attacker).
  ;; SCORING PROCEDURE 1: Attack scoring
  ; Matching between tags takes place in a similar manner to the evaluation score for resource extraction from plantoids,
  ; in this case the matching is done between the offense tag and the defense tag.
  ifelse (length [defense] of agent2 > length [offense] of agent1) ; If the defender has a longer defense tag than the attacker's offense tag...
  ; ...the match is made between the attacker's offense tag and the sublist of the defender's defense tag which
  ; matches in size the attacker's offense tag, the extra score penalty is set to 0.5 for the attacker because it has the shorter tag:
  [ set agent-comp1 (map [abs (?1 - ?2)] [offense] of agent1 (sublist [defense] of agent2 0 (length [offense] of agent1)))
    set extra1 0.5 ]
  ; ... else: the match is made between the sublist of the attacker's offense tag, which matches in size the defender's defense tag,
  ; and the defender's defense tag, the extra score penalty is set to 1 (no penalty incurred) for the attacker because it does not have the
  ; shorter tag:
  [ set agent-comp1 (map [abs (?1 - ?2)] (sublist [offense] of agent1 0 (length [defense] of agent2)) [defense] of agent2)
    set extra1 1 ]
  ; Scoring is set as before:
   set agent-score1 extra1 * (0.5 * (length filter [? = 0] agent-comp1 - length filter [? != 0] agent-comp1 + length agent-comp1) + 1)
  ;; SCORING PROCEDURE 2: Defense scoring
  ; In the conflict the agent that defends when attack also strikes in response assuming (so that integrated in defense is a counterstrike
  ; the procedures are similar to the above procedures with some adjustments. Namely, the defender has a disadvantage when the tags match in size
  ; and not only when the defense tag of the attacking agent is longer than the defender's offense tag.
  ifelse (length [defense] of agent1 >= length [offense] of agent2) ; If the attacker has defense tag at least as long as the defender's offense tag...
   ; ...the match is made between the defender's offense tag and the sublist of the attacker's defense tag which
   ; matches in size the defender's offense tag, the extra score penalty is set to 0.5 for the defender because 
   ; it has the shorter tag or at least of equal size:
   [ set agent-comp2 (map [abs (?1 - ?2)] [offense] of agent2 (sublist [defense] of agent1 0 (length [offense] of agent2)))
     set extra2 0.5 ]
   ; ...else: the match is made between the sublist of the defender's offense tag, which matches in size the attackers's defense tag,
   ; and the attacker's defense tag, the extra score penalty is set to 1 (no penalty incurred) for the defender because it has the
   ; longer tag:
   [ set agent-comp2 (map [abs (?1 - ?2)] (sublist [offense] of agent2 0 (length [defense] of agent1)) [defense] of agent1)
       set extra2 1 ]
   ; Scoring is set as before:
   set agent-score2 extra2 * (0.5 * (length filter [? = 0] agent-comp2 - length filter [? != 0] agent-comp2 + length agent-comp2) + 1)
   ; The transfer of resources depends on the scores obtained by each agent relative to the total score.

   set proportion1 agent-score1 / (agent-score1 + agent-score2) ; Proportion of resources gained by attacker.
   set proportion2 agent-score2 / (agent-score1 + agent-score2) ; Proportion of resources gained by defender.
   ; Agent 1 (the attacker) transfers to agent 2 (the defender) an amount equal to proportion2 of its reservoir:  
   set transfer12 ([agent-reservoir] of agent1) * proportion2
   ; Agent 2 (the defender) transfers to agent 1 (the attacker) an amount equal to proportion1 of its reservoir.  
   set transfer21 ([agent-reservoir] of agent2) * proportion1
   ; For cog-0 agents the result of conflict is the above, for cog-1 agents they anticipate the result of a conflict, 
   ; in this sense if the agents are cog-1, they may not engage in conflict. This dynamics depends upon the attacker agent1.
   ; Cog-0 attackers do not have the antecipatory response given by the emotional trigger of fear versus desire that is introduced for Cog-1 replicators, so that 
   ; they just engage in conflict without deliberation.
   ask agent1 ; Attacker procedures
     ifelse cog = 1 ; If the m-agent is a cog-1, the agent anticipates the result of the resource transfer, the agent's actions will be dependent upon this evaluation
       ; Emotional responses:
       ; Fear: the fear of confrontation is triggered by the antecipatory perception of the outcome of the confrontation, namely,
       ; the cog-1 predator (the attacker) fears the confrontation by a level equal to the relative proportion of resources transferred to 
       ; the prey (the defender) over the total amount of energy resources transferred in the conflict:
       set fear transfer12 / (transfer21 + transfer12)
       ; Desire: the desire of confrontation is also triggered by the antecipatory perception of the outcome of the confrontation, namely,
       ; the cog-1 predator (the attacker) desires the transference of resources from the prey (the defender), so that the desire level is
       ; set equal to the proportion of energy resources received from the prey:
       set desire (1 - fear)
       ; If the fear surpasses the desire for resources (resource transfer to the defender is less than half the transfer from the defender)...
       ifelse fear > desire
       ;... color is set to yellow (the agent is afraid to engage in conflict) (NOTE: the color change reflects a physiological response), but
       ; nothing else happens, since the attacker does not engage the potencial prey...
       [ set color yellow ]
       ;...else: the cog-1's color changes to red (physiological response) and the cog-1 attacks so that resource transference takes place.
       [ set color red ; Color is set to red if the desire for resources surpasses the fear of conflict (in this case, the attacker identifies an advantage)
         set agent-reservoir agent-reservoir + transfer21 - transfer12 ; The agent's reservoir changes by the amount of resources received from the defender 
                                                                       ; minus the amount of resources lost in the conflict.
         ifelse agent-reservoir > max-reservoir [set agent-reservoir max-reservoir] [set agent-reservoir agent-reservoir] ; The agent's reservoir cannot exceed the maximum capacity.
         if agent-reservoir <= 0 [die] ] ; If the energy reservoir is depleted, the m-agent dies.
      ; For the cog-0, the resource transfer takes place independently of the advantage of each part.
      [ set agent-reservoir agent-reservoir + transfer21 - transfer12
       ifelse agent-reservoir > max-reservoir [set agent-reservoir max-reservoir] [set agent-reservoir agent-reservoir]
       if agent-reservoir <= 0 [die] ]
   ask agent2 
     ; Fear and desire are triggered in the same way for the cog-1 defender
     if cog = 1 [ set fear transfer21 / (transfer21 + transfer12) ; Cog-1 preys fear the loss of resources to the predator.
                  set desire (1 - fear) ; Cog-1 preys desire the resources from the predator.
                  ifelse fear > desire [set color yellow] [set color red] ] ; Physiological responses triggered by fear versus desire
     ; If the predator is a cog-1 that has decided to attack (identified by red color) or a cog-0, which attacks no matter what...
     if ([cog] of agent1 = 1 and [color] of agent1 = red) or ([cog] of agent1 = 0) 

     ; ... conflict takes place, the resource transference procedures are analogous:
     [ set agent-reservoir agent-reservoir + transfer12 - transfer21
       ifelse agent-reservoir > max-reservoir [set agent-reservoir max-reservoir] [set agent-reservoir agent-reservoir]
       if agent-reservoir <= 0 [die] ]
   ; Cog-1 reevaluate their internal state after conflict:
   ask agent1 [ if cog = 1 [ evaluate-internal-state ] ]
   ask agent2 [ if cog = 1 [ evaluate-internal-state ] ]

to replicate
  if (agent-reservoir > rep-thresh) ; If a m-agent's reservoir exceeds the replication threshold then...
   [ if (random-float 1.0000 <= rep-chance) ; ... replication takes place with probability equal to rep-chance
     [ if cog = 1 [ set desire-to-replicate 1 ; Cog-1 agents set their desire to replicate equal to 1
                    set color pink ]            ; and their color changes to pink, this is a physiological change in the agent's body
       hatch 1 ; A new m-agent is born
        [ ; The new m-agent gets the same traits as the parent:
          set offense [offense] of myself 
          set defense [defense] of myself
          set cog [cog] of myself
          ifelse cog = 1 [set desire-to-replicate 0] [set desire-to-replicate "not applicable"]
          ; Mutation can take place with probability mutation-p
          if random-float 1.000 <= mutation-p
          [ ifelse random-float 1.000 <= length offense / (length offense + length defense)
            [ set offense replace-item (random-float length offense) offense (random (1 + genetic-diversity)) ] ; Mutation can take place either in the offense tag...
            [ set defense replace-item (random-float length defense) defense (random (1 + genetic-diversity)) ] ; ... or in the defense tag
         set genetic-code sentence offense defense ; The genetic code of the new organism
         ; Reservoir capacity is the same as that of the parent, the new m-agent is, however, born with half the reservoir of the parent
         set reservoir-capacity [reservoir-capacity] of myself
         set agent-reservoir (0.5 * [agent-reservoir] of myself)
         ; The offspring gets the same replication threshold
         set rep-thresh [rep-thresh] of myself
         ; Cog-1 evaluates its internal state
         ifelse cog = 1 [evaluate-internal-state] [set color green]
         if labels? [set label genetic-code]
      set agent-reservoir agent-reservoir / 2 ; The agent loses half its reservoir to the new offspring.
      ifelse cog = 1 [evaluate-internal-state] [set color green] ; Cog-1 agents reevaluate their internal state.
      if cog = 1 [set desire-to-replicate 0] ] ; Cog-1 agents that have replicated no longer have desire to replicate for the round.

to release-poison
  ; The plantoids react to the m-agents releasing poison that depletes the energy of the m-agents by one unit:
  ask replicators-here 
  [ set agent-reservoir agent-reservoir - 1
    ifelse agent-reservoir <= 0 [die] [move] ] ; Agents that have their energy reservoir depleted die, otherwise moving procedures are implemented.

to compete
  ; Competition is a procedure for plantoids.
  ; If a plantoid finds a neighbor with less than half its resources, then, it replicates, with the offspring occupying now the neighboring patch.

  if any? neighbors with [amount-resources < 0.5 * [amount-resources] of myself]
  [ ask one-of neighbors with [amount-resources < 0.5 * [amount-resources] of myself] ; Replication takes place with a mutation probability 
      set plantoid-tag [plantoid-tag] of myself
      if random-float 1.000 < mutation-p 
      [ set plantoid-tag replace-item (random-float length plantoid-tag) plantoid-tag (random (1 + genetic-diversity))
        set amount-resources max-reservoir ] ; The new replicator increases the site's amount of resources to its maximum level.

to do-plots

; Increase and decrease in numbers ;

set number-of-replicators_1 count replicators
if (number-of-replicators_1 - number-of-replicators_0 < 0) [set decrease-in-population number-of-replicators_0 - number-of-replicators_1]

set-current-plot "Replicator Deaths"
plot decrease-in-population
set number-of-replicators_0 number-of-replicators_1

to plot-species

count-genetic-variants ; A procedure to count the number of genetic variants in the population

set-current-plot "Number of Different Variants"
plot num-variants

set-current-plot "Number of replicators"
plot count replicators

set-current-plot "Extinctions"
plot extinctions ; extinctions of genetic variants

set-current-plot "Genetic Complexity"
set-current-plot-pen "Average Complexity"
plot mean [length genetic-code] of replicators
set-current-plot-pen "Maximum Complexity"
plot max [length genetic-code] of replicators

set-current-plot "Plant Genetic Complexity"
set-current-plot-pen "Average Complexity"
plot mean [length plantoid-tag] of patches
set-current-plot-pen "Maximum Complexity"
plot max [length plantoid-tag] of patches

to count-genetic-variants
set variants remove-duplicates [genetic-code] of replicators 
set num-variants length variants
ifelse empty? variants_0 [set extinctions 0]
set variants_0 variants

to pair-up-gene-pool
let count-s 0
foreach variants_0 [if member? ? variants [set count-s count-s + 1]]
ifelse count-s < length variants_0 [set extinctions length variants_0 - count-s] [set extinctions 0]

There is only one version of this model, created over 3 years ago by Carlos Pedro S. Gonçalves.

Attached files

File Type Description Last updated
ALife Somatic Computation.png preview Preview for 'ALife Somatic Computation' over 3 years ago, by Carlos Pedro S. Gonçalves Download

This model does not have any ancestors.

This model does not have any descendants.