Category Archives: Agent-Based modelling

A modelling technique that deploys multiple ‘agent’ objects into an arena, each with its own behaviour patterns, allowing observations of interactions between them to be made by the observer.

Agent-Based Modelling with NetLogo

Agent-Based modelling is a powerful technique that we are using here at Cranfield University to explore scenarios where decisions or interventions are required, and the consequences of sets of outcomes, or behaviours needs to be explored. As a result agent-based modelling, or ABM, is widely used in the social sciences and management sciences for setting out and testing hypotheses. However ABM techniques also have an application in the environmental sciences where ‘agents’ can represent natural features or processes such as water droplets falling across a landscape, or land use patterns, for example in agricultural crop rotations.

Agent-based modelling software tools
A number of agent-based modelling software tools exist, the three most popular of which are linked below.
NetLogo :
Repast :
AgentSpring, an advanced ABM tool :

For beginners in ABM, it is suggested that Netlogo represents the easiest tool to use to learn about this technique.

Worked example with NetLogo
To run this example you will need to install NetLogo on your PC or MacBook first. NetLogo can be obtained here.

There are many excellent tutorials online for using NetLogo, so no need to repeat here. The best tutorial to start with is included with the installed help information for the software itself.

NetLogo Sample Model Tutorial:

In brief models identify four categories of objects: agents (or turtles); patches; links, and; observers. An embedded programming language using Logo allows customisation and conditional control over the agent objects and their behaviours – at initialisation and during the model run itself. A graphical user interface allows you to control and direct the flow of a model as it progresses through ‘ticks’, e.g. time steps. The speed at which these ticks progress can be changed by the user of the model. A model window presents the agent elements on-screen, during a model run. User interface features such as slider bars, switches and buttons allow you to develop sophisticated graphical user interfaces for your model. Additional features such as graphs allow you to plot agent model data throughout a run.

An extensive sample library of fully functional models, and code snippets comes with the installation and allows you to develop your ideas quickly with NetLogo.

Presented below is a simple ‘supply and demand’ agent-based model, which allows ‘demand’ agents to query properties of ‘supply’ agents. When a supplier satisfies a demand, a link is drawn between the two agents to show the user where the connection was met. A graph shows the user the number of connections that are made over time as the model runs.


Adjacent is a screenshot from the example model, the logo code for the model is presented below.

;; Simple Supply and Demand model
;; Definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

breed [ demanders demand ]
breed [ suppliers supply ]

demanders-own [ ;; properties of demanders

suppliers-own [ ;; properties of suppliers

;; Setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
  set-default-shape demanders "truck"
  set-default-shape suppliers "house"
  if number_of_demanders > count patches [
    user-message (word "This arena only has space for "count patches" demanders.")

to make-demanders ;; Create demanders
  create-demanders number_of_demanders [
    set color blue
    set happy? false
    set hit_count 0
    set label-color white
    setxy random-xcor random-ycor

to make-suppliers ;; Create suppliers with proportions of supply type
  ( foreach [ .3 .7 ] [ orange violet ] [
    create-suppliers precision (number_of_suppliers * ?1) 0 [
        set color ?2
        fd max-pxcor - 1
        fd max-pycor - 1

;; Run ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go ;; Run
  if ticks mod reset_period = 0 [ ;; Every 'n' ticks
    update-demanders-preferences  ;; update demander preferences

to move-demanders
  ask demanders [
    if happy? = false [ ;; and when happy remain still ...
      right random 360
      forward 1
      let _pref preference_of_supply ;; demanders properties
      let _happy false
      let _hits 0
      let _textcolor white
      ask suppliers in-cone-nowrap vision_distance vision_cone [
        ifelse _pref = color 
        [ if show_links = true [
            create-link-from myself ]
          set _happy true 
          set _hits ( _hits + 1 )
          set _textcolor green 
        [ set _happy false
          set _textcolor white ]
      ;; Carry settings back to demanders
      set happy? _happy
      set hit_count _hits
      set label-color _textcolor

to update-demanders-preferences ;; split half and half each cycle
  let _label ""
  ask n-of (number_of_demanders) demanders [ 
    set preference_of_supply (orange) 
    ifelse show-pref?
      [ set label-color white
        set label "o" ]
      [ set label "" ]
  ask n-of (number_of_demanders / 2) demanders [ 
    set preference_of_supply (violet) 
    ifelse show-pref?
      [ set label-color white
        set label "v" ]
      [ set label "" ]
  ask demanders [ ;; Force search mode
    set happy? false
  ask links [die]

;; end

Finding out more
One book in particular provides a very good overview of agent-based modelling, or ABM. In particular a detailed description is given of the stepwise modelling process in Chapter 3: see

Modeling Ostrom as agents:

For more information
For a published example of the use of agent-based modelling techniques in exploring the energy sector, look at this paper – co-authored by Cranfield scientist, Dr L.Varga, Director of the Complex Systems Research Centre (CSRC) in the Cranfield School of Management.

Gonzalez de Durana JM, Barambones O, Kremers E, Varga L (2014) Agent based modeling of energy networks. Energy Conversion and Management, 82 () 308-319.

The authors would like to thank Dr. ir. Igor Nikolic, Assistant Professor Section Energy & Industry, at the Faculty of Technology, Policy and Management, Delft University of Technology, The Netherlands, for his kind assistance with ABM. Web: