healthy and nonhealthy food choice

healthy and nonhealthy food choice preview image

This model is seeking new collaborators — would you please help?

1 collaborator

Tags

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.4.0 • Viewed 66 times • Downloaded 5 times • Run 0 times
Download the 'healthy and nonhealthy food choice' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

patches-own[
  healthy ;healthy price food in the market
  unhealthy ;; unhealthy price food in the market, unhealthy is half price of healthy
]

turtles-own[
  metabolism ;;indicate when turtle must to go to shopping
  budget ;; indicate how much money turtle has to spend in food, it has a time basis, t is a kind of wage
  food-preferences ;;indicate what kind of food the agent prefers, healthy or unhealthy
  thealthy ;; keep track of the type of healthy food consumed
  tunhealthy ;; keep track of the type of unhealthy food consumed
  tdistance ;; keep track of the recorred distance
]

to setup
  ca
  buildmarkets
  reset-ticks
  crt num-turt [
    set color white
    set shape "person"
    set metabolism 10
    set budget earnings ;; set budget based on slider with earnings
    set food-preferences random 2 ;; 0 healthy, 1 unhealthy
    set thealthy 0
    set tunhealthy 0
    set tdistance 0
    set xcor random-xcor
    set ycor random-ycor
  ]
end 

to buildmarkets
  ask patches [
    ;;the food price is defined as the 3% of the max wages (1000), healthy food price is twice unhealthy food
    if pxcor > 10 and pxcor < 14 and pycor > 10 and pycor < 14
      [set pcolor green
       set healthy 6]
    if pxcor > 4 and pxcor < 8 and pycor > 10 and pycor < 14
      [set pcolor red
       set unhealthy 3]
    if pxcor > -2 and pxcor < 2 and pycor > 10 and pycor < 14
      [set pcolor green
       set healthy 6]
    if pxcor > -8 and pxcor < -4 and pycor > 10 and pycor < 14
      [set pcolor red
       set unhealthy 3]
    if pxcor > -14 and pxcor < -10 and pycor > 10 and pycor < 14
      [set pcolor green
       set healthy 6]
    ;;down line
    if pxcor > 10 and pxcor < 14 and pycor < -10 and pycor > -14
      [set pcolor red
       set unhealthy 3]
    if pxcor > 4 and pxcor < 8 and pycor < -10 and pycor > -14
      [set pcolor green
       set healthy 6]
    if pxcor > -2 and pxcor < 2 and pycor < -10 and pycor > -14
      [set pcolor red
       set unhealthy 3]
    if pxcor > -8 and pxcor < -4 and pycor < -10 and pycor > -14
      [set pcolor green
       set healthy 6]
    if pxcor > -14 and pxcor < -10 and pycor < -10 and pycor > -14
      [set pcolor red
       set unhealthy 3]
  ]
end 

to go
  ;; just to watch what is going on
    if sum [metabolism] of turtles = 0
      [stop]
  wandering
  hungry
  ;; every 180 ticks turtles get paid, this is 45 times turtles go to shop,
  ;; the price is 45 * 4.5 (average of food prices) equal to 202
  ;; check that is not the first tick (= 0)
  if ((ticks mod payday = 0) and (ticks != 0))
    [wagepay]
  tick
end 

to wagepay
  ask turtles [
    set budget budget + earnings ;; budget refilled beacause of payday
  ]
end 

to wandering
  ask turtles [
    if metabolism > 0
    [
      set heading random 361 ;; move random
      fd 1
      set metabolism metabolism - 1 ;;lose metabolism
      set tdistance tdistance + 1
    ]
  ]
end 

to hungry
  ask turtles[
  if metabolism > 0 and metabolism < hungry-threshold
    [ set color yellow
      ;; search for the more nearest store healthy and unhealthy
      let nearstoreh searchstoreh
      let nearstoreun searchstoreun
      ;; decide if eat healthy or unhelthy based on distance, preferences and budget
      let store eatchoice nearstoreh nearstoreun
      ;; face to the winner store
      face store
      ;; go to store
      fd distance store
      let ldistance (distance store)
      set tdistance round tdistance + ldistance
      buyfood
    ]
  ]
end 

to buyfood
  let price ([healthy] of patch-here + [unhealthy] of patch-here) ;; get price from patch
  if budget > price
    [set budget budget - price ;;spend budget on food
     set color white
     let foodpatch ([pcolor] of patch-here) ;; read patch colour
     ifelse (foodpatch = green)
      [set thealthy thealthy + 1 ;[healthy] of patch-here ;; set variable to sum kind of food bought
      set metabolism (metabolism + 2) ;; metabolism recovery and get 2 more for healthy food
      ]
      [set tunhealthy tunhealthy + 1;([unhealthy] of patch-here)
       set metabolism (metabolism + 1)
      ]
    ]
    ;[
    ;  set food-preferences 1
    ;]
  setxy random-xcor random-ycor ;;all turtles after buying go to a random spot
end 

to-report eatchoice [vnearstoreh vnearstoreun]
 ;; check preferences, by now it is only a boolean property, in a future version could be modified by network
 ;; check budget, if it is half of it then turtle buys cheap food (unhelathy) otherwise expensive food (healthy)
 ;; check distance to both closest stores, less distance i better
 ;; each property add 1 point, based on added points the turtle choice between healthy or unhealthy
 let sumchoiceh 0
 let sumchoiceun 0
 ifelse food-preferences = 0
   [set sumchoiceh sumchoiceh + 1]
   [set sumchoiceun sumchoiceun + 1]
 ifelse budget > (earnings / 2)
   [set sumchoiceh sumchoiceh + 1]
   [set sumchoiceun sumchoiceun + 1]
 ;; by pitagoras i get the distance sqr((mindthY - ycor)2 + (mindthyX - xcor)2)
 let ycort ycor ;; coord y from turtle
 let xcort xcor ;; coord x from turtle
 let ycorh [pycor] of vnearstoreh ;; coord y from closest healthy store
 let xcorh [pxcor] of vnearstoreh ;; coord x from closest healthy store
 let disth sqrt((ycorh - ycort) ^ 2 + (xcorh - xcort) ^ 2) ;; distance from turtle to closest healthy store
 let ycorun [pycor] of vnearstoreun ;; coord y from closest healthy store
 let xcorun [pxcor] of vnearstoreun ;; coord x from closest healthy store
 let distun sqrt((ycorun - ycort) ^ 2 + (xcorun - xcort) ^ 2) ;; distance from turtle to closest unhealthy store
 ifelse disth < distun
   [set sumchoiceh sumchoiceh + 1]
   [set sumchoiceun sumchoiceun + 1]
 ifelse sumchoiceh > sumchoiceun
   [report vnearstoreh]
   [report vnearstoreun]
end 

to-report searchstoreh
  ;; search for a food store
  let healthystores patch-set patches with [healthy > 0]
  let mindisth min-one-of healthystores [distance myself]
  report mindisth
end 

to-report searchstoreun
  let unhealthystores patch-set patches with [unhealthy > 0]
  let mindistun min-one-of unhealthystores [distance myself]
  report mindistun
end 

There is only one version of this model, created about 1 month ago by Diego Díaz Córdova.

Attached files

File Type Description Last updated
healthy and nonhealthy food choice.png preview Preview for 'healthy and nonhealthy food choice' about 1 month ago, by Diego Díaz Córdova Download

This model does not have any ancestors.

This model does not have any descendants.