Search code examples
netlogomoveprocedure

how to make turtles who satisfy a condition move with NetLogo


I'm currently working on a project with NetLogo. Long story short: I have a certain number of turtles spread across the first half of my world. The objective is to make the turtles move on the other half of the world if they satisfy a certain condition (a mathematical one). The problem that i'm ecountering is that I want just the turtles who satisfy the condition to move to the other half (so I assume it will be a subgroup of turtles whom dimension will depend on which value of "free income" I select through the slider), but in reality what happens is that if at least one of them satisfy the condition then ALL the turtles move. That's not what I want. I was thinking to use the function "breed" but I am not sure how to implent it. Here is the code :

globals
[
  lazyness-coefficient 
  fatigue-of-work     ; cost associated with looking for work and the activity of working
  free-income
  working-income
]


turtles-own
[
  condition                       ; condition = 1 if the subject works, 0 if the subject is unemployed
  utility-value-working-income    ; utility associated with working or being unemployed while receiving a subsidy
  utility-value-free-income
]



;;;
;;;
;;;

to setup
  clear-all
  set free-income free-income-slider       ; mettere slider
  set working-income working-income-slider ; mettere slider
  setup-turtles
  setup-patches
  reset-ticks
end

to setup-patches
  ask patches [ set pcolor black]
end

to setup-turtles
 create-turtles 500
  [
    set shape "person"
    set color green
    set size 1.5
    set condition 0
    setxy random 64 random 32
    set utility-value-free-income free-income ^ 2 + free-income + random-float 1000
    set utility-value-working-income 0
  ] 
end

to go
  let target any? turtles with [utility-value-free-income > 14000]
  if utility-value-free-income > 14000
  [move-target]
end

to move-target
    setxy random 64 random 64
    set color blue 
end

The condition in this case is the following: If the turtle has an utility value (which is of the type: x^2 + x + r, where r is a random factor) higher than 14000 then set color blue and move to the other half. This condition is just a try, in the final project the condition will be: if the ration of the free income utility and the working income utility is higher than 1 then move to the other half and set the colour of that particular turtle blue.

I hope I have explained it clearly, thanks everybody.


Solution

  • You're making it too complicated. The Ask keyword allows you to specify a filter.

    to go   
      ask turtles with [utility-value-free-income > 14000]
      [
        setxy random 64 random 64
        set color blue   
      ] 
    end
    

    should do the trick.