Expected Command - netlogo

I think this is an error somewhere in my brackets, but I am not sure where this error is located.
to feed
let prey one-of humans-here
if prey != nobody [
[ifelse random-float 1 <= zombie-victory-probability
ifelse random-float 1 <= conversion-probability
[ ask prey [ convert ] ]
[ ask prey [ die ] ]
[ die ]
]]
end

Hard to say for sure as I can't test without seeing your setup code, but maybe like this?
to feed
let prey one-of humans-here
if prey != nobody [
ifelse random-float 1 <= zombie-victory-probability
[ ifelse random-float 1 <= conversion-probability ; option a1
[ ask prey [ convert ] ] ; option b1
[ ask prey [ die ] ] ; option b2
]
[ die ] ; option a2
]
end

Related

add another turtle's id to another turtle's attribute

In the model below, a bank can only fund customers with a credit score that matches the scores in their acceptable_scores attribute. and if it doesn't match any of the banks acceptable_scores it is rejected.
globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
list_of_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set list_of_customers []
]
reset-ticks
end
to go
ask one-of banks [
fund-loan
reject-loan
]
tick
end
to fund-loan
let person one-of customers-here with [
(member? credit_score [acceptable_scores] of myself)
]
if person != nobody [
ask person [
set status "funded"
]
set list_of_customers lput person list_of_customers
]
end
to reject-loan
let person one-of customers-here with [
(not member? credit_score [acceptable_scores] of myself)
]
if person != nobody [
ask person [
set status "funded"
]
set list_of_customers lput person list_of_customers
output-print list_of_customers
]
end
I want to add each funded customer to the list_of_customers after funding here:
set list_of_customers lput person list_of_customers
but the list is always empty when printed out. What is the right way to add another turtle's id to another turtle's attribute? In general, is this the best way to handle the funding and rejection procedures? Can it be done in one function?
Here is a pared-down version of your model using agentsets. The bank behavior may not be just what you want, but it should get you started.
globals [
scores
]
breed [ customers customer ]
breed [ banks bank ]
customers-own [
loan_amount
credit_score
status
]
banks-own [
acceptable_scores
my_customers
]
to setup
clear-all
ask patches [ set pcolor 8 ]
set scores n-values 10 [random 900 + 10]
create-customers 100 [
set loan_amount random-exponential 20000
set credit_score one-of scores
set status "applied"
]
create-banks 10 [
set acceptable_scores n-of (random 3 + 1) scores
set my_customers no-turtles
]
reset-ticks
end
to go
ask banks [
fund-loan
]
ask banks [ show my_customers ]
tick
end
to fund-loan
let person one-of customers-here
ifelse (member? [credit_score] of person acceptable_scores) and ([status] of person != "funded") [
ask person [
set status "funded"
]
set my_customers (turtle-set person my_customers)
]
[
ask person [
set status "rejected"
]
]
end

what is wrong with the way I am coding the probability of surviving?

I'm trying to create a model in which turtles move through a landscape and each type of patch means a different probability of survival for the turtles (representing patches that have more resources = higher chance of survival, patches with less resources = lower chance of survival).
However, all my turtles die out super quickly and don't seem to be following the differences in the probability of survival.
The only thing I have identified is that only if they are in a patch with probability of survival = 1, they survive. If not (even if the probability is .96), they die.
The probability of survival that each type of patch represents is determined by a slider.
extensions [
gis
palette
]
patches-own [
TipoRaster
tipoDeUso
**probSupervivencia**
]
breed [bichos bicho]
to go
if not any? turtles [stop]
if ticks = 120 [stop] ;; representa un ciclo de vida de las hembras adultas (donde cada tick = 1 dia). ***180
ask turtles [
**move
if random-float 1.00 > probSupervivencia [die]**
]
tick
end
to initHabitat
if Habitat = "bichos" [
ask patches with [ tipoDeUso = "Urbano" ][
set probSupervivencia probabilidad-supervivencia-urbano
]
ask patches with [ tipoDeUso = "Nada" ][
set probSupervivencia probabilidad-supervivencia-nada
]
ask patches with [ tipoDeUso = "Bosque" ][
set probSupervivencia probabilidad-supervivencia-bosque
]
ask patches with [ tipoDeUso = "CuerposDeAgua" ][
set probSupervivencia probabilidad-supervivencia-agua
]
ask patches with [ tipoDeUso = "Pastizal" ][
set probSupervivencia probabilidad-supervivencia-pastizal
]
if calidad-matriz = "actual" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" ][
ifelse random-float 1.00 < 0.32 [ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja ][ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta ]
]
ask patches with [ tipoDeUso = "AgriculturaRiego" ][
ifelse random-float 1.00 < 0.63 [ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja ][ set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta ]
]
]
if calidad-matriz = "alta" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" or tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta
]
]
if calidad-matriz = "baja" [
ask patches with [ tipoDeUso = "AgriculturaTemporal" or tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja
]
]
if calidad-matriz = "contrastante" [
ask patches with [ tipoDeUso = "AgriculturaTemporal"][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-alta
]
ask patches with [ tipoDeUso = "AgriculturaRiego" ][
set probSupervivencia probabilidad-supervivencia-agricultura-calidad-baja
]
]
]
end
**to move**
if random 100 < 10 [move-to one-of patches in-radius (tasa-movimiento / longitud-step)]
end
Can anybody figure out what it is I am doing wrong?
Your agents need to inquire about the patch they occupy.
Something like
ask turtles [
if ([probSupervivencia] of patch-here < random-float 1.00) [die]
]

