Netlogo - Behaviour Space overwriting a set variable - netlogo

I am using BehaviourSpace to run simulations. In my code I set variable A (near-radius in this case) to be 0,25 of variable B (detection-range), but in BehaviourSpace I set variable A to a fixed value, and I have a multitude of values for variable B.
Code:
set near-radius detection-range / 4
BehaviourSpace:
["near-radius" 4]
["detection-range" 2 8 14 20]
When I run these simulations will variable A stay at that fixed value of 4, or does is change according to my code (to 0.5, 2, 3.5, 5)? What takes precedence, the code, or BehaviourSpace?

The code takes precedence. Think of BehaviorSpace providing the initial values to your global variables, or as the value that would be on a slider or other input widget. If you have the slider named my-slide set to 5 and somewhere in your code it says set my-slide my-slide + 2, then the slider will actually move to reflect the updated value of the global variable.
To get the flexibility you want, you can use if [behaviorspace-run-number = 0] [set near-radius detection-range / 4] or similar. This will only run your code line when the model is not controlled by BehaviorSpace.

Related

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 exchange variables numbers

I'm asked to do a program that asks for two numbers, the first variable for example is 4 and the second is 5, i need the program to show the first variable as 5 and the second one as 4, so i need the variables to exchange their values
Thanks :DDDD
I think you are asking for number swapping logic.So you can use two logic to swap the number
1. By using 3rd variable.
2. Without using 3rd variable.
Their respective logic's are as follows.
Suppose you have x=4,y=5;
take 3rd variable like temp;
temp=x; x=y; y=temp;
and 2nd logic.
x = x+y; y=x-y; x=x-y;
Such questions are usually asked to reduce the space complexity and to do so we take the following approach:
a=a+b;
b=a-b;
a=a-b;
for example we take a=4 and b=5
a becomes 9
b becomes 4
a becomes 5
finally a=5 and b=4 (swapped)

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.

NetLogo - Behavior Space - controlling variable value

I am having a problem in working on Behavior Space. I have 3 parameters, percentage A, Percentage B and Percentage C. I want to vary values of these three in behavior space experiment but the sum of it must be always 100. For example, Percentage A 30%, Percentage B 30%, Percentage C 40%.
["percentage A" 50]
["percentage B" 25]
["percentage C" 25]
One way to skip unsufficient parameter settings would be the use of a stop condition. In the variables section of "Behaviour space" you can vary your parameters automatically by a range definition like:
["percentageA" [0 10 100]]
["percentageB" [0 10 100]]
["percentageC" [0 10 100]]
This would of course generate combinations which do not have a sum of 100.
Next in the reporter section you could add a reporter, which helps to filter your results later on:
(percentageA + percentageB + percentageC)
In the bottom section of the Behaviour Space Menu you can then simply add a stop condition like:
(percentageA + percentageB + percentageC != 100)
This condition will skip all unsufficient variations. Nevertheless you still would have entries in the output file for runs with unsufficient combinations but you can easily filter them. Just use the defined reporter and select only those entries with a value of 100 in that column.