Updating Simple Preferential Attachment Model in NetLogo - netlogo

There is a model in NetLogo based on simple preferential attachment. Agents create links thusly:
to go
if count turtles > num-nodes [ stop ]
let partner one-of [both-ends] of one-of links
create-turtles 1 [
set color red
move-to partner
fd 1
create-link-with partner
]
layout
tick
end
In this model, a node's chance of being selected is directly proportional to the number of connections it already has. I want to edit this code so that there is a variable, prestige, which also determines the probability that a node will be selected. I understand that I need to create a variable for turtles called prestige, but I'm stuck on how to make it so that the probability that a link will be created is also proportional to the amount of prestige a turtle has.

Related

How to have patches "belong" to turtle

I am brand new to Netlogo and am coding a world with caching animals. They will go to their caches (I set them as blue patches) if their energy value falls below 10. They can find these caches based on a random 'memory' value given to them which is used as an in-radius value. That way, they will face and go towards a cache within their in-radius memory if they are about to die. I am starting to incorporate a home-base system where the turtle remains in a smaller area with their own caches. Does anyone know how I can make a patch belong to an individual turtle? This would allow turtles to have their specific caches in their territory. I have looked into using links and breeds, but links are only between turtles and making the individual breeds for the 50+ turtles at a time seems ineffective and complex. I apologize I don't have any code attempting to have a cache (patch) belong to a turtle, I don't know where to start. Any ideas?
If you want a turtle to remember anything (patches or income or anything else), then you need to assign a variable in a turtles-own statement and then set the value appropriately. Here's some example code fragments. They won't work, and you actual code would likely look a lot different because you will need some design about the conditions under which a cache will be assigned, but they show you what a variable solution looks like.
turtles-own
[ my-caches
]
set my-caches (patch-set my-caches patch-here) ; code when a turtle finds a new cache site
If you want a patch that belongs to a turtle to make that patch unavailable to other turtles, then also set up a patch variable to store its owner.
patches-own
[ my-owner
]
ask turtles
[ if [my-owner] of patch-here = nobody [set my-caches (patch-set my-caches patch-here)]
ask patch-here [set my-owner myself]
]
I suggest you do several NetLogo tutorials, then look at some library models (and understand them) before starting your own model. You need to understand basic concepts like turtles/patches, variables, ticks before trying to build a model.

getting turtles to consider other turtle's variables

I am new to Netlogo and have become stumped with a problem.
I have written a model where one breed of turtles (wombats) randomly chose to move-to different burrows (a second breed of turtles). However, I now wish to make it so that the quality (represented by a number) of the burrow currently on the same patch as a wombat influences the probability of the wombat moving to a different burrow. I had envisaged this to look similar to:
ask wombats[
if random-float 100 >= burrow-fidelity * ( quality one-of burrows burrows-here / 2)
[move-to one-of burrows with [not any? wombats-here]]
]
however this does not work.
Is there anyway that I make the wombat report the size of the burrow currently sharing the same patch (there is only ever one burrow per a patch) and then make the wombat incorporate the reported value into the above equation where "quality one-of burrows burrows-here" is?
Thank you in advance
To report the value of another agent's variable, use the of keyword:
[ quality ] of one-of burrows-here

Identifying subgroups in a flocking Netlogo model

I am working on a flocking model with subgroups of agents that form temporary aggregations. I would like to quantify these subgroups by identifying them with a unique ID and a color. Thus I included the following subprocedure (chain-rule) in the go procedure, right before the tick:
to chain-rule
clear-links
ask turtles [
create-links-with other turtles in-radius distance-chain-rule
ask link-neighbors [
set subgroupID [subgroupID] of myself
set color 5 + 10 * subgroupID
]
]
end
This procedure is correctly linking only those agents within a certain distance, and because links die, it only links agents within what I want to call a subgroup (which is a temporary aggregation). The problem is the labelling: if they just acquire the subgroupID of their neighbors, eventually they all end up with the same subgroupID (and color), regardless of whether the agents still belong to the same temporary aggregation. How to update this labelling just like the links? Thanks in advance.
This is the solution I found with help by JenB, using the network extension's nw:weak-component-clusters. This procedure identifies, on each tick, the weak components of a network of agents linked by a given distance.
extensions [ nw ]
to chain-rule
clear-links
ask turtles [ create-links-with other turtles in-radius distance-chain-rule ]
set subgroups nw:weak-component-clusters
show subgroups
end

