netlogo t-t communication example, chance to spread message slider - netlogo

I want to add a slider that shows the chance to spread the message to "Communication T-T Example" on Netlogo.
It's supposed to show the probability of the second turtle to receive the message from the first one who has the message, and it should be adjustable by the user.
Yet I don't know how I should modify the code in such a case.
I couldn't find any similar question in previous ones, I would appreciate your recommendations and helps, thank you.

Suppose you define your slider like this:
then it's just a matter of adding a simple condition to the communicate procedure:
to communicate
if any? other turtles-here with [ message? ]
and random 100 < transmission-probability
[ set message? true ]
end
You could also define your probability to be from 0 to 1 and use random-float 1.0 instead of random 100.

Related

How to efficiently create data on one variable all agents have

I'm working with a NetLogo model on EV charging behaviour. All (500) agents monitor their my-charging-demand per tick and I want to find out what happens to this emergent behaviour when I change the policy intervention that is active (costs of electricity in this case). I am trying to show changes in charging characteristics such as charging-duration, charging power etc.
What is the best way to create data on the agents' my-charging-demand in time?
Right now I am plotting all their data in one graph using the following code:
ask adopters
[ create-temporary-plot-pen (word-who)
set-plot-pen-color color
plotxy ticks my-charging-demand
]
It works, but unfortunately it also made the model incredibly slow, as 500 pens are to be updated every tick. The model needs 105120 ticks before a whole year/run is completed, as each tick in the model represents 5 minutes. Therefore, speed does matter :-)
Is there a more efficient way to keep track / create data of one variable all agents have?
If I have understood this correctly, you want each agent to remember the value of its variable my-charging-demand across all time. If so, the easiest way (but I don't know if it's more efficient) is to have the list as a turtle variable. So, modify your turtles-own to add another variable:
adopters-own
[ ....
my-charging-demand
my-charging-demand-series
]
And wherever you have the code for calculating demand, add the result to the list
ask adopters
[ ...
set my-charging-demand ...
set my-charging-demand lput my-charging-demand my-charging-demand-series
...
]
I can't imagine a plot with 500 lines is readable. The plot should do something like the average of my-charging-demand or the proportion of turtles with my-charging-demand greater than some threshold.

How to coding divisible number in Netlogo

I have a problem about divisible number because I want to use the number of ticks to code in my project. For example, I want the turtle to start doing something in specific time (like in every 30,60,90..., number that able to be divided by 30).
I have no idea about it so if you guys have any suggestion about it?
You'll want to use the modulos operator. In your forever go function, you could use the following code that checks whether enough ticks have passed.
if ticks mod number = 0 [ask turtles [do-something]]
Don't forget to tick your simulation at the end of your go.

how to plot an agent attribute against time

I am coding a traffic simulation and I want to plot a property of the patches against time.
Can you help me with the coding?
I am trying to introduce an if clause that a monitor (representing budget) will produce a certain amount of money when the IRI or USER COST reaches a certain number.
Please, I will be glad if you could help me with this.
Hope to hear from you soon.
Kind regards,
Jephunneh Bonsafo-Bawuah.
I tried creating a monitor it reports the amount once and that's all but I wanted it to report continuously.
I tried using a code but that didn't also work
to budget
ifelse IRI > 220
[ set budget 20000 ]
[set usercost 0]
end
the error message says
set expects two inputs

NetLogo monitor widget display changes when nothing is happening

I have a NetLogo model, simplified to this:
to setup
clear-all
create-turtles 1000 [
fd 100
]
end
When I add a monitor widget to the UI, with a reporter like mean [xcor] of turtles and then run setup, the values in the monitor change a slight bit constantly. It might show 0.2305090322262271 one moment then 0.2305090322262268 the next, and then another similar number on and on.
What is making my monitor widget flicker or flash like this? How can I prevent it?
This is caused by a combination of a few things:
NetLogo's use of floating point numbers, which can produce small accuracy issues. See Floating point accuracy in the NetLogo programming guide: https://ccl.northwestern.edu/netlogo/docs/programming.html#math
Agentsets such as turtles are always returned in a random order.
Monitors re-run their reporter calculation constantly, even when you are not running any model code with a forever button or through the command center.
So the monitor constantly re-runs its mean [xcor] of turtles reporter, but the turtles agentset gives the turtles in a random order, and so the floating-point inaccuracies for mean will accumulate in a slightly different way each time due to the order differences. The end result is you see very slightly different numbers flashing through the monitor widget while nothing is happening.
You would see the same problem doing sum [xcor] of turtles or variance [xcor] of turtles - anytime you're reducing a bunch of floating point numbers from an agentset into a single value. You can also see the problem running your reporter code directly in the command center repeatedly, without a monitor widget at all.
The fixes are fortunately pretty easy:
Sort your numbers before you calculate: mean sort [xcor] of turtles, sum sort [xcor] of turtles, variance sort [xcor] of turtles. If the numbers are in the same order you'll still have small floating-point inaccuracies, but they'll be the the same every time so you won't see the values change. This is probably the best solution, but it can be slow if you have a really large agentset.
Change the Decimal places setting of your monitors to a number where you don't notice the changing values. Since the differences in results should be small, this is usually possible.

