identify highest value of several variables of one agent - netlogo

I have an agent that has 3 variables quantifying the area required for certain tasks as calculated by other agents. The agent has another variable "max_area", and in each tick, this should be given the maximal value.
e.g the agent has the variables
area_cattle: 100
area_gather: 200
area_fields: 300
tick
area_cattle: 200
area_gather: 500
area_fields: 200
and i want it to set its variable max_area to 300, then in the next tick to 500.
any ideas?
many thanks!

You can built a list out of the values in your three variables and use max on that list:
set max_area max (list area_cattle area_gather area_fields)

Related

How to measure a set of attributes of individual agents in Behaviour Space?

So far, all the experiments I have run using Behaviour Space have been to either record global variables or the average values of agent variables across different agentsets.
However, I need to measure a set of attributes (violence, entitativity, homogeneity, size) of individual emergent agents (extremist groups) at two/three different timesteps each run. I also need to do this across a number of different model scenarios and ideally have it all summarised in the same spreadsheet. The aim is to plot the relationship between each agent attributes, with individual agents as my cases.
I can't seem to workout if this is possible using Behaviour Space. I have tried using e.g. [violence] of groups as a reporter in Behaviour Space, but the output is then a single string variable that I can't do anything with. I've also thought about using the export-world primitive but, from what I understand, this will overwrite the file every time it is executed or create separate files each time.
There may be a more elegant way to do this but the following should work.
Create global variables, say v0, v1, v2 ...,vn for the individual violence within group n.
Set these at each tick. Report them separately in Behavior space.
Example:
globals [ mass-violence v0 v1 v2]
turtles-own [ violence]
to setup
clear-all
create-turtles 3 [ setxy random-xcor random-ycor set violence 0 ]
reset-ticks
end
to go
set mass-violence 0
if ( ticks > 4 ) [ stop ]
ask turtles [ set violence random 100 set mass-violence mass-violence + violence]
set v0 [violence] of turtle 0
set v1 [violence] of turtle 1
set v2 [violence] of turtle 2
print (word mass-violence " " v0 " " v1 " " v2 )
tick
end
Or you could parse the string you ended up with in Excel using Excel commands to pull selected items out of the string and put them into separate columns. That would end you up in the same place. For example, 5 runs of the above code produces this:

Reporting a list in behaviorspace Netlogo

I want to capture the agent set of agent variable X in behaviorspace.
to-report MeanOfX
report mean [X] of turtles
end
to-report AgentSetOfX
report [X] of turtles
end
After I run the experiment I am not getting the same mean of my agent set, and also weird numbers. Is this the right way to do it?
Yes, those reporters will report the mean value of X for your turtles and a LIST of the X VALUES for the turtles, like "[ 1 34 3 4 8 92 ]" It will not return an "agent-set" containing a SET of TURTLES themselves despite your name. Did you want such an agent-set for some reason?
If you are using any randomization at all anywhere there is no reason the means should come out the same for different runs. If you need the randomization-generated X values to be identical across runs you should set "random-seed" to some value in your setup.
if the values of X are "weird numbers" you need to debug using some logic or printing out the X values as you generate them to see where they deviate from not being weird.

How to create condition in NetLogo that 2 slider values cannot exceed defined value?

I created a model which as 2 different sliders, namely ratio1 and ratio2. They are located on the interface and their values should add up to 1 (here: labour-unit), and also cannot exceed this value. For now, NetLogo let's me exceed the condition.
I tried this:
to setup
create-turtles number-of-turtles ;; number of firms to be defined through slider
set labour-unit ratio1 + ratio2
set labour-unit 1
end
Therefore, my question is: How to create a condition in the setup that 2 slider values cannot exceed a defined value?
Is there any reason you actually need two sliders if the values always add to 1? Could you just have one slider called "proportion with labor-type x" or whatever you're modelling? Then, you can just have reporters to return the values for the actual proportion you're after- for example:
to-report ratio1
report proportion-slider
end
to-report ratio2
report precision ( 1 - proportion-slider ) 2
end
Then on your interface you could have the slider (and monitors if needed):

How to let agents select and remove an item from a list in NetLogo?

I'm relatively new to NetLogo so this may be more straightforward than I think, but I would appreciate any help.
Is there a way to let agents select a number from a list, and make it so that other agents cannot select the same number?
I'm giving each agent in a group a time to wait before they start walking. I've made a list of wait times:
set intervals-list [0 50 100 150]
I try to have each agent have a unique interval-time, but using "one-of" leads to repetition. Can I let each agent select a unique value?
Thanks a lot
You could shuffle the list, then have each agent remove the number it uses:
let intervals-list shuffle [0 50 100 150]
ask turtles [ ;; assuming there are four turtles
set interval first intervals-list
set intervals-list butfirst intervals-list
]
Other solution approaches are possible.

Constructing a set of variables

I have a question about Netlogo. I have two breeds of turtles, breed1 and breed2. Breed2 has a variable called theta. First, a random number of breed1 turtles change to breed2; the breed2 then theta set at random. Later, another random number of breed1 become breed2, who will also have theta set at random.
My two questions are:
1.) How can I ensure that only those turtles that change their breed in the second round of breed-changing set their theta variable? I don't want those that changed in the first round to lose the theta variable that was set for them immediately after changing.
2.) Is there a way I can construct a set of all the theta variables that have been set so far? I want my breed2 to later on make decisions based on the maximum value of theta that has been set so far.
Thank you!
You should ask two separate questions separately, but ...
There are many ways to do this. Example 1: If you always update to a nonzero value of theta, just test for a zero and only change a zero. Example 2: add a can-change-theta attribute to breed2 and always initialize it to true but change it to false after resetting theta. Example 3: gather your new breed2s into an agentset (or a list, if necessary) and change theta only for these turtles.
If you really want the max, you don't need all values. Just add a global variable max-theta and update it each time you update a theta. If you really want all, add a thetas global and initialize it as an empty list; append to this list each time you update a theta attribute, and use max to pull out the max whenever you wish.