user5766716
user5766716

Reputation:

netlogo: make turtles stop if a condition (patch variable value) is met

I'm trying to program turtles finding jobs. They are separated in age groups.

The patches are the jobs, with two variables called "salary-here" and "hours-worked" generated randomly.

I'm trying to make my turtles (people) to stop moving (looking) when they find the patch (job) with the highest salary-here/hours-worked, but they always keep moving.

patches-own
[salary-here       ; amount of salary paid in one specific job (patch)    
hours-worked      ; time working and leisure
reward-ratio      ; ratio between salary and hours ]

turtles-own [age]

to search-job     ; they can only find jobs according to age "zones"
if age = 1 [ move-to one-of patches with [ pxcor > 10 and pxcor < 40 ] ]
if age = 2 [ move-to one-of patches with [ pxcor > 40 and pxcor < 70 ] ]
if age = 3 [ move-to one-of patches with [ pxcor > 70 and pxcor < 100 ] ]
end

to go  
ask turtles [ search-job ]
ask turtles [ keep-job ]
tick
end'

The idea is to: keep-job (stay in patch) if condition (reward-ratio is maximum in the surrounding area), if not, search job.

Thanks in advance for any help.

Upvotes: 2

Views: 868

Answers (1)

mattsap
mattsap

Reputation: 3806

The idea is to not move a turtle if they should stay.

In your go,

ask turtles with [should-stay = false] [search-job]

I would then write a function called should-stay and insert your stay logic there.

to-report should-stay
   report [reward-ratio] of patch-here >= max [reward-ration] of neighbors4
end

There are alternative ways which include storing a turtle variable that could help improve speed if performance is an issue.

Upvotes: 2

Related Questions