Reputation: 806
I am trying to build a network with good and bad turtles, in order to study their actions (do-well, do-wrong, do-nothing). Good turtles may be susceptible, infected, or selfish; bad turtles only infected, instead. At each tick, other turtles (goods and bad) are created. When the simulation starts, each turtle can (randomly) decide to do something good, bad or just nothing based on its neighbours.
My approach to write the part of code regarding the turtles' actions is the following:
This is the part of code that I have written trying to answer this question:
ifelse one-of goods with [any? link-neighbors] ;; check neighbours and decide action to take
[ ifelse out-link-neighbors with [infected? true] ;; if neighbor is infected, it should have three options: do-well, do-wrong, do-nothing.
[
ifelse random-float 1 < probability
[do-well][do-wrong]
] ;; but there should be another possible action, do-nothing... and maybe I should use an if condition with probability split in 0.3, 0.4, 0.3 for example
[
ifelse random-float 1 < probability ;; this if condition is for turtle linked with only good turtles
[do-well][do-nothing]
]
] [ifelse random-float 1 < probability [do-well][do-nothing]]
but I understand that this code cannot work due to errors, so I would like to ask you what I am doing wrong and, eventually, if you could explain me why.
(If you need to edit the probability, in order to show me how I could set three different options/actions in an if/ifelse condition, please do that. I used probability as an example on what I am trying to do)
Upvotes: 0
Views: 150
Reputation: 17678
You have lots of problems.
ifelse one-of goods with [any? link-neighbors]
makes no sense. Your description says that you want to choose a random turtle. This doesn't choose a turtle, it checks whether a random turtle has any neighbours. But it doesn't then use that same turtle for any of the code that follows.So I made some guesses and here's one possibility. Of course, it is untested as I haven't built a model with 'goods' or a network etc. Hopefully it will help you work out what you want and how to do it.
ask one-of goods ; select a random turtle
[ ifelse [any? link-neighbors] ; check if it has neighbours
[ let choice one-of out-link-neighbors ; pick one of the available neighbours
[ let roll random-float 1 ; get a random number
ifelse [infected?] of choice
; condition if the chosen neighbour is infected
[ ifelse roll < probability1
[ do-well ]
[ ifelse roll < probability1 + probability2 [do-wrong] [do-nothing] ]
]
; condition if the chosen neigbour not infected
[ ifelse roll < probability1
[do-well]
[do-nothing]
]
]
]
[ print "No neighbours to select" ]
]
Upvotes: 2