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

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):

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.

NetLogo: Neet to set the variable's value to a random number within a range

Dear NetLogo Community,
I am aiming to set a variable's value to a number between -1 and 1. I have tried the following code but in vain.
to xyz
[
set probability-of-wom compute-wom [-1 1]
if probability-wom > 0 [...]
]
end
to-report compute-wom -1 1
report -1 + random-float (1 - -1)
end
probablity-wom is a global variable in this case.
Appreciate your support in advance.
Thank you.
Regards,
Shreesha
Shreesha
Let's say you want to generate a random number between lower and upper. Then your compute-wom would be
to-report compute-wom [lower upper]
report upper - random-float (upper - lower)
end
In your case, you would
set probability-of-wom compute-wom -1 1
But a couple of comments. First, what you are generating here is a random number between two limits (as your title suggests), so calling it a probability could be misleading to anyone reading your code. Probabilities will normally be in the range from zero to one. If you really are just looking to do something with a 50% probability, you can simply say
if random-float 1 >= 0.5 [...]
Second, reporters should generally take variable arguments if they are to have arguments at all. Note that since you hard code -1 and 1 in the body of your to-report compute-wom reporter, passing them as arguments is redundant, and possibly misleading to anyone reading your code.

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.

Can we code to calculate the difference of tick values in netlogo

Actually i need to calculate density increase/decrease rate of human population for my model, the model is same as i asked in unable to make non-stationary turtles change their direction if an obstacle a patch ahead (a specific area and a building within it, people are randomly visiting and going). What i thought that i will be needing to save the tick values for initial population value and after some time difference updated population value. Below is the procedure i want to plot graph for.
to density-increase-rate
store population-density at some initial time (ticks)
store updated-population-density at some later-time (ticks)
calculate density-increase-rate
( ( ( updated-pd - previous-pd ) / (updated-tick - previous-tick ) ) * 100 ) / 10
end
I am calculating population-density in my code as
total-density-inside-boundary count people with [inside-boundary?]
for any suggestion or code help i am very thankful.
If you just want to plot this change, there is no need to store it because the plot will update each tick.
globals [total-density-inside-boundary density-increase-rate]
to calc-plot-vars
let old-density total-density-inside-boundary
set total-density-inside-boundary count people with [inside-boundary?]
set density-increase-rate (total-density-inside-boundary - old-density) / 100
end
Then have a plot on the interface with plot total-density-inside-boundary and plot density-increase-rate. You may need to do some rescaling to have them both on the same plot.
If you want to have the rate based on total time, then create a variable to hold the initial value and calculate it at the specific time you think initial means (such as the end of the setup or at a specific tick).
globals [total-density-inside-boundary initial-density]
to setup
... (commands that create your people)
set initial-density count people with [inside-boundary?]
...
end
to go
...
if ticks = 1 [ set initial-density count people with [inside-boundary?] ]
...
end
Then have the rate plot in the interface have plot (total-density-inside-boundary - initial-density) / 100