find the nearest node that has one-of data

i have two breeds
breed[nodes]
breed [messages]
nodes-own [data]
messages-own [basedata]
i have a network with n nodes. each node has a specific data. im selecting a random turtle as sink.in my network data distributed from a turtle(first all turtles are nodes) to sink.each node that is in the way becomes a message.and each message has a memory space too keep those data that pass from that message.messages basedata keep the original data.
i want sink find the nearest node that has for example "D1".
to setup
setup1
setup-spatially-clustered-network ;create links
ask links [set color white]
end
to setup1
__clear-all-and-reset-ticks
create-nodes number-of-nodes
[
setxy (random-xcor * 0.95) (random-ycor * 0.95)
set shape "circle"
set color green
set value ["D1" "D2" "D3" "D4" "D5" "D6"]
set data one-of value
set label data
set dontpick false
set visit false
]
end
to test1
ask one-of turtles
[
set color red
set label "sink"
set nodenumberdestination who
]
ask min-one-of turtles with [(data = "D1") or (basedata = "D1")][distance turtle nodenumberdestination]
[
]
error : NODES breed does not own variable BASEDATA
There is a conflict between your stated goals in your question and your code, which suggests you have not finished thinking through what you are doing. (The code you posted is also incomplete; for example, it does not include your globals declaration nor setup-messages.) So first a question: did you really mean to use turtles instead of nodes in test1? If yes, that means you allow a message to become your sink. So I'll assume no, as suggested by your actual question. Introduce a new global sink and
to test1a
ask one-of nodes [ ;move this to setup!
set sink self
set label "sink" set color red
]
ask sink [
let _choice min-one-of (other nodes with [data = "D1"]) [distance myself]
ask _choice [] ;do something
]
end
That answers your question as asked. If you really wanted a choice out of all turtles, as suggested by your posted code, you'll have to ask a new question.
the problem is when you do
ask min-one-of turtle with [(data = "D1") or (basedata = "D1")]
it could refers to either nodes and message, while each other doesn't share the same variable.
For example: when it runs on nodes, it will return error when checking [(basedata="D1")] since it doesn't own basedata. Likewise, when it runs on message it will return error when checking [(data="D1")] as well. However, since you haven't created any messages so it will always returning error : NODES breed does not own variable BASEDATA
So, you need to be specific when referring to agentset because any command blocks including variable used will be sensitive to as whose the variables are belong to.

Count neighbors turtles of a specific patch and report true or false

Hello i will try to be quick
I have a room with a fire that expands , and i have two exits , all i want to do is say to agents that if a door is blocked by fire then to go to the other one. i came up with something like this but not result.
to doorblock
show count neighbors with [pcolor = 77] ;; the patch color of the two doors
end
;;to go
ask smarts [ ;;smarts are the agents inside the room that need to get oout
if [ doorblock > 5 ]
[ set target one-of sexits]] ;;sexits is the other door
Anyone got a better idea? Thanks
OK, so if I understood correctly, you want your agents to take a look at the door that is their current target, check if that door has more than 5 fire agents around it, and choose another target door if that is the case.
If your fire agents are just red turtles (with no specific breed), you probably want something like this:
ask smarts [
if count ([ turtles-on neighbors ] of target) with [ color = red ] > 5 [
if-else ([ breed ] of target = sexits )
[ set target one-of nexits ]
[ set target one-of sexits ]
]
]
The key primitives here are:
neighbors, that will give you the patches around a turtle (the patches around target, in this case)
turtles-on, that will give you the turtles that are on members of a patch set (here, that will be the turtles that are on the patches that are the neighbors of target)
and finally, with allows you to get only the turtles from an agentset that satisfy some condition (here, we use it to get only the red turtles that represent the fires).
You should also try to understand the of primitive.
And I guessed you wanted to assign a new target that was of a different breed than the previous one (south if north, north if south) but that's up to you.