The situation is straightforward: there are some turtles, producers, and others, choosers. Producers produce a product with a certain objective quality. Choosers choose based on their perceived quality.
Perceived quality is a function "quality-of-product-of-producers - beta-of-chooser", where beta is an individual adaptive variable. All these variables are turtles-own, and they all own them (at each round, roles are switched).
So, choosers will select the best product with a max-one-of
, based on their perceived quality (that is why beta has to be the value of the choosers).
Here's how the code is working (also thanks to Stack user @Luke C):
turtles-own [ group product-quality beta perceived-product-quality]
to setup
ca
resize-world 0 5 0 5
set-patch-size 40
ask patches [
sprout 1 [
set group one-of [ "producers" "choosers" ]
]
]
ask turtles [
ifelse group = "producers" [
set product-quality random 500 + 500
set beta random 200 + 100
set color red
] [
set product-quality random 50 + 50
set beta random 20 + 10
set color blue
]
]
reset-ticks
end
to choose-best-moore
let current-choosers turtles with [ group = "choosers" ]
ask current-choosers [
let current-producers ( turtles-on neighbors ) with [ group = "producers" ]
ifelse any? current-producers [
let turtle-with-highest-perceived max-one-of current-producers [ perceived-target-value myself ]
]
end
to-report perceived-target-value [ from-who ]
let target-product-quality product-quality
let target-perceived-quality ( target-product-quality - [beta] of from-who )
report target-perceived-quality
end
So far, so good. Now, I'd like the following thing to happen.
I introduced two kinds of producers: t-producers and f-producers. Choosers always choose based on “perceived-product-quality”. However, for t-producers, there is no “minus beta”, because they are trustworthy, so “product-quality = perceived-quality”.
How can I make choosers select the product with the highest perceived quality, but in one case, there is “- beta” and not in the other?
Thank you!
Currently, in my model, this process is twofold. First, choosers select the best product from t-producers, then select the best product from f-producers, compare the two and pick the highest. However, this has problems because it requires at least one type of producer in the neighborhood. How can I do it? Is there a simpler way?
The way you are doing it, getting two different values and comparing those two in the end, does work and there is not really anything wrong with it. The only problem you had was that you would need to check which ones are present before trying to do anything else with them.
if any? turtles with [group = "producers" and trustworthy? = true] [ ...]
A more elegant solution is probably to shove the condition into the reporter instead. An ifelse
inside the reporter, evaluating the trustworthyness of the producer who is being assessed, can allow you to decide whether or not to detract beta from the product quality
to-report perceived-target-value [ from-who ]
let target-perceived-quality FALSE
ifelse trustworthy? [
set target-perceived-quality product-quality
][
set target-perceived-quality product-quality - [beta] of from-who
]
print (word "actual quality: " product-quality " , beta: " [beta] of from-who " , perceived quality: " target-perceived-quality " , trustworthy?: " trustworthy?)
report target-perceived-quality
end
I've also taken the liberty of changing your code a bit so that it now uses breeds instead of groups. I personally feel like it is much easier and cleaner to work with those. It also let me remove a few of your local variables
You can still let them change their breed every round, using set breed choosers
and set breed producers
.
breed [choosers chooser]
breed [producers producer]
turtles-own [beta product-quality trustworthy?]
to setup
ca
resize-world 0 5 0 5
set-patch-size 40
ask patches [
sprout 1 [
set beta random 20 + 10
set product-quality random 500 + 500
set trustworthy? one-of [true false]
]
]
ask turtles [
ifelse random-float 1 < 0.5 [
set breed producers
set color red
] [
set breed choosers
set color blue
]
]
reset-ticks
end
to choose-best-moore
ask choosers [
if any? producers [
let turtle-with-highest-perceived max-one-of producers [ perceived-target-value myself ]
]
]
end
to-report perceived-target-value [ from-who ]
let target-perceived-quality FALSE
ifelse trustworthy? [
set target-perceived-quality product-quality
][
set target-perceived-quality product-quality - [beta] of from-who
]
print (word "actual quality: " product-quality " , beta: " [beta] of from-who " , perceived quality: " target-perceived-quality " , trustworthy?: " trustworthy?)
report target-perceived-quality
end