Life Cycle Stages NetLogo Model
Produced for the book series "Artificial Intelligence";
Author: W. J. Teahan; Publisher: Ventus Publishing Aps.
powered by NetLogo
view/download model file: Life-Cycle-Stages.nlogo
WHAT IS IT?
This model shows an example of finite state automata (FSA) that represents the life cycle stages of people throughout their lives. The model is based a model proposed by on D Jobber (1998) in "Principles and Practice of Marketing", McGraw-Hill. The FSA is drawn rotated 90 degrees to the way Jobber draws it. This is simply because it is easier to fit the middle line of states vertically rather than horizontally within the NetLogo environment.
The model illustrates that life is not a linear progression - there are cycles that people go through.
THE INTERFACE
The Interface buttons are defined as follows:
- setup: This sets up the FSA.
- go-once: This executes one tick of the simulation.
- go: This makes the simulation runs continuously.
The Interface sliders and switches are defined as follows:
- births-each-tick slider: This is the number of turtle agents that are born each tick (that start at the "Single, at home" state at the top middle of the FSA).
- turtles-are-visible switch: If this is set to Off, the turtles will become invisible.
The Interface plot labelled "Agent population" plots the number of agents that currently exist versus time tick for three sets of states: for all states; for just the "Young, parents" state; and for just the "Solitary, retired" state.
HOW IT WORKS
The slider birth-each-tick controls the number of turtle agents that are born each tick. They will start out in the top middle state labelled "Single, at home". Each subsequent tick, these agents will randomly choose to head to one of the outgoing states. Eventually, each agent will end up in the final state labelled "Solitary, retired" at the middle bottom.
HOW TO USE IT
This model is another more complicated example of a FSA. It can be used as a starting point for drawing other FSAs, and then animating them. To run the simulation, press the setup button first, followed by either the go once button (to make the simulation proceed one tick) or the go button (to make the simulation proceed continuously).
WHAT IS ITS PURPOSE?
Its purpose is to show how you can animate FSAs in NetLogo.
RELATED MODELS
See the Two States models.
CREDITS AND REFERENCES
To refer to this model in publications, please use:
Teahan, W. J. (2010). Life Cycle Stages NetLogo model.
Artificial Intelligence. Ventus Publishing Aps.
PROCEDURES
; Life Cycle Stages model.
;
; Based on D Jobber, 1998. "Principles and Practice of Marketing", McGraw-Hill
; Copyright 2009 William John Teahan. All Rights Reserved.
breed [agents agent]
breed [points point]
directed-link-breed [straight-paths straight-path]
directed-link-breed [curved-paths curved-path]
agents-own [location] ;; holds a point
to setup
clear-all ;; clear everything
;; ask patches [ set pcolor white ] ;; make background full of white patches
set-default-shape points "circle 2"
create-points 1 [setxy 5 46] ;; point 0
create-points 1 [setxy -20 32] ;; point 1
create-points 1 [setxy 5 32] ;; point 2
create-points 1 [setxy 30 32] ;; point 3
create-points 1 [setxy -20 18] ;; point 4
create-points 1 [setxy 5 18] ;; point 5
create-points 1 [setxy -47 4] ;; point 6
create-points 1 [setxy -20 4] ;; point 7
create-points 1 [setxy 5 4] ;; point 8
create-points 1 [setxy 30 4] ;; point 9
create-points 1 [setxy 55 4] ;; point 10
create-points 1 [setxy -20 -10] ;; point 11
create-points 1 [setxy 5 -10] ;; point 12
create-points 1 [setxy 5 -24] ;; point 13
create-points 1 [setxy 5 -38] ;; point 14
ask patches [
;; don't allow the viewer to see these patches; they are only for
;; displaying labels on separate lines
if (pxcor = 1 and pycor = 49) [set plabel "Single,"]
if (pxcor = 1 and pycor = 46) [set plabel "at home"]
if (pxcor = -24 and pycor = 34) [set plabel "Young,"]
if (pxcor = -24 and pycor = 31) [set plabel "on own"]
if (pxcor = 2 and pycor = 34) [set plabel "Young,"]
if (pxcor = 2 and pycor = 30) [set plabel "couple,"]
if (pxcor = 1 and pycor = 27) [set plabel "no children"]
if (pxcor = 41 and pycor = 34) [set plabel "Young,"]
if (pxcor = 44 and pycor = 31) [set plabel "divorced,"]
if (pxcor = 46 and pycor = 28) [set plabel "no children"]
if (pxcor = -23 and pycor = 18) [set plabel "Young,"]
if (pxcor = -23 and pycor = 15) [set plabel "divorced,"]
if (pxcor = -23 and pycor = 12) [set plabel "with children"]
if (pxcor = 15 and pycor = 18) [set plabel "Young,"]
if (pxcor = 16 and pycor = 15) [set plabel "parents"]
if (pxcor = -50 and pycor = 4) [set plabel "Middle-aged,"]
if (pxcor = -51 and pycor = 1) [set plabel "on own"]
if (pxcor = -23 and pycor = 4) [set plabel "Middle-aged,"]
if (pxcor = -23 and pycor = 1) [set plabel "divorced,"]
if (pxcor = -24 and pycor = -2) [set plabel "with children"]
if (pxcor = 2 and pycor = 4) [set plabel "Middle-aged,"]
if (pxcor = 2 and pycor = -1) [set plabel "parents"]
if (pxcor = 26 and pycor = 4) [set plabel "Middle-aged,"]
if (pxcor = 26 and pycor = 1) [set plabel "married,"]
if (pxcor = 25 and pycor = -2) [set plabel "no children"]
if (pxcor = 51 and pycor = 4) [set plabel "Middle-aged,"]
if (pxcor = 51 and pycor = 1) [set plabel "divorced,"]
if (pxcor = 50 and pycor = -2) [set plabel "no children"]
if (pxcor = -23 and pycor = -10) [set plabel "Middle-aged,"]
if (pxcor = -23 and pycor = -13) [set plabel "divorced,"]
if (pxcor = -24 and pycor = -16) [set plabel "no dependent children"]
if (pxcor = 2 and pycor = -10) [set plabel "Empty nester,"]
if (pxcor = 2 and pycor = -15) [set plabel "married,"]
if (pxcor = 1 and pycor = -18) [set plabel "working"]
if (pxcor = 2 and pycor = -22) [set plabel "Empty nester,"]
if (pxcor = 2 and pycor = -25) [set plabel "married,"]
if (pxcor = 1 and pycor = -28) [set plabel "retired"]
if (pxcor = 2 and pycor = -38) [set plabel "Solitary,"]
if (pxcor = 2 and pycor = -41) [set plabel "retired"]
]
ask points [set size 5 set color blue]
ask point 0 [create-straight-path-to point 1]
ask point 0 [create-straight-path-to point 2]
ask point 1 [create-straight-path-to point 2]
ask point 1 [create-straight-path-to point 6]
ask point 2 [create-curved-path-to point 3]
ask point 2 [create-straight-path-to point 5]
ask point 2 [create-straight-path-to point 9]
ask point 3 [create-curved-path-to point 2]
ask point 3 [create-straight-path-to point 10]
ask point 4 [create-curved-path-to point 5]
ask point 5 [create-curved-path-to point 4]
ask point 5 [create-straight-path-to point 8]
ask point 6 [create-straight-path-to point 14]
ask point 7 [create-curved-path-to point 8]
ask point 8 [create-curved-path-to point 7]
ask point 8 [create-straight-path-to point 12]
ask point 9 [create-straight-path-to point 13]
ask point 10 [create-straight-path-to point 14]
ask point 11 [create-curved-path-to point 12]
ask point 12 [create-curved-path-to point 11]
ask point 12 [create-straight-path-to point 13]
ask point 13 [create-straight-path-to point 14]
;; ask points [ create-path-with one-of other points ]
;; lay it out so links are not overlapping
ask straight-paths [ set thickness 0.5 ]
ask curved-paths [ set thickness 0.5 ]
set-default-shape curved-paths "curved path"
;; put some "walker" turtles on the network
end
to go
ask links [ set thickness 0.5 ]
create-agents births-each-tick [
set color lime
;;set location one-of points
set location point 0
move-to location
ifelse turtles-are-visible
[set size 10]
[set size 0]
]
ask agents [
let new-location one-of [out-link-neighbors] of location
ifelse (new-location = nobody)
[ die ] ;; Kill agent that reaches bottom point
;;else
[
;; change the thickness of the link I will cross over
ask [link-with new-location] of location [ set thickness 1.1 ]
face new-location ;; not strictly necessary, but improves the visuals a bit
move-to new-location
set location new-location
]
]
update-plot
tick
end
to update-plot
set-current-plot "Agent population"
set-current-plot-pen "All"
plot count agents
set-current-plot-pen "Yng par"
plot count turtles-on point 5
set-current-plot-pen "Sol ret"
plot count turtles-on point 14
end
;
; Copyright 2010 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). Life Cycle Stages NetLogo model.
; Artificial Intelligence. Ventus Publishing Aps.
;