going to target and home within one tick

I want my turtles to go to a target and go home again (using fd) within the time period of one tick. The model works fine when I execute the go procedure one by one ("go once"). Execution as a loop (without altering the code), however, doesn't work: The turtles don't move; the tick counter is updated though. It seems that the functions are executed correctly but the movement is not visualized. Thanks for your help!
to go
if ticks >= 365 [ stop ]
move
if not any? turtles with [ shape = "person" and movement-done? = false ]
[
tick
ask turtles with [ shape = "person" ] [
set movement-done? false
set reached? false
set at-home-again? false ]
]
end
to move
ask turtles with [ shape = "person" ]
[
if movement-done? = false
[
ifelse reached? = false
[
ifelse patch-here = target [ set reached? true set at-home-again? false ]
[
face target
fd 1
]
]
[
ifelse at-home-again? = false
[
ifelse patch-here = myhome [ show "patch-here = myhome" set at-home-again? true ]
[
face myhome
fd 1
]
]
[
set movement-done? true
]
]
]
]
end

Changing the color of myself

I have the following code where I ask some agents to die:
breed [ readers reader ]
breed [ pallets pallet ]
breed [ trucks truck ]
readers-own [
truck-being-served
pallet-being-served ]
to complete-service [ ?reader ]
ask ?reader [
ask pallet-being-served [ die ]
set pallet-being-served nobody
ask truck-being-served [
if not any? pallets-in-truck [
ask self [ die ]
ask myself [
set truck-being-served nobody
set color green
set next-completion-time 0
]
]
]
]
end
Where pallet-being-served and truck-being-served are pallets and truck agents.
The problem is that the inner ask myself [... it seems not working, bacause the color of the ?reader agent does not change to green. Here I am not sure if I am referring to ?reader or to truck-being-served agent which I have just killed. I would like to change the color to green. Is ask myself [ ... referring to the reader agent?
Regards.
Asking a dead turtle to do something has no effect. Also, please provide a minimal runnable example that illustrates your problem.
globals [next-completion-time]
breed [ readers reader ]
breed [ pallets pallet ]
breed [ trucks truck ]
readers-own [
truck-being-served
pallet-being-served ]
trucks-own [pallets-in-truck]
to setup
ca
create-readers 1
create-trucks 1
create-pallets 1
ask reader 0 [set truck-being-served truck 1]
ask truck 1 [set pallets-in-truck pallets]
ask reader 0 [set pallet-being-served one-of [pallets-in-truck] of truck 1]
end
to complete-service ;reader proc
ask pallet-being-served [ die ]
ask truck-being-served [
if not any? pallets-in-truck [
ask myself [
set color green
set next-completion-time 0
]
die
]
]
end
to test
setup
ask reader 0 [complete-service]
end

Query / create subset of turtles for each turtle

I have an agentset where all the turtles have different values for age/experience. What I would like to do is find the more experienced turtles for each turtle and then follow those turtles. Unfortunately, I get the following error for the ifelse [ age-experience > my-own-age-experience ] line:
Expected a TRUE/FALSE here, rather than a list or block.
Here's my code:
turtles-own [
age-experience
more-dominant
dominant-flockmates
]
to setup
clear-all
create-turtles 10 [ set age-experience random-float 1 ]
reset-ticks
end
to go
ask turtles [
find-dominant-flockmates
ifelse any? dominant-flockmates
[ show "follow the more dominant flockmates" ]
[ show "take the lead" ]
]
tick
end
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles [
ifelse [ age-experience > my-own-age-experience ]
[ set more-dominant true ]
[ set more-dominant false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
Okay, you have several choices here. You can get rid of the error by removing the []
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles [
ifelse age-experience > my-own-age-experience
[ set more-dominant true ]
[ set more-dominant false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
But there's much more efficient ways to code this. If you are going to use the variable more-dominant for other purposes (so you need it), you can use ifelse-value like this (and because it's true/false, you don't actually need ifelse-value but it's a good thing to know about):
to find-dominant-flockmates
let my-own-age-experience age-experience
ask other turtles
[ set more-dominant ifelse-value (age-experience > my-own-age-experience)
[ true ]
[ false ]
]
set dominant-flockmates other turtles with [ more-dominant ]
end
But if the only reason to have the variable is to create the agentset, you can do the whole thing directly:
to find-dominant-flockmates
let my-own-age-experience age-experience
set dominant-flockmates other turtles with [ age-experience > my-own-age-experience ]
end