Search code examples
complexity-theorynetlogomodelingagent-based-modeling

Netlogo business model code in Chapter 10. 4 of Railsback and Grimm, Agent-based and Individual-based models


I am trying out examples from the book by Railsback and Grimm (Agent-based and individual based modeling). I have coded a business model in using the instructions from chapter 10.4. I can successfully setup the model however when I click on the go button, I get an error

 "this code can't be run by a patch
 error while turtle 3 running UTILITY-FOR
     called by procedure REPOSITION
     called by procedure GO
     called by Button 'go'"

This is my code

patches-own
 [
  annual-profit
  business-risk
 ]

turtles-own
 [
  wealth
 ]
to setup
 clear-all
 ;initializing the profit
 ask patches 
  [
   set annual-profit random 1000
   set business-risk 1 - risk-probability
   set pcolor scale-color green annual-profit 0 1000
  ]
 crt 5 ; created five business spots for test
  [
   setxy random-xcor random-ycor
   set shape "house"
   set color red
   set wealth random 10000]
   reset-ticks
end

to go
  ask turtles [reposition]
  tick
end

to reposition
  let potential-destinations neighbors with 
  [not any? turtles-here]

  ;adding the current patch to the potential-destinations
  set potential-destinations
    (patch-set potential-destinations patch-here)
 ; Identify the best one of the destinations
  let best-patch max-one-of potential-destinations
  [utility-for myself]

  ;Now move there
  move-to best-patch
 end

to-report utility-for [a-turtle]
  ; a patch-context reporter that calculates utility
  ; for turtle "a-turtle" in this patch
  ; first get the turtle's wealth

  let turtles-wealth [wealth] of a-turtle
  let profit [annual-profit] of patch-here
  let risk [business-risk] of patch-here

 ; then calculate turtles's utility given its wealth and
 ; relevant variables
   let utility ( turtles-wealth + profit * 5 ) * (risk ^ ticks)

   report utility
 end

Solution

  • Change

    let profit [annual-profit] of patch-here
    let risk [business-risk] of patch-here
    

    to

    let profit annual-profit
    let risk business-risk
    

    hth