Preferential attachment: assigning edges with a certain probability

I'm trying to create a preferential attachment network with a tunable gamma parameter in Netlogo. I've posted a more general question here, but I have the feeling that I do not fully understand the mechanisms behind the preferential attachment model so I will ask some other questions about it. I have the following definition for the network:
"First, each individual is assigned a number of ties according to the distribution p(k) ∝ k^−γ, where k is the number of ties a particular indiviudal has. Then, connections are made between individuals at random, beginning with those assigned the most number of ties in the first step, until either all connections assigned in step one are accounted for, or no additional connections can be made without adding to the assigned number of ties per person. "
This definition seems to indicate that nodes first have to be created, then the number of ties have to be assigned, after which these ties have to be directed to other nodes. If we take a look at the preferential attachment models in the netlogo models library, the procedure is very different. Namely, nodes are created sequentially. With the nodes selecting who to link with based on the number of already existing ties, as if they were lottery tickets.
So currently I am trying to figure out what the best procedure is to create the network with the tunable gamma. To make the first described procedure work I should create a set of nodes and then assign the number of ties given the distribution. How is this done?
Thanks!
EDIT:
Based on the answer #JenB has given. I want to make sure I am understanding it correctly. If I have the following code:
to create-new-nodes [n]
clear-all
ask patches [ set pcolor white ]
create-nodes n [
set color red
set shape "circle"
]
reset-ticks
end
to wire-pref-attach
create-new-nodes num-nodes
set friends [;;distribution should be included here?]
ask nodes
[ let new-edges friends - count my-edges
if new-edges > 0
[ let candidates other nodes with [ count my-edges < friends ]
create-edges-with n-of min (list new-edges count candidates) candidates
[ hide-link ]
]
]
radial-layout
end
The set friends command should include the distribution with the tunable gamma, right? How is this achieved? By using a weighted rnd extension? Also, I still don't fully understand the meaning of both A and m. Anyone care to explain in the most basic language possible? I understand that A is defined as the inherent attractiveness and m is the number of edges a new node creates, but how do high (low) values of these parameters translate to the outcome of the network structure?
EDIT2:
Received advice from a different source to use the following 'hack' to correctly program the network algorithm. The code should have the structure:
Let k_i be the degree of node i
Let a variable D (for denominator) be the sum of all (k_i)^(gamma)
Iterate on the nodes; for each node i, create an edge if random-float 1.0 <= k_i ^ gamma / D
this is considered to be a hack, because the model creates on average one link per turn. It does not create exactly one link per turn.
I've tried to code this in the following way:
to wire-pref-attach
create-new-nodes num-nodes
let connect? False
let denominator (count nodes * k_i ^ gamma) ;;HOW TO DETERMINE K_i?
let numerator (k_i ^ gamma)
ask other nodes [
if (numerator / denominator) >= random-float 1.0 [
set connect? true
create-link-from myself
]
]
radial-layout
end
However, I still don't understand how I should determine k_i and how this relates to variables m and A mentioned in the comments below.
That 'definition' is the general algorithm for creating a network with an arbitrary degree distribution. That is, you assign each node an intended or target degree from whatever distribution you want. Then, you simply create links until that target degree is reached. Has nothing to do with preferential attachment, except that the distribution you have provided is the distribution that arises when the preferential attachment mechanism is used.
I think you need the algorithm described in Dorogovtsev et al (2000) Structure of Growing Networks with Preferential Linking (see https://journals.aps.org/prl/pdf/10.1103/PhysRevLett.85.4633 if you have access). In the Barabasi-Albert algorithm, the nodes in the existing network for the new node to attach to are selected with probability proportional to degree (or k in your question). In the extended algorithm, each node has an inherent attractiveness A and the probability of selection is instead A+k.
Equation 12 in the paper describes the relationship between the exponent (your parameter gamma as: gamma = 2 + A/m where m is the the number of edges being attached with each node.
Also see NetLogo Efficient way to create fixed number of links for potential code to generalise.