Projects‎ > ‎

open to change project model

This code library has been built to help people explore how altruistic punishment, bribes, status anxiety,  influence and privacy play in causing / preventing the tragedy of the commons. 

Model design

Pseudocode

  1. micro-behaviours (for patch, agent and utility prototypes)
    1. create view i.e. size of world and size of patches
    2. create n agents based on parameter set by slider
    3. initialise all agent and patch attributes
    4. set random position of agents
    5. set color of patches according to energy-of-patch
    6. agent scans patches and decides where to move to next
      1. agent reads energy-of-patch from all patches in radius vision 
      2. agent chooses a patch to move to based on patch variables e.g. energy, culture, privacy values
    7. agent takes energy from patch 
      1. my-greed or less (value 0.1 - 1 units)
    8. patch grows energy at the-growth-rate 0 - 0.1
    9. manage funds
      1. preference / sum of all preferences * ( 0.75 * my-assets )
    10. ( decide whether to set entry-cost-of-patch )
      1. if my-privacy-fund > [ entry-cost-of-patch ] of patch-here [
        1. if my-privacy-preference > 0.5
          1. set [ entry-cost-of-patch ] of patch-here [ entry-cost-of-patch ] of patch-here + (my-privacy-preference * ( random 10 ) )
          2. create a circular transparent agent just bigger than a patch:
            1. set shape "thin ring" set size 5 set color lput 64 extract-rgb 15 __set-line-thickness 0.5]
            2. transparency varies in range 0 - 250 so this could be used to change transparency as time ticked
    11. link to 1 or more agents in vision
      1. create-link-with one-of other agents in-radius my-vision
      2. put these agents into my-interaction-agents
        1. let n other turtles in-radius vision with [color > number ]
        2. create-links-with n [ set age-of-link 5 ]
      3. set age-of-link age-of-link - 1 
    12. bribe
      1. if my-defect = true
      2. ifelse my-bribe-fund >= my-bribe-preference
        1. [ set my-bribe-this-tick my-bribe-preference ]
        2. [ set my-bribe-this-tick my-bribe-fund ]
          1. let bribe my-bribe-this-tick
            1. ask [ other-end ] of my-links [ set my-assets my-assets + bribe ]
            2. set my-assets my-assets - my-bribe-this-tick
    13. punish
      1. if [ my-defect ] of other-end 
    14. normalise attributes in favour of transaction winner
      1.  ifelse my-bribe > ( [my-punish] of other-end )  [ 
        1. set ([ my-punish-preference ] of other-end) my-punish-preference
        2. set ([ my-bribe-preference ] of other-end) my-bribe-preference
        3. set ([ my-privacy-preference ] of other-end) my-privacy-preference
        4. set ([ my-love-of-culture-preference ] of other-end) my-love-of-culture-preference 
          1. set my-punish-preference ( [ my-punish-preference ] of other-end
          2. set my-bribe-preference ( [ my-bribe-preference ] of other-end
          3. set my-privacy-preference ( [ my-privacy-preference ] of other-end
          4. set my-love-of-culture-preference ( [ my-love-of-culture-preference ] of other-end
    15. remove old links
    16. manage asset funds i.e. move assets into the various funds according to preferences, taking care to not over-fill some funds
    17. let entropy into the world (as per slider settings):
      1. increase energy-of-patch and reduce culture and entry-cost from all patches
      2. extension: add some randomness to jolt simulation out of potential local maxima and  minima

Variables

  1. variables:
    1. agent:
      1. my-defect (boolean 0 = don't defect, 1 = defect)
      2. my-greed (energy agent tries to take from patch)
      3. my-assets (energy accrued by agent). assets are divided into funds:
        1. my-punishment-fund (fund for punishing)
          1. my-punishment-preference ( 1 - 10 )
          2. my-punishment-this-turn ( my-punishment-preference * 10 )
        2. my-bribe-fund (fund for bribing)
          1. my-bribe-preference ( 1 - 10 )
          2. my-bribe-this-turn ( my-bribe-preference * 10 )
        3. my-privacy-fund (fund for setting entry-cost-of-patch)
          1. my-privacy-preference
        4. my-love-of-culture-fund (fund for adding to culture-of-patch)
          1. my-love-of-culture-preference
      4. my-assets-available-to-invest (calculated each turn by taking n from my-assets to leave n ( which could be cost of living * risk ( 1  - 10) i.e. low risk = high score )
      1. my-number-of-agents-on-patch-here (to work out how much energy to take this turn)
      2. my-patch-with-most-energy
      3. my-patch-with-least-energy
      4. my-cheapest-patch
      5. my-agent-to-interact-with (look at agents in-radius n, look at attributes and decide which to interact with
      6. my-energy-taken-this-turn (for bribe/punish behaviours)
      7. my-love-of-culture
      8. my-popularity (reduces when punished, increases when give to culture...may effect bribe / punish )
    2. patches:
      1. energy-of-patch
      2. sustainable-energy-of-patch (how much that can be taken so as not to tip past the-energy-quota
      3. sustainable-share-of-energy-of-patch ( if any? agents set sustainable-energy-of-patch / agents-here )
      4. entrycost-of-patch (payment in assets)
      5. culture-of-patch

Interface: slides, view, graphs and monitors

    1. sliders (the numbers that I am not sure how sensitive the model is to e.g. factor that agent attributes should be changed after losing a bribe/punish interaction 
      1. number-of-agents-slider
      2. the-patch-energy-growth-rate-slider
      3. the-decay-rate-of-entry-cost-slider
      4. the-decay-rate-of-culture-slider
      5. the-energy-quota (simply the threshold at which a energy of  patch should not decline below - probably doesn't need to be a slider)
    2. monitors
      1. ****
    3. graphs
      1. histogram of agent happiness
      2. histogram of agent assets 
  1. the view (make it easy to observe):
    1. energy of patch
    2. entry-cost-of-patch
    3. how rich agents are
    4. when altruistic punishment happens
    5. when bribery happens

Extensions, questions, notes and references

  1. possible coding extensions
    1. create links only every n ticks
    2. add agent behaviours where the agent decisions change depending on local conditions e.g. conscious equilibrating decisions.
    3. the-likelihood-of-altruistic-punishment-slider ( the % of times that punishment will happen when it should NB agents can be punished by more than one agent each tick)
    4. the-sociability-of-network (how many links are made each tick)
    5. add social networks e.g. give agents dunbar endorphine release relationship networks e.g. 5, 15, 35, 150, 500, 1500 ( fractal periodicity 3 )
    6. some agents could move before others e.g. those with most energy; see difference between ask and ask-concurrent 
    7. add breeding, birth, death and learning
    8. is cognitive load an issue with respect to agents acting on environmental information
    9. add taxation to try to stop very rich agents
    10. see if social norms vary in classes e.g. agents with assets in range l-h punish with mean frequency n
    11. use the model to explore the concept of price elasticity
  2. question(s):
    1. how important is altruistic punishment?
    2. which types of agent will emerge and why, and what worlds will they create? e.g. openness of agents, will the world be over-exploited or cultured.
    3. how path-dependent is this kind of model i.e. if privatisation becomes the norm at the start, can it be counter-balanced?
    4. is it possible to create a model that other people can easily extend to put their own theories about how people behave in relation to each other and resources
  3. pedagogical notes: 
    1. build the model as a story:
      1. script 1:
        1. In the beginning there was just two people and lots of energy. 
        2. Then more people came and energy became scarce. 
        3. These people learnt to remind each other that they should each not take more than their fair share 
        4. As more people arrived it became too difficult to police consumption and some people managed to take more than their fair share. 
        5. As a solution the idea of private property was created but this created huge inequality
        6. Then people realised that the people with private properties were not as independent as they liked others to believe
        7. But it was too late, the environment collapsed, the private land owners survived, everyone else perished and the whole cycle started again.
      2. script 2:
        1. 2 agents lots of energy
        2. more agents some start dying (no assets)
        3. agents punish
        4. agents bribe
        5. agents set patch entry price and spend more time at home
        6. agents stray from home 
    2. when designing the model here it is important to fight the urge to over-complicate the implementation i.e. it is better to focus on simplification first, then build, then complicate. it is better to come up with ideas for complications when implementing as this is when modeler is thinking in details. 
    3. when building complicated micro-behaviours e.g. nested and dependent on behaviours that calculate values (see decide how much energy to take from patch) it is a good idea to use paper and pen to draw out the sub-components and conditions.
    4. a plan is ready when it is easy to see a the micr0-behaviours and the NL they would use (more-or-less). to get to this state it helps to keep looking at the MB library and the NL dictionary, and trying things out by writing commands into the NL (or writing short programs - especially true for understand NL lists and link primatives).
    5. the problem of scheduling behaviours within and between ticks especially with respect to movement and decision-making
    6. the different types of variables e.g. core and utility (knowledge about world e.g. self, other agents, patches and parameters) agent attributes, parameters and sliders (user controlled agent/world variables). these could be seen to exist in a hierarchy
    7. a plan can be analysed with certain checklists e.g. 
      1. what happens at setup
      2. what will happen when a calculation results in zero, nobody or a list 
      3. what to do when the order things happen within a tick matters
      4. different ways to debug and test
      5. if in doubt insert brackets
      6. if there's a bug or model not running as it should:
        1. check you've added enhancement
        2. write simplified code in NL and get it working
        3. paste code from modelling4all into NL to check brackets etc
        4. download code and insert show statements and write commands to check things e.g. how many agents have greed > n
        5. ...
    8. highlight idea that the names that are given to attributes are fairly arbitrary i.e. agent bribery is just one way of linking what is happening at the numerical level to an idea about society (and bribery should probably be re-cast as something else like charm, sense of status or ability to induce status anxiety)
    9. there is a stage in model design where the focus can be on making the model look good i.e. choosing appealing looking agent shapes, adjusting how things move around, colours, size of world, using 3D, getting rid of graphical noise...and all the other basic usability/aesthetics/ information visualisation techniques
    10. acknowledge that code looks like nonsense until you've tuned into the language. try to work out a nice metaphor or approach. maybe there's a way to analyse lines of code using the dictionary and some testing with NL. relating this to my own experience may be a good approach. nb programming languages are steeped in history (like every day languages) and this can be confusing.  relate this whole thing to the big idea of micro-behaviours - making your own programming language
    11. when is a model interesting?:
      1. when you are adding spatial dimensions to a pre-existing model
      2. when you are critiquing a paper in some kind of meaningful way
      3. when the results are interesting i.e. some some scenarios wildly more likely that others
      4. when it sheds light on the questions you were asking
  4. ideas for the video
    1. little jokes
      1. spell debug wrongly then correct
    2. make sketches that illustrate what i want do build roughly
    3. put words onto film and have a support web page that makes similar points
    4. discuss the variations for the MB and suggest how they can be coded
    5. discuss how attributes/parameters may change their meanings and the names given should be changed to reflect this to avoid confusion
    6. suggest how to organise development e.g.
    7. keep a diary and record each day what you've done, and what you plan to do next time
  5. references:
    1. altruistic punishment: http://www.nature.com/nature/journal/v415/n6868/abs/415137a.html 
      1. what is altruism? 
      2. behaviour that benefits the version of the environment that is least likely to harm life
      3. behaviour that benefits the most long term version of the environment
      4. behaviour that benefits the widest range of individuals 
    2. bribery
      1. Bargaining for bribes under uncertainty: http://ora.ouls.ox.ac.uk/objects/uuid:2257e3d3-733b-4712-8140-261d6ae2effa
    3. tragedy of the commons etc:
      1. http://en.wikipedia.org/wiki/Elinor_Ostrom
      2. http://www.sciencemag.org/content/162/3859/1243.full
    4. game theory
    5. similar ABMs
      1. Sugarscape (how complex are the agent decisions?)
    6. models and reality - what to leave in and what to cut out?
      1. George Box
      2. Epstein

Diary notes

10th October

Fabio sent through the COMSES 2011 Challenge which seems to fit this work very well. Increasingly it seems people are seeing ABM as a valuable communication tool. A plan would be to get something out and trial it at the John Mason school. 
  1. Put resource on patches
  2. Make resources grow 
  3. Make resource grow unevenly (gradual to extreme gradation)
  4. Get agents consuming to survive
  5. Get agents consuming and contributing culture
  6. Get some agents consuming more than their equitable share
  7. Introduce status anxiety
  8. Introduce punishment
  9. Introduce bribes
  10. Introduce privatisation
Learning objectives:
  1. It is important to understand the assumptions made about people when they are being modelled - it can make a big difference
  2. About tragedy of the commons, equity, justice, status anxiety, punishment, bribes and privatisation (sub-cultures)
  3. About the modelling4all software (as an constructionish tool)

6th October

After lots of messing around with the code described earlier in the week I made the change a patch attribute within concentric circles micro-behaviour (MB). There were lots of lessons learned in the making of this MB, how to implement input boxes, let/set statements and general code. I now want to take this forward to implement MBs that control how agents link to each other as they move around.

Earlier I implemented linking with these ideas:
  • an agent would first memorise things about the patches and agents around them
  • an agent would like to 1 or more agents depending on what they committed to memory
  • they would keep a record of who they are linked to now
  • they could keep a record of who they have linked to in the past
  • they could have a preference for linking to certain kinds of other agent
  • links would have an age so for instance they could be made to die after a specific period of time
  • agents would interact with each other based on who they are linked to
    • they would interact according to game theory experiment matrices e.g. bribe and punishment
It would be best to break this into several MBs:
  • sense local environment
    • if any? individuals with [ kind = "abc" ] in-radius n [ set my-nnn]
  • form links with 1 or more other agents
    • create-links-with n-of 1 other individuals with [ kind = "abc" ] 

4th October

Another example of setting patch attributes according to a distribution:
globals [ 
  x ;; circumference 
  c ;; patch color
  ]

to setup
  ca
  crt 1
  set x 18
  set c 20
end

to go
 ask turtle 0 [ 
   repeat x [
     ask patches in-radius x [ set pcolor c ]
     set x ( x - 1 )
     set c ( c + 1 )
   ]
 ]
ask turtle 0 [ die ]
ask patches [ set plabel pcolor ] 
end


The code can be made more succinct and flexible:
globals [ 
  x ;; circumference 
  c ;; patch color 
  ]

to setup
  ca
  set x n ;; n is a slider
  set c 20
  paint-patches-in-a-circle
  ask patches [ set plabel pcolor ]
end

to paint-patches-in-a-circle
  crt 1 [
    ;; position the centre of the circle
    set xcor up ;; 'up' is an input box
    set ycor across ;; 'across' is an input box
    ;; set color of patches starting at outer-most circumference and moving inwards
    repeat x [
      ask patches in-radius x [ set pcolor c ]
      set x ( x - 1 )
      set c ( c + 1 )
      ]
    ;; remove the coloring agent 
    die
    ]
end


This then is the basis for a micro-behaviour where 1 or more circles that set an attribute (doesn't have to be pcolor) at increments from the circumference to the center. The main point being that you can create an agent at setup and make it move around and change patch attributes. To be usable as a micro-behaviour we'd want to call it and pass in the relevant parameters i.e. circumference, color, xcor and ycor.

After discussion with Ken I am not sure about implementing my understanding of OO in the BC. The code above in can be implemented as in the create circle of colour in patches MB.

30th September

First we need to create a micro-world where a resource is available for human consumption. The resource could be distributed evenly, randomly or according to some pattern. The resource could deplete at a fixed or variable rate, deplete as consumed, or it could grow evenly or at a rate that fluctuates over time. There could also be different types of resource where agents gain utility from consumption in different ways.
  • resource distributed evenly at start, it does not grow or decline spontaneously (unless consumed)
  • resource distributed evenly, it grows at rate g in conditions c1, and declines at rate d in conditions c2
  • ...and so on
resource quantity at start (RQs)
growth-rate (gr)
depletion-rate (dr)

Patch attributes can be set according to some pattern by:
  • using patch coordinates
  • creating an agent that moves around grid and setting patch attributes
  • using geometry
Let's play with these approaches in NL:

globals [ x c ]

to setup
  ca
  crt 1
  set x 0.1
  set c 10
end

to go
 ask turtle 0 [ 
   repeat 10 [
     repeat 36 [
     fd x 
     rt 10
     ask patch-here [ set pcolor c ]
   ]
          set x ( x + 0.1 )
          set c ( c + 1 )
   ]
 ]
ask turtle 0 [ die ] 
end


29th September

After a lengthy delay I am back to thinking about the ideal chunking of MBs so that they can be both easy to understand and expressive. This will require some field work with social scientists who are new to modelling - it will be an interesting juggling act.

I have made two models while thinking about how people relate to energy (a resource) and each other (see top of the page). The question now is how to re-author these MBs so that they can be part of a more general energy and people library. A library is a super-set of a specific model so requires more careful consideration. Taking a specific example - how to model the growth of a resource. I have: 
  • initialise patch attributes
  • patches grow energy
  • set color of patch based on a patch attribute
There are many ways to do this and the BC is slightly confusing with respect to how it has to be done for the following reasons:
  • set attribute is per attribute so there's a lot of clicking to initialise the number of attributes I create in these models
  • attributes are assigned on the fly to agents but they need to be specifically assigned to patches (hence the use of ask patches or use the add-behaviours-to MB

This can all be done in one MB or broken up as is. Wrt modelling energy, the MBs could do things like:

  • distribute energy randomly
  • distribute energy according to a pattern
  • energy grows at fixed rate (controlled by a slider) and fixed range
  • energy growth rate varies according to 
    • time e.g. seasons
    • location
  • animate energy i.e. set color
  • energy moves
  • there are different types of energy
    • i.e. vary in utility (as experienced by the agents)
    • cost different amounts
It is important to:
  1. Introduce is important i.e. get people thinking in the right way about modelling energy/resource
  2. Explain any programming tricks used with a MBs e.g. how to distribute energy according to a pattern
So this really comes down to developing an easy language for people to use to build the kinds of models they are interested. How to get them thinking along the lines? Well the general class of model I am thinking about is one relating to how individuals interact within different types of energy/resource distributions. This is a tragedy of the commons problem that emphasizes modelling realistic interactions between people e.g. status anxiety, altruism etc.  Early in this diary I raised the idea of using a story to help people build ever more interesting models.

It occurs to me now that this sounds like the numerous optimisation game theory simulations. I guess this is making that math more tractable and also allowing people to model changes in strategy e.g. agents showing for-thought for instance i.e. there being agents that can stabilise systems that are at tipping points. In other words, agents are not simple self-optimisation units, more sophisticated decision-makers that inter-relate according to different societal roles. 

19th August

  • again thinking about the final model, or more specifically the model when it is running as a simulation of people interacting with resource/energy and other people. it occurs to me there are at least two types:
    • a model running with lots of agents that is essentially a data generating machine
    • a model with perhaps a few agents that interact and evolve in an easily observable way that is almost like a film script being played out i.e. agents wander, energy becomes scarce, agent behaviours polarise, battles happen, winner dominates...
  • it might be a good idea to use the ant shape instead of the circle because it rotates with direction and it is easier to empathise with animal shapes. (the person just jumps around)
  • i should look up research on the emotional intelligence that is necessary for independent learning i.e. how to stay motivated even when things move forwards very slowly
  • from a technical perspective: how about micro-behaviours that are blog posts where the comments are all micro-behaviours directly associated with the original post i.e. behaviours for moving, linking, fund-management. with respect to linking there are a large number of variations
  • can i come up with a way to crowd source model making i.e. the tools and community engagement strategy:
    • the tools i am using here
      • diary
      • pseudo-code
      • library of models e.g. the various models created with BehaviourComposer and NL that were made on the course of making the main one
      • NL and BehaviourSpace
      • Spreadsheets and other statistical tools
      • discussion forum
      • place to publish models and accompanying materials e.g. youtube, openabm, published papers
      • if you're lucky a classroom and people to arrange teaching / technical support
    • how would this relate to the social constructionist theory of knowledge i.e. truth is relative

18th August

I've noticed two trends lately:
  1. I am turning all the behaviours into raw code inserted into the generic netlogo MB - makes debugging easier
  2. I am debugging most of the time now - the easiest way to do this is download to NL and use the command center
I am doing things like working out why patch energy levels drop below 0, re-writing code to be more efficient and understandable, changing variable value ranges so that one change doesn't swamp another e.g. some agents can put others too much in debt. Somehow mathematically it doesn't feel right - its like I am making up numbers to steer the simulation in a direction...which I am not totally sure what it should be. I really need some kind of data set to tune things towards.

As I've been saying the last few days I need to turn more attention back to the original questions that are meant to underpin this model. I also need to think about how this model (and ones perhaps more directly related to the environment) can be used by researchers to communicate with policy-makers and the general public. Regarding the later I am thinking of a guide divided up into several chapters:

chapter 1
  1. patches grow energy according to some kind of energy distribution (currently random) - there are all kinds of other energy topologies I could create
  2. agents wander around looking for energy and other agents to link with (or avoid)
  3. as time ticks agents lose energy 
chapter 2
  1. if an agent takes more than the sustainable share of energy they risk being punished by another agent
  2. but the agent can bribe the punisher (so setting up a game theory matrix)
chapter 3
  1. as the agents accrue energy (as assets) they can move it into funds that can be used to punish and bribe
  2. they can also have a fund to buy patches (making the patch private)
  3. and a fund for contributing to the culture of a patch 
A number of programing tasks still remain:
  1. how can i show a patch or patches are privately owned? perhaps using the "thin ring" shape (see Halo Example in NL)
  2. how can I represent patch culture visually without masking the energy? perhaps using a button so viewer can flip between each or asking agents to either hatch a small shape
;; 
hatch 1 [ set shape "circle" set size 0.5 set color report culture-shade (my-culture / the-max-culture ) rt random 360 fd random-float 1 set my-culture n ] 
set my-culture my-culture - 1
  1. how to create a population of agents that make different choices re. movement, linking, interaction with agents, fund management, interaction with patches
As an idea I might be able to use a slider to initialise agent behaviour set points on a range between selfish to 100% altruistic e.g. using my-defect and my-greed attributes. I could even ask for the set point and variation from this mean value then create the population.  

Finally for today - a reminder how to use to-report:
to setup
;; first schedule the procedure you want to run e.g. 
  aprocedure
end

;; then define the procedure

to aprocedure

;; introduce a command that refers to a procedure e.g. "answer" and pass variable(s) to this procedure as a ;; list if required

  show answer [ 5 ]
end

;; then define this "answer" reporter remembering to give the input variables a name here e.g. " v"
to-report answer [ v ]
;; then use report primitive do to something with the variables
  report first v * first v
end

;; this program will show the number 25

17th August

To do:
change my-greed/punish/bribe to variables in range 0-8
make my-defect a variable range so that it is part of the influence behaviour
change the influence behaviour so that the difference of the abs (bribe - punish) is added/taken from my-defect and my-greed
change the manage funds so that a fund is only topped up to a maximum value of 100
add the idea that an agent can spend assets to move its defect/greed values back towards the set point it initialised with
add culture and privacy interactions between patches and agents
add attribute cloaking to agents ( another instantiation of privacy )
break up the behaviours into smaller chunks that are aggregated together
- make a range of behaviours that implement different rules (so they can be activated as desired)
think whether I need to implement life-cycles to get the desired heterogeneity and multiple stable equilibria? actually - how will I know when the model is finished...i need to return to my original question.
then i need to start simplifying and return back to the original question
more generally:
create a page on Sites that has sections for each of the main type of behaviour. 
describe the story of how each type can be used (he order). describe the conceptual range of each type e.g. the possibilities in terms of the end game. 
i think this goes back to privacy - I want to show that in an open world over-exploitation of resources wouldn't happen ( if people agreed what defecting is ) but when the information is not available defecting comes the norm. 
after re-reading the altruistic punishment paper, it is the addition of bribes to the interaction that is different. Fehr and Gachter only used punishment/no punishment. in this sense the end-game is to show this by plotting data created using the Behaviour Space.
in terms of the paper, then I should focus on saying that education is the key to tackling climate change, that the learning must focus on complexity, and that contemporary discourse over-simplifies humans when it talks about the future, we are denigrated to simplistic agents who will repeat the mistakes of the past. we after all live in a deeply right-wing and conservative world (UK/ USA etc). 
with respect to education, I could mention serious games but most of all mention constructionism. learning with graphics might also be worth emphasizing.
Thinking about the end game for the simulation - I want to generate data on: 
the types of agents that exist at different stages of a simulation run and how these population mixes correlate to the state of the environment e.g. energy and culture
i could also experiment to see how robust different states are to shock e.g. sudden reduction in energy availability

16th August

The latest model seems stable but the agent interaction behaviours ( links, bribe, punish ) quickly result in a homogenous population with respect to 'my-greed'. 

I need to come up with a way of analysing the model so that it can be more realistic and preferably evolve to a range of interesting stable states. I suspect I can do this by eye (so to speak) and then will need to use the BehaviourSpace.

15th August

First I am working on making the link behaviour more flexible/expressive. I think this means using NL primitives like max-n-of, with-max, max-one-of etc i.e. the agents are making a decision  about which other agent to link to based on an attribute such as my-assets, my-greed or even my-culture. Code examples:

;; giving agents vision and the ability to interrogate other agent's attributes gives a good start point for constructing meaningful ;; simulations of social networking e.g. replace 'in-radius n' with a vision attribute and 'color' with something like my-greed
;; NB. prefix these statement with an if any? agents...

;; turtle 0 creates a directed link to all the other turtles in the view
ask turtle 0 [ create-links-to n-of ( count turtles - 1 ) other turtles ]

;; similar to above but only in-radius 3 
ask turtle 0 [ create-links-to n-of count turtles in-radius 3 other turtles ]

;; link to 1 agent that has the highest color value 
ask turtle 0 [ create-links-to max-n-of 1 other turtles [ color ]]

;; ...lowest color value
ask turtle 0 [ create-links-to min-n-of 1 other turtles [ color ]]

;; ... in a defined radius
ask turtle 0 [ create-links-to max-n-of 1 other turtles in-radius 20 [ color ]]

Here's a finished program that asks agents to link to half of their surround agents with the highest number score within their vision:

turtles-own [ 
  number 
  vision]
to setup
  ca
  cro 20 [ 
    set shape "circle"
    fd random 15 
    set number random 100
    set vision random 9 + 1  
    ]
end

to go
  ask turtles [
    if any? other turtles in-radius vision [ 
      let n count turtles in-radius vision * 0.5
      create-links-to max-n-of n other turtles in-radius vision [ number ]
      ]
    ]
end

The question now is how to store the linked agents so that they can be used within the interact behaviour:

turtles-own [ 
  number 
  other-number 
  linked-agent 
  vision
  interaction-agents]
to setup
  ca
  cro 8 [ 
    set shape "circle"
    fd random 15 
    set number random 100
    set vision random random 9 + 1
    ]
end

to go
  ask turtles [
    if any? other turtles in-radius vision [ 
      let n count turtles in-radius vision - 1
      create-links-to max-n-of n other turtles in-radius vision [ number ]
      ]
    ifelse count my-out-links > 0
    [ set interaction-agents [ other-end ] of my-out-links ]
    [ set interaction-agents nobody ]
    if interaction-agents != nobody [ 
      show interaction-agents 
      foreach interaction-agents [ 
        ask ? [ set size 2 ] ]
    ]
  ]
  ask links [ set color red set thickness 0.2]
  
end

The program above is a good general template for simulating how agents might decide which other agents to link to at any one moment i.e. combining vision, knowledge about another agents attribute(s) (- here 'number), and then acting on the attributes of the linked agent (- here just changing the size).

The process of coding 

(This is a teaching note).  To build a model you need to move often between several tools and perform a range of tasks repeatedly i.e.
  • create a behaviour in modelling4all
  • format it in NL
  • run it in modelling4all
  • download and debug in NL
  • if stuck with creating some syntax, create a simplified version in NL then copy over to modelling4all
  • refer to NL dictionary and modelling4all programming guide
  • write notes about what you are doing somewhere (like I am here)
  • debug and test variable values in NL using the command line to query simulation (and insert show statements into code)

14th August

Very small syntax changes can completely change a model e.g. a bracket in the wrong place. To an inexperienced programmer these changes seem small but with more practice when you spot them you think ' how could I be so stupid '. What develops is a way of reading code, and parsing it into your own mental logic.

http://m.modelling4all.org/m/?frozen=Bc4hyesfZsKl2tn7xUyd55&MforAllModel=1
This code had me confused for a while: 

turtles-own [ interaction ]
to setup
  ca
  cro 20 [ fd random 12 set shape "circle"]
  ask links [ set thickness 2 set color red ]
  ask turtles [ 
    if any? other turtles in-radius 5 with [ count my-links = 0 ] [
      set interaction one-of other turtles in-radius 5 with [ count my-links = 0 ]
      create-link-with interaction ]]       
end

I can change the code to the below to use  directed instead of undirected links:

turtles-own [ interaction ]
to setup
  ca
  cro 20 [ fd random 12 set shape "circle"]
  ask turtles [ 
    if any? other turtles in-radius 5 with [ count my-in-links = 0 ] [
      set interaction one-of other turtles in-radius 5 with [ count my-in-links = 0 ]
      create-link-to interaction ]]
  ask links [ set thickness .2 set color red ]       
end


but why do I end up with agents that have 2 links? (Something to do with ask and ask-concurrent?)
Anyway, I think I should use directed links within the link micro-behaviour and write the code so that it can be easily extended to model many different forms of social interaction each step.
13th August
Pedagogic note: if things aren't working as you'd expect e.g. no influence seems to be happening - check the scheduling!!!

By downloading the model into NL and running some queries at the command line while the model is running e.g.

show count objects with [kind = "agents" and my-defect = 1]

I can quickly check various aspects of the model configuration. For instance this command shows me that by setting a random number of defectors at the start, each simulation run will vary greatly e.g. if there are none by chance. However the model currently set so that non-defecting agents quickly influence defectors to change their ways - the result of which is that defection quickly disappears (and the model is not interesting or realistic). Actually I just tested this some more and the number of defectors as the simulation runs is more to do with the fraction of them at the start compared to non-defectors. Again this is not interesting - I need to change things so that a more interesting parameter sweep occurs and the model evolves as I outlined yesterday.

Second sitting (2pm ) I just changed the interface so that agents relative asset ownership is illustrated by size (color was difficult to distinguish). Now I have the interesting situation where some agents have massively negative assets - should I kill them or is this indicative of debt...should they go insolvent instead?

To fix next time: 
  1. Agents are bunching for some reason - I assume this is because of something to do with scanning
  2. Patches are being colored blue - maybe because of the bunching. 

12th August

The big lesson of today is very small - be careful of square brackets! I spent too long working out how to change one agents attributes to be the same as an agent that it is linked:

set my-defect [ my-defect ] of [ other-end ] of one-of my-links

the documentation for 'of' and 'other-end' don't make it clear to me my 'other-end' needs to be in squared brackets. I found out though by playing with simple programs in NL:

turtles-own [ number other-number]
to setup
  ca
  cro 2 [ 
    fd random 15 
    set number random 100 
    create-link-with one-of other turtles ]
end

to go
  ask turtle 0 [ set other-number [ number ] of [ other-end ] of one-of my-links ]
  ask turtle 1 [ set other-number [ number ] of [ other-end ] of one-of my-links ]
end

I also had the annoying issue that I had named a set of variables in two ways: punish-fund and punishment-fund. Since modelling4all auto-creates variables the compiler through no errors. 

So the next step is to work out exactly what I want to happen as agents influence each other. This approach is not very interesting since it will result in a homogeneous population eventually. I want the population to evolve into one that has an interesting optimization landscape e.g. with a number of stable states, or perhaps several states that exhibit chaotic behaviour e.g. bifurcations etc.

To do next: change the influence MB so that the transaction winner subtly influences the loser attributes rather than simply over-writing them i.e. simulate a nudge rather than a complete domination.  This could be done by changing my-defect so that it is a scale and defection occurs when the value is over a tipping point i.e. 1 - 10 with defection at 5.  Or there could be an influence variable that is the factor and this could be calculated based on a population-wide norm i.e. ... 


The main thing is to think about the conference, what I need to do for it e.g. how does this model relate to the themes of the event? In particular I need to think about how extensible these behaviours are.

11th August

First some reflections on coming back to the model. 

Being able to come back to a model and fix/enhance it after a period away (when you've forgotten most of the detail or thinking behind it) is a good test of how expressive and clearly it has been designed. Because of the limitations of programming through a browser modelling4all does not make it easy to follow the logical flow of the program because of all the nested micro-behaviours and the difficulty in remembering how all the variables (attributes and parameters) are being used. I remember that just before I went away I started to use a great deal of agent attributes to get bribes/punishment working and coming back now I can't quite remember why I decided to use some of them. This amounts to saying that the program outline description above is very useful and should be encouraged in the video guides.

I am starting to see a programming skill might be to kind of relax using variables and trust that they work as you use them e.g. I created sustainable share of energy of patch variable which is calculated by looking at the parameter the-energy-quota to find how close to zero a patch energy should go, then look at how much patch energy there is, and divide this by the number of agents that are on the patch. I do not necessarily need to remember all this each time I use this variable, I just need to trust that it is what it infers i.e. how much energy an agent can take from a patch. If they take more they have defected. 

The two frozen models:
  1. http://m.modelling4all.org/m/?frozen=oWj-00xloqh1Db6LbN5m7f&MforAllModel=1
  2. http://m.modelling4all.org/m/?frozen=xgIbBe_JICWqWDWAeqhF59&MforAllModel=1 (includes bribe/punishment and subsequent changes in attributes).
I had before the break are useful, the first works, the second makes a flawed attempt at modeling bribe/punishment behaviour. I think I will start again with how I want this to work and return to the pseudocode description above.

A pedagogical note: when you get to the step of comparing and setting agent attributes then the 'log specific attributes' behaviour is very useful to make sure the model/MBs are behaving as you expect. This was particularly true of the way Cindy modeled in that we were not sure after several weeks what was going on

10th August

After lengthy break...
the latest model doesn't run because there is a problem with the MB 'change attributes after bribe/punishment'. Will be fixed tomorrow with fresh eyes.
Today I fixed the division by zero error - this was caused by me naming an agent attribute incorrectly (my-punish-preference instead of my-punishment-preference) which mean the wrongly named attribute was created on the fly (a feature of modelling4all) and set to zero.

12th July 2011

Using NL to get the hang of linking wrt this model:
links-own [ age-of-link ]

to setup
  ca
  cro 10 [ fd random 10 set color random 255 ]
   
end

to go
  ask turtles [ ifelse color > number [ set size 3] [ set size 1 ] ]
  move
  find-turtle-and-link
  links-age
  ask links [ if age-of-link >= 10 [ die ] ]
  tick
end

to move
  ask turtles [ rt random ( 30 + random -60 ) fd 0.1 ]
end
  
to find-turtle-and-link
  ask turtles [
   let n other turtles in-radius 3 with [ color > number and not any? my-links ] 
   if any? n [
      create-link-with one-of n [ 
        set age-of-link 0
        set thickness 0.2
        set color red ]]]
end

to links-age
  ask links [ set age-of-link age-of-link + 1 ] 
end

bribes and punishment:
  • add behaviours (to agent implicitly)
    • update attributes:
      • if agent is linked
      • if bribe/punish fund > n
      • if agent i am linked to takes more than energy quota
        • take bribe/punish from the bribe/punish fund of the agent i am linked to 
        • take same amount from my bribe/punish fund
          • as outlined above this works by agents having 3 attributes:
            • my-assets (as agents move about and take energy they accrue assets)
              • my bribe/punish fund ( how many assets I have available to bribe / punish, this fund is added to each tick by distributing a fraction of available assets  )
              • my bribe/preference ( how likely I am to bribe / punish represented as 1 / n where n is a number between 0 and 10 ) 
              • my-bribe/punish this turn (if decide to bribe/punish this is set to bribe/punish preference * 10
    • normalise attributes in favour of transaction winner
      • ifelse my-bribe-this-turn > [ my-bribe-this-turn ] of other-end [
        • set [my-variables... ] of other-end my-variables...
          • my variables [my-variables] of other-end
            • variables = bribe/punish/privacy/love-of-culture preference and my defect

11th July 2011

The task today has been to get agents linking and setting link attributes to break the links. An example model shows this working but we've decided to raise an enhancement request because of the non-intuitive way that the BC currently schedules the naming of prototypes. Ken's religiosity model also shows some more advanced used of links working in the BC. 

There are 3 things to remember about the example model with regards to linking:
  1. Be careful with respect to when behaviours will run for each agent - the NL ask command runs procedures/behaviours in serial for each agent - this means that if I currently do NOT delay behaviours that reference the name of a prototype (use objects of [kind = "name"] then some of the other agents may not have been given this name. This complication will be removed as per the feature request above but as a general rule it is important to consider ask-concurrent documentation
  2. Note the behaviour to set the link die attribute to true 
  3. Not the need to use the add behaviours to behaviour and change the input box to links (so that the BC knows which breeds the behaviour should be changing i.e. links/turtles/patches etc).
The example code works in the main model (which it just occurs to me needs a name).

8th July 2011

A short NL program that shows how links attributes can be created and used, but I am not sure how to do this in modelling4all yet. we might need to write some more extension code to allow attributes to be created and set on the fly as for attribute-of-patch and my-attribute.
links-own [ age-of-link ]

to setup
  ca
  cro 10 [ fd random 10 ]
end

to go
  move
  find-turtle-and-link
  links-age
  ask links [ if age-of-link <= 0 [ die ]]
  tick
end

to move
  ask turtles [ rt random 45 fd 0.1 ]
end
  
to find-turtle-and-link
  ask n-of 1 turtles [
    create-link-to one-of other turtles [ set age-of-link 5 ]
  ]
end

to links-age
  ask links [ set age-of-link age-of-link - 1 ] 
end

7th July 2011

There is a pedagogical issue here that the model description above has become so complex it is difficult to hold in memory. This makes it difficult to imagine whether it is interesting, coherent, consistent etc. One approach to dividing the implementation up into smaller chunks is to create a story script (see pedagogical section above) and use it to build the micro-behaviours. Each story chunk should contain the following elements:
  1. patches and agents
  2. some form of measurement to check the model is working as expected
  3. ...
During the build lots of new ideas will pop out - these should be recorded and parked if they are overly complicated.

10:45: started to add reproduction - how can I hatch an agent and reset some of the attributes once i.e. my-assets

Current model has reproduction (based on an assets threshold which is a little artificial). The coloring of agents is now achieved by using a list [( 255 * fraction) 0 0] which means agents are always a shed of pure red (no green/blue).

Next steps: add a histogram to watch main parameters

5th July 2011

focus on decision-making of agents e.g. how agents decide whether to punish/bribe AND how the agents will respond to environmental stimuli

4th July 2011

plan for today:
  • get all the attributes initialised and named coherently
  • transfer money from my-assets onto my-punish etc

24th June 2011

another way to model privacy would be to implement attribute cloaking (rather than allowing agents to set patch-entry-cost).

to model agent decisions based on attributes? 
  1. use the do-with-probabilities micro-behaviour e.g.
    1. based on ( my-love-of-culture / 1 ) give my-assets to culture-of-patch
  2. use add-behaviours and add-behaviour-to with conditions e.g. 
    1. if my-greed < (my-greed-of-neighbor / 2) and the-global-environment-health-monitor > my-care-score ... change agent / linked agent/ patch

23rd June 2011

So the focus needs to be in creating a pattern for coding behaviours that model agent decision-making. As is the case in the  current model - the difficulty here is deciding on sensible numbers i.e. how much my-assets would be needed to create culture, how much should culture effect agents.

One approach to this  'arbitrary numbers' problem is to let the numbers evolve in the system. This can be done by (a) letting agents breed, and the offspring have attributes that are the sum of the two parents (b) let agents effect each other's attributes during transactions. At this stage I am veering towards option B i.e. change attributes like my-love-of-culture in favour of the agent that wins a transaction e.g. if an agent successfully bribes another, then this other's attributes will be changed to resemble those of the briber.

So what might be a general schema for coding behaviours?:
if condition e.g. have enough assets to do something like bribe
and another if condition
do something e.g. bribe/punish/set entry-cost
normalise attributes between two agents in favour of the 'winner' e.g. the briber, the punisher

by normalise i don't mean make the loser's attributes the same as the winner. this might quickly emerge into a homogeneous model. i want the agents to explore the bribe/control/punishment space comprehensively.

22nd June 2011

The model so far has made me re-focus what I want to do so I have re-written the overall model description above. The general idea is to model assets (money) as an expression of power that agents can use to (a) control access to a resources (b) avoid altruistic punishment by bribing the agent dishing out the punishment (c) spend on building culture. 

The model I've been building to-date was not focused enough on an interesting question. This one gets back (I think) to understanding how an agent's attitude to openness can skew an economy. 

21st June 2011


The model I ended up with yesterday had quite a few problems because of the way parameters are scheduled. Basically the parameters were set to zero because their value was dependent on agents existing, and none were when the parameter is created. Also patch behaviours cannot be scheduled in the same way agent attributes can. These issues are fixed in this model. Now I need to get the numbers right, and think some more about how I want the model to grow from here.

18th June 2011



Plan:
  • Get more control over the simulation and explore the parameter space I have added sliders for energy growth rate (rate energy-of-patch grows) and price decay rate (so that the price to enter a patch reduces over time, allowing other agents to 'take over'.
  • Add to the model that the agent that buys a patch gets paid the money the other agents pay to enter this patch
  • Add graphing to help analyse the simulation
  • Note: (after discussion with AH) this is a difficult and distinct stage in the modelling process: analysing and deciding which route to take next. The BehaviourSpace might also be needed.
  • Just realised that I need to distinguish price of patch from a new patch attribute called 'entry cost' to distinguish buying a product/ service from taking ownership of the production of that service. To do this I will change the initialising of patch attributes to one netlogo-code MB i.e. set price-of-patch set entry-cost-of-patch.
  • I also need to get agents making decisions, perhaps based on a difference between a new attribute called my-need and changing my-greed into a factor
  • The issue of how to color the patches and agents then arises. Colors can be expressed in fractions and they are visible i.e. 64.5 is darker than 65 and lighter then 64 (and easily visible). If I concentrate on showing the entry-price of patches, and the my-cash of agents it will be easy to see what the rich agents are doing and how they have taken over the land, and who is moving into that land i.e. land that is being closed off compared to opened up. One way to do this is to find the maximum price of  a patch then paint each patch on a scale of green by: 61 + ((price-of-patch / max price x 80 ) / 10 ) this excludes the black and white shades at each of of the green scale, and should paint shades of green from 61 to 68 including decimals. The same approach can be used for the my-cash of agents although the code below needs to be changed because of the lack of breeds in the BC and the inability to replace turtles with "objects with [kind = "agent"]:
to setup
  ca
  cro 10
  ask turtles [ fd random 10 set color random 255]
end

to go
  let x first [color] of turtles with-max [color]
  show x
  ask turtles [
    set color 61 +  ( ( ( color / x ) * 80 ) / 10 )
  ]
end
  • This also raises the inevitability of a blossoming of attributes of different types e.g. ones with obvious relationships to behaviours (price) and ones that are needed to make algorithms and measurement work.
  • In general this aspect of the coding shows how to set and use a parameter to control the attribute of an agent (i.e. its color).

17th June 2011

Agent prototype
attributes:
  • control
  • cash
  • property (patch ids)
  • desire-points
micro-behaviours:
  • ( initialise attributes )
  • look at attributes of local environment e.g. surrounding patches ("sense environment")
  • receive messages from wider environment e.g. through network (even the Internet)
  • make a decision e.g. choose a patch and set heading towards it 
  • move e.g. towards a goal
  • interact with world and agents e.g. take energy/ grow wealth
  • set price to enter a patch
Patch prototype
attributes:
  • price
  • energy
  • owner (agent id)
  • shareholder (agent ids)
micro-behaviours:
  • initialise attributes
  • grow energy
  • price decay
Measurements
  • total energy in world
  • distribution of wealth across all agents
  • distribution of prices across all patches

16th June 2011

  • The latest model built using NetLogo has agents moving around, buying land and setting prices. The task now is to work out how to decompose this code into behaviours in the BehaviourComposer (BC). The guiding principles for restructuring being (a) ease of understanding the code blocks, (b) flexibility of using the blocks, (c) ease of debugging and analysing different model runs, (d) provide blocks that make it possible to easily model different related ideas, especially with respect to agent behaviours towards openness.
  • The model is basically one of agents interacting with patches to exchange energy and set prices. The simple way to do this in the BC is to use add-behaviours + condition and then use add-behaviours-to to say what to do specifically to agent and patch. I should be able to do this for each of the procedures below. (Only concern at this stage is my extensive use of the let primitive - not sure how this will map over to the BC).
turtles-own [control cash]
patches-own [energy-on-patch price ]

to setup
  ca
  crt number
  ask turtles [ set control random 9 set color control set cash 100]
  ask patches [ set energy-on-patch random 8 set pcolor 60 + energy-on-patch ]
end

to go
  grow-energy
  move
  consume
  price-land
  ask turtles [ 
    set cash cash - cost-of-living
    if [price] of patch-here > 0 [
      ask patch-here [ set pcolor price ]]
    ]
  ask patches [ 
    if price > 0 [ set price price - decay ]
    if count turtles-here > 0 and price <= 0 [ set pcolor energy-on-patch]
    ]
  tick
end

to grow-energy
  ;; patches continuously grow energy to a threshold
   ask patches [
    if energy-on-patch <= 8 [ 
      set energy-on-patch energy-on-patch + 0.1 
      set pcolor 60 + energy-on-patch]
  ]
end

to move
  ;; agents find cheapest neighboring patch and move to it if they have enough cash
  ;; extensions: 
  ;; find the patch with the best energy to price ration
    ask turtles [
      let x first sort [price] of neighbors
      face one-of neighbors with [ price = x ]
      if x <= cash [ fd 1 ]
  ]
end

to consume
  ;; agents take energy according to their control, only limited by the energy available on the patch
  ask turtles [
    let energy [energy-on-patch] of patch-here 
    let c control
    ifelse energy >= control   
    [
      set cash cash + energy
      ask patch-here [ set energy-on-patch energy-on-patch - c ]
      ]
  ;; the finite earth view of the world i.e. can't take more energy than there is on a patch
      [
        set cash cash + energy 
        ask patch-here [ set energy-on-patch energy-on-patch - energy ]
        ]
    ]
end

to price-land
  ;; turtles can put a price on land
  ;; extensions:
  ;; set price a multiplier of control
  ask turtles [
    let p [price] of patch-here
    let c control
    if cash >= p [
      set cash cash - p 
      ask neighbors [ 
        set price price + c ]
        ]
  ]

end
On thinking about this for a bit it seems that I can categorise the types of behaviours needed to model interaction between people and their environment, perhaps like this:
  • movement (and link to other agents)
  • sense the environment (patches and other agents)
  • make a decision (based on algorithms that work on attributes (of agents, patches etc))
  • interact according to decision
  • ...then back to move/link which are just ways of deciding what the next ream of sense data will be, the next decision, the next interaction
or something like this. Point being this could serve as a process for stepping through when designing models, and improving them to be ever more complex yet simple.

It has also occurred to me that openness/control is only one aspect that needs modelling with reference to the open to change project. The other is responsiveness of agents to environmental parameters...which is another type of openness. 

15th June 2011

  • The quick way to explore the role of agents buying patches is: ask patches in-radius 3 [ set pcolor red ] which does not look as nice as putting a circular transparent agent over the patches (especially where I can allude to a wall around the patches using the ring shape in halo example. 
  • To ask agents to look at an attribute (e.g. energy-of-patch) in all the neighboring patches I can do something like:  let x (list [energy-of-patch] of neighbors) but this only gives me a list of variables, I need the coordinates of the patches too (so I can move to one of the patches based on the variables).
  • Teaching note: Lists are perhaps a really good example of where programming is a lot harder than writing pseudocode i.e. it is very easy to say "i want agent to move to its neighboring patch which has the most energy" but, at least when you are learning to code, this is a hard thing to work out how to write in NL (using the programming guide and dictionary). This is perhaps where the BC comes into its own i.e. by making useful MBs people can think at a higher level.
  • Here's some clunky looking code that is starting to do what I want:
turtles-own [greed wealth]
patches-own [energy-of-patch price ]

to setup
  ca
  crt number
  ask turtles [ set color red fd random 15 set greed random 9 set wealth 0]
  ask patches [ 
    set energy-of-patch random 9 
    set pcolor 60 + energy-of-patch ]
end

to go
  move
  eat
  grow-energy
  own-land
  tick
end

to move
  ;; turtles find cheapest patch
    ask turtles [
    let x sort [price] of neighbors
    let y first x
    face one-of neighbors with [price = y]
    fd 1
  ]
end

to eat
  ;; main thing here is not to take more energy than there exists on a patch (hence the ifelse)
  ask turtles [
    let energy [energy-of-patch] of patch-here 
    let g greed
    ifelse energy >= greed [
      set wealth wealth + energy
      ask patch-here [ set energy-of-patch energy-of-patch - g ]]
      [set wealth wealth + energy 
        ask patch-here [ set energy-of-patch energy-of-patch - energy ]]
    ]
end

to grow-energy
  ;; patches keep growing energy to a threshold
   ask patches [
    if energy-of-patch <= 9 [ 
      set energy-of-patch energy-of-patch + 0.1 
      set pcolor 60 + energy-of-patch]
  ]
end

to own-land
  ;; when rich enough turtles can put a price on land
  ask turtles [
    if wealth >= 200 [
      ask neighbors [ set price price + 200 ]
      set wealth wealth - 200 ]
    ]
end

10th June 2011

With the basic model now working I can start listing basic agent (and patch) behaviours and attributes:

agent:
  • decide to buy land
  • set access price
  • set access rule
  • decide to access
  • pay access fee
  • take amount of energy
  • allow self to be effected by neighboring agents (e.g. ostentatious wealth or humility) so decide to spend

9th June 2011

The issues were caused with a bug in the new 'remove enhancement' micro-behaviour functionality. After re-making the behaviours I now have a model that works as expected. I also received a reply from the netlogo yahoo group from JL that gives me a cunning solution to report all the patches under a symmetrical shape like a circle. I still find it surprising that a more general reporter is not available since this is something that the eye can see easily but NL cannot report easily, especially if the agent was an irregular shape like a star:

It is not difficult to get the agentset of all patches whose center is inside a circle. You would use the `in-radius` primitive. In the context of a turtle whose circular shape goes all the way to the edge of the shape editor grid, you might use a reporter like this:

to-report patches-within  ; by turtle, agentset of patches covered by me
  report patches in-radius size / 2
end

I just tested this and it does give some strange results:

crt 1 [ set size 4 set shape "circle" set color lput 150 extract-rgb color fd 10]
ask turtle [show count patches in-radius size / 2]

 Size of circle Number of patches
 1  1.5
 2  5.5
 3  14
 4 25.5
 5  39.5

...easily solved by (size / 2) but I could not get this code working in a NL model i.e. using to-report/report. I think I will take the other approach of simply enabling agents to take ownership of patches and so exert some control over access to these patches.

8th June 2011

  • The reply from Ken via the modelling4all discussion group helped me better understand the problem I faced with getting the agents to interact with patches (taking and losing energy respectively). This has been partially solved in this model by separating out the two statements using two add-behaviours-to MBs and referring to what needs to happen to the agent with "self" and the patches with "patch-here". However the problem still persists - how can I do the NetLogo equivalent of: if [energy-of-patch] of patch-here >= 0 [ "add energy to agent / take energy from patches"]
  • Moving on from this issue for a while. I also need to work out how to make agents avoid or pay to enter areas that other agents buy. One way to do this would be to create a transparent agent of a certain size, then set the attributes of all the patches under that agent. This approach doesn't seem to be possible since there are no NL reporters to return all patches under an agent i.e. including those under the edge of the circle. I have asked the main NL support list to see if this is true (and if they can suggest other approaches). 
  • An obvious other approach to create a nice-looking (circular) piece of land that has specific attributes is to use some cunning code that asks specific patches around an agent to change color and set some attributes. It would be easiest to do this with square pieces of land.
  • Yet another approach might be to simple change the neighbors of a specific patch a certain colour and set some attributes. Other agents that enter these patches pay the tax, once a certain threshold is reached these patches can turn neighbouring patches into part of this land. THIS APPROACH SEEMS EASIEST AND THE BEST FIT WITH EXISTING NL PRIMITIVES. 

7th June 2011

  • http://m.modelling4all.org/m/?frozen=WNcd10cuEY08g3a9jZ7M67&MforAllModel=1
  • There is a problem with putting behaviours onto all patches - this snapshot only implements agent interaction with the central patch for some reason
  • Need to get the numbers right so that agents don't take too much or too little energy from patches
  • In the NetLogo code library the Halo Example model has some useful code in terms of building the barriers. Essentially you can create an agent with shape "thin ring" and get it to follow an agent by forming an invisible link with it. The radius, thickness and hue of the ring could be based on attributes that are changed as this 'land' prototypical agent interacts with other people agents.
  • Ideas: 
    • To implement the barrier idea agents could drop an anchor (when rich enough) which becomes the center for a circle to be drawn. To enter the circle all agents would have to spend some assets (a tax) which would increase the size of the circle (in intervals). 
    • The circles could also have other properties e.g. exclude based on more than just willingness to pay with assets e.g. other properties of the agents
    • The agents could also spend money to move the anchor point towards areas with more sugar
    • Agents could also spend money to attack the circle
    • The circles would whither automatically with time (and so disappear if they don't collect sufficient assets from agents)
    • Generally this is a model of the economy which is entirely focused on controlling access to resources
    • If agents bounce off the barriers then this would simulate how barriers can occlude access (e.g. monopoly)
  • Implementation idea:
    • when assets > threshold [ create a transparent circle e.g. hatch 1 [ set color lput 64 extract-rgb color set shape "circle" set size 11]]
    • get all the patches that the circle is on and create/set a patch attribute 'entry-cost'
    • then agents can move about and decide whether they want / can enter patches as they get partitioned by rich agents grabbing land
    • if they pay the tax the reserves of the land increase (on the transparent agent)
    • as time ticks past the reserves could automatically decline
    • the founding agents could decide to restrict entry to the patches under the transparent agent on other criteria too e.g. if they are members of other land which has restrictive practices (economic bonsai idea)
    • (made a practice nlogo model to try out some of the ideas above)

6th June 2011

  • Model was lost due to something about a specific MB (it just won't load past a specific point in the history any more). Ken is investigating.
  • Found bug with set world size MB (only works once model is downloaded)
  • Lots of problems with initiating and adding behaviours to patches (using "add behaviour to" MB)
  • Added the log patch attributes MBs that Ken created