Wall Following Events NetLogo Model

Produced for the book series "Artificial Intelligence";

Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: Wall-Following-Events.nlogo


This model visualises a small set of events that an agent can follow in order to perform a modified type of wall following behaviour where sensing, thinking and acting are all done concurrently in no particular order (see the Wall Following Example 2 model for further explanation). The events are shown using an event map representation, where events are linked to other events on separate streams in an ordered sequence. The idea is that an agent processes events simultaneously on separate streams. The approach is similar to the approach adopted for Event Stream Processing (ESP).


The purpose of this model is to show how to visualise a series of events using an event map.


The model uses turtle agents to represent the states in the event map, and uses links agents to represent the paths between states. States own three variables:

- depth: The depth in the event map tree.
- stream: The stream name (where a stream consists of a sequence of sensory or motor events).
- event: The event - either sensory or motor.

A spring layout is used to visualise the event map.


Press the setup button first. This will often produce a cluttered layout. To unfold the clutter, press the change-layout button, and then dynamically change the values in the sliders that control the layout. One effective technique is to reduce the value of the spring-length slider to 0, then slowly increase it back up again until the desired length is achieved.


The model's Interface buttons are defined as follows:

- setup: This will clear the environment and variables and (re)-load the event map. Normally, this will appear in a cluttered form and the change-layout button needs to be pressed subsequently.

- change-layout: This can be used to clear some of the clutter by changing the values in the three sliders.

The model's Interface sliders are defined as follows:

- spring-constant: This is a value used by the layout-spring command. Changing it will usually not affect the visualisation of the event map much.

- sprint-length: This modifies the length of the paths between the states of the event map network.

- repulsion-constant: This controls how much each of the states repulse each other.


Notice how the repulsion-constant slider can be used to "repel" the states away from each other (for larger values) and "attract" the states towards each other (for smaller values).

Notice that the clutter in the network layout can often be removed by setting the value of the spring-length slider to zero and then increasing it afterwards.


Try altering the values of the sliders to see what effect this has on the layout.


Combine this model with the Wall Following Example 2 model. Then animate the environment and event map at the same time for one of the agents in the environment that is moving around following the walls.


The model uses the layout-spring command for modifying the layout of the network of states (turtle agents) and paths (link agents).


See the Wall Following Example 2 model, the Central Park Events model and the Knowledge Representation model.


This model was created by William John Teahan.

To refer to this model in publications, please use:

Central Park Events NetLogo model.
Teahan, W. J. (2010). Artificial Intelligence. Ventus Publishing Aps.


; Wall Following Events model.
; Draws an event map for the wall following behaviour.
; Copyright 2010 William John Teahan. All Rights Reserved.

breed [states state]
directed-link-breed [paths path]

[ depth       ;; depth in the tree
  stream      ;; the name of the stream of sensory or motor events
  event       ;; the sensory or motor event

[ root-colour node-colour link-colour ] ;; defines how the event tree gets visualised

to setup
  clear-all ;; clear everything
  set-default-shape states "circle 2"
  set root-colour sky
  set node-colour sky
  set link-colour sky
  add-events (list ["sensing-event" "use-sight"]
             (list "motor-event" "look-to-right")
             (list "sensed-object-event" "wall")
             (list "motor-event" "turn-90-to-preferred-side")
             (list "create-abstract-event" "checked-following-wall"))
  add-events (list ["sensing-event" "use-sight"]
             (list "motor-event" "look-to-right")
             (list "sensed-object-event" "nothing")
             (list "create-abstract-event" "checked-following-wall"))
  add-events (list ["sensing-event" "use-sight"]
             (list "motor-event" "look-ahead")
             (list "sensed-object-event" "wall")
             (list "motor-event" "turn-90-to-non-preferred-side"))
  add-events (list ["sensing-event" "use-sight"]
             (list "motor-event" "look-ahead")
             (list "sensed-object-event" "nothing")
             (list "create-abstract-event" "way-is-clear"))
  add-events (list ["abstract-event" "checked-following-wall"]
             (list "abstract-event" "way-is-clear")
             (list "motor-event" "move-forward-1")
             (list "delete-abstract-event" "way-is-clear")
             (list "delete-abstract-event" "checked-following-wall"))

to reset-layout
  repeat 500 [ layout-spring states paths spring-constant spring-length repulsion-constant ]

  ;; leave space around the edges
  ask states [ setxy 0.95 * xcor 0.95 * ycor ]

to change-layout

to set-state-label
;; sets the label for the state
  set label (word "[" stream " = " event "]   ")

to add-events [list-of-events]
;; add events in the list-of-events list to the events tree.
;; each item of the list-of-events list must consist of a two itemed list.
;; e.g. [[hue 0.9] [brightness 0.8]]

  let this-depth 0
  let this-stream ""
  let this-event ""
  let this-state nobody
  let next-state nobody
  let these-states states
  let matching-states []
  let matched-all-so-far true
  foreach list-of-events
  [ set this-stream first ?
    set this-event last ?

    ;; check to see if state already exists
    set matching-states these-states with [stream = this-stream and event = this-event and depth = this-depth]
    ifelse (matched-all-so-far = true) and (count matching-states > 0)
        set next-state one-of matching-states
        ask next-state [ set-state-label ]
        set these-states [out-path-neighbors] of next-state ]
      [ ;; state does not exist - create it
        set matched-all-so-far false
        create-states 1
          set size 8
          set depth this-depth
          set stream this-stream
          set event this-event
          ifelse (depth = 0)
            [ set label-color root-colour ]
            [ set label-color node-colour ]
          ifelse (depth = 0)
            [ set color root-colour ]
            [ set color node-colour ]
          set next-state self

    if (this-state != nobody)
      [ ask this-state [ create-path-to next-state [ set color link-colour ]]]
    ;; go down the tree
    set this-state next-state    
    set this-depth this-depth + 1
  ask links [ set thickness 1.3 ]
; Copyright 2009 by William John Teahan.  All rights reserved.
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from William John Teahan.
; Contact William John Teahan for appropriate licenses for redistribution for
; profit.
; To refer to this model in publications, please use:
; Teahan, W. J. (2010).  Wall Following Events NetLogo model.
;   Artificial Intelligence. Ventus Publishing Aps.