I'm doing an ABM model on couple bargaining. On it, some turtles calculate their utility by taking account of common resources (which are possessed by the undirected link between a turtle and his couple). The link was created with
create-link-with turtle (who - 25)
and the utility is being calculated with
to W-Ut-compute
set utility ( Wworkprod * ([work] of my-links ^ (workneed / (workneed + houseneed))) * Mhouseprod * ([house] of my-links ^ (houseneed / (workneed + houseneed))))
end
The code checking worked, but the go button doesn't.
^ expected input to be a number but got the list [-2.1300000000000017] instead.
error while women 100 running ^
called by procedure W-UT-COMPUTE
called by procedure GO
called by Botón 'go'
How can I use the link values on its variables to do the turtles calculations?
Regards, thanks for your attention.
Since my-links is the agentset of all the turtle's links, [work] of my-links returns a list (albeit a list of only one item, since there is only one link).
If you want to extract the one link you're interested in from the my-links agentset, you can use one-of:
[ work ] of one-of my-links
As the name implies, this will randomly select one of the turtle's links. But since there should be only one anyway, it will always be the same.
Related
With the use of the myself primitive, I want a patch with a certain land use to make buildings of that type in a specific radius, but it's not working. Here is the code:
patches-own [land-use] ;land-use can take many types: "residential", "industrial", "commercial"
...
to grow
ask patches with [land-use = "residential"]
[ask other patches in-radius 10 [
if [land-use = "residential"] of myself [build-house]]]
end
How can this be fixed?
The problem there is not myself but the use of of. Two things to fix:
of requires the reporter to be in square brackets. Only the reporter that of refers to, not the whole condition being tested (as in your case where you are testing a condition).
You should not specify the value of the variable but just its name. Just as in normal language: you wouldn't say "If your hair colour equals my blonde", but you would say "If your hair colour equals my hair colour".
The resulting syntax is:
if (land-use = [land-use] of myself) [
build-house
]
Parentheses surrounding the condition are optional, I use them as a stylistic choice.
PS Regarding point 2 above... of course you could keep the value of the variable (i.e. "residential") instead of the name of the variable (i.e. land-use), and in that case drop of myself.
You would have:
if (land-use = "residential") [
build-house
]
And as of now it would work because the patches starting this process are just those with land-use = "residential"... but this doesn't look like great code, as it is not extendable to other variable's values and it contains more hard-coding than necessary.
I'm building a model where turtles "search" a subset of patches for a resource according to different search criteria.
I'm trying to build reports that return a sorted list or agentset of patches that a turtle can then use as an itinerary for it's search.
For some reason I'm having trouble storing the itinerary in a turtle owned variable.
an example reporter is:
to-report availability
let sorted-patches sort-on [ ( (space - occupants) / space ) ] patches with [space > 0]
report sorted-patches
end
when I do show availability in the console, it prints out what I expect, an ordered list of patches.
But if I do
let test-variable availability
show test-variable
it returns
ERROR: Nothing named TEST-VARIABLE has been defined.
is this a problem of scope somehow, can I not use let as an observer?
Is it a problem of type? Can I not store an agentset as a named turtle-owned variable?
Is there a way to do the same thing with a list instead of an agent set?
Thanks
From your description, it's a scoping problem. But the problem is not that you are trying to use let with an observer, it's the scope of let. NetLogo is not really interactive in the sense you are trying to do - the variable created by let is thrown away at the end of the line.
If you type let test 3, hit enter, then type show test, you will get the same error. However if you type let test 3 show test, then it will return 3.
Why are you needing this from the console? If it's for testing, then you can look at it the way you have already found - simply by show availability. If you are using it for turtles while the model is running, then it is not interactive and there's no problem.
The netlogo docs give the following example
show count turtles-here
=> 10
show count other turtles-here
=> 9
and the documentation says the "other" command excludes "this" agent. My question is ... WHICH agent? Seems like this command can be run in the observer context and so no agent. Or at least in this example, the context could be a patch context in which case the "other" would exclude ALL the turtles? Is there some mechanism to set the context for a particular agent? Maybe:
ask agent [
show count other turtles-here
]
in which case why didn't the NetLogo code snippet include that?
The agent excluded is the agent being asked. ask, ask-concurrent, and of set the context. For example,
ask turtle 0 [ show count other turtles ]
counts all turtles except for turtle 0.
ask turtles [ show count other turtles ]
iterates over each turtle individually. In each iteration, other excludes the current turtle.
other never excludes agents of a different type. That is,
ask patch 0 0 [ show count other turtles ]
will just count all the turtles since none of the turtles are patch 0 0.
The agent of the current context can be referred to with self. The agent that other excludes will always be self. Thus,
ask agents [ show count other agents ]
is exactly equivalent to
ask agents [
let this-agent self
show count agents with [ self != this-agent ]
]
(note that this can be expressed more succinctly using myself, but since myself is way more confusing, and way worse named, than other I'm avoiding it here)
Seems like this command can be run in the observer context and so no agent.
This is in fact a bug! I've created an issue for it here: https://github.com/NetLogo/NetLogo/issues/757
I am fairly new to Netlogo and have been working through Railsback & Grimms excellent book while trying my own stuff on the side
Currently, I am trying to code a kind of money transfer whereby two turtles meet (e.g. Turtle 1 and Turtle 2), and the two turtles then share money (e.g. T1 has $4 and T2 has $6, they both leave with $5)
The code I have tried using is as below
to currency-share
let neighbor one-of bystanders-here ; identify neighbor around
if neighbor != nobody ;; is there a neighbor? if there is
[ set currency round ((currency + neighbor currency) / 2)] ; share money
end
Unfortunately the code isn't working and I can't find any examples through the forums which use a similar idea. Perhaps I'm searching incorrectly (using key words like turtle exchange, share etc. normally comes up with patch sharing). If anyone has any models they could recommend where such exchanges happen, or if anyone knows how I may improve my code, please let me know. Thank you.
At first glance, this seems like a simple syntax problem. To get the currency of the neighbor, you should be using of:
set currency round ((currency + [ currency ] of neighbor) / 2)
But since you also said that you want both turtles to get the new amount, you also need to add:
ask neighbor [ set currency [ currency ] of myself ]
Or, perhaps less confusingly you could do something like:
set new-amount round ((currency + [ currency ] of neighbor) / 2)
set currency new-amount
ask neighbor [ set currency new-amount ]
One last variant, slightly better in my opinion because more general (and perhaps even clearer) is:
let sharers (turtle-set self one-of bystanders-here)
let new-amount mean [ currency ] of sharers
ask sharers [ set currency new-amount ]
In this last one, you don't even need the if neighbor != nobody check because if there are no bystanders, turtle-set will build an agentset containing only self and the mean currency of that set will just be the present currency value.
I am implementing an evacuation simulation of a lecture hall.And i have two types of students those who sit on tables and extra students who allocated randomly inside the class.So i created two sliders in order to allocate the students at the desired numbers.The sliders are named extrastudents and standarstudents. When the simulation starts i want all the students (both in tables and extras students) to go to the nearest exit ( i have two exits ) .So i implemented that for only the students that are seating down :
ask standarstudents [
ifelse pycor > 0
[ set target one-of nexits]
[ set target one-of sexits]
face target
]
Nexits is the north exit.
Sexits is the south exit.
The problem is that i get this error and i can move on :
ASK expected input to be an agent or agentset but got the number 3 instead.
error while observer running ASK.(The number 3 derives from the slider that user is pick)
called by procedure SETUP
called by Button 'setup'
org.nlogo.nvm.ArgumentTypeException: ASK expected input to be an agent or agentset but got the number 3 instead.
any ideas?
Well, if you have sliders named extrastudents and standarstudents, those two variables are numeric values representing how many students of each kind you want, not the students themselves. Like the error message says, the ask primitive works with agentsets that represent "who you are asking".
Have you actually created your students? Putting sliders on the interface won't do anything by itself. I would suggest renaming your sliders to something like num-extrastudents and num-standarstudents and then using code like this to initialize your population:
breed [ extrastudents extrastudent ]
breed [ standarstudents standarstudent ]
to setup
create-standarstudents num-standarstudents
create-extrastudents num-extrastudents
end
Then, the code you have posted would work because extrastudents and standarstudents would be breeds of turtles, and thus, agentsets.