Dear NetLogo Specialists,
Please can you give me some advice? This is the first NetLogo Model that I have put together and the first time I have posted a query on this forum.
I am currently adapting the Wilensky Voting model from the NetLogo library.
I am interesting in creating two breeds. The first are agents who are part of an “Echo Chamber”, the second Breed are “not in Echo Chamber”.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
breed [ Echos Echo ]
breed [ NotEchos NotEcho ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
As with the Wilensky model, I would like the agents to base their voting decision on the voting choices of their eight friends. I can set up the a network where “Echo Chamber” agents are friends with “Echo Chamber” and “not in Echo Chamber” agents are friends with “not in Echo Chamber” agents . I achieved this adapting code from JenB. The current code is below.
The limitation of this method is that friendships are not across Breeds.
Ideally, I would like a piece of code that allows me to select of the eight friends a breed has and how many are from their own breed and how many other breed. For example, I would like agents in the “Echo Chamber” to have six “Echo Chamber” agent friends and two “not in Echo Chamber” agent friends.
Any help would be much appreciated.
Many thanks for your time,
Paul
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to make-network
;; THE PURPOSE OF THIS IS TO CREATE A NETWORK WHERE EACH AGENT IN THE ECHO CHAMBER IS FRIENDS WITH
;; 8 OTHER AGENTS IN THE ECHO CHAMBER
ask NotEchos
[ let needed 8 - count my-links
if needed > 0
[ let NotEchoscandidates other NotEchos with [ count my-links < 8]
create-links-with n-of min (list needed count NotEchoscandidates) NotEchoscandidates
[ hide-link]
]
]
;; THE PURPOSE OF THIS IS TO CREATE A NETWORK WHERE EACH AGENT NOT IN THE ECHO CHAMBER IS FRIENDS WITH
;; 8 OTHER AGENTS NOT IN THE ECHO CHAMBER
ask Echos
[ let needed 8 - count my-links
if needed > 0
[ let Echoscandidates other Echos with [ count my-links < 8]
create-links-with n-of min (list needed count Echoscandidates) Echoscandidates
[ hide-link]
]
]
;; THE PURPOSE OF THESE IS TO CREATE MEASURES TO VALIDATE AND QUALITY ASSURE THE ABM
ask NotEchos [ set num_NotEchos_friends count my-links ]
ask NotEchos [ set total_NotEchos_vote (sum [vote] of link-neighbors) ]
ask Echos [ set num_Echos_friends count my-links ]
ask Echos [ set total_Echos_Vote (sum [vote] of link-neighbors) ]
ask Echos [show total_Echos_vote]
ask NotEchos [show total_NotEchos_vote]
End
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
You have NotEcho to NotEcho, Echo to Echo and Echo to NotEcho links and will need separate constructions for each. So far you are limiting your candidates to the right breed, but you haven't adjusted your counts of whether they still have slots available. You need something like (not tested):
ask NotEchos
[ let needed 6 - count my-link-neighbors with [breed = NotEchos]
if needed > 0
[ let NotEchoscandidates other NotEchos with [ count my-neighbors with [breed = NotEchos] < 6]
create-links-with n-of min (list needed count NotEchoscandidates) NotEchoscandidates
[ hide-link]
]
]
Note that I switched to my-link-neighbors instead of my-links because it's the turtles at the end that have a breed, not the links. I also changed 8 to 6 because you want 6 of the same breed.
Also, you will need to think about how many of each breed you have, so that the numbers all come out and there are sufficient to make links.
Finally, are Echo and NotEcho really different turtles? Think about two different opinion groups A and B. A talking to A is likely to be echoing similar sentiments and B talking to B as well, but A and B talking to each other are not echoing. In your model, what do you mean when a NotEcho is linked to a NotEcho. It might be that you really want two opinion groups, with preferential attachment to the same group, and then whether they are same or different at each end is a function of the link (relationship) rather than the turtle.
Related
I got 2 large sets of agentbreeds1 (villagers) and an equal amount of agentbreeds2 (houses). I am attempting to link these two together on a one-to-one ratio. So far I tried to do this by the following line, but I am not sure whether it does so correctly:
ask villagers [
create-link-with one-of other houses
]
Just for clarity, if I have villager1 it may only connect to one house that does not have any link to another villager already.
Hopefully one of the bright folks here can help me further!
Thanks in advance.
That's pretty close, but since you have no constraint saying something like "you may only create a link with a house that has no villager already" you will end up with some houses that have multiple villagers linked and some houses that have no villagers linked. All you have to do to correct that is to include that constraint, such that villagers may only link to a house that is not already linked:
ask villagers [
create-link-with one-of houses with [ not any? link-neighbors ]
]
To check that it worked, you can either visually inspect the links or run some variation of the lines below:
ask turtles [
if count link-neighbors != 1 [
show ("I am not linked to just one turtle.")
]
]
If any turtle is not linked to another, or is linked to more than one, it will print the line in quotes.
I want to create various agents from one breed.
like :
breed [ nodes node]
Question:
using this one breed " node ", I want to create some nodes as home, some as consumers, some as cars etc. Is it possible? Please guide me.
Nothing stops you from creating your own variable (e.g. kind) to specify the type of each node:
breed [ nodes node ]
nodes-own [ kind ]
to setup
clear-all
creates-nodes 10 [ set kind "home" ]
creates-nodes 10 [ set kind "consumer" ]
creates-nodes 10 [ set kind "car" ]
end
That being said... why would you ever want to do that?
NetLogo breeds are the right tool to represent different kinds of agents. If all these things are different, they should probably belong to different breeds. Much better, in my opinion, to do:
breed [ homes a-home ]
breed [ consumers consumer ]
breed [ cars car ]
to setup
clear-all
create-homes 10
create-consumers 10
create-cars 10
end
Note that all these things can still be connected by links (i.e. be nodes in a network) even if they are of different breeds.
If there is some other downside of breeds that you are worried about, please let us know in the comments. We can probably alleviate your concerns.
In my study, I'm trying to build a simulation representing of a real work setting, with the aim of creating knowledge on how make people feel better at work.
In particular, I'm modelling a scenario where people work for more than one team (do you work on only one project at a time? Many don't...). To do this, I'm working with NetLogo.
I'm having a problem with an ASK to a specific agent of a custom link-turtle-set. The point is that sometimes it reports an error, saying that "ASK expected input to be an agent or agentset but got NOBODY instead", but it should not arrive to that "ASK" without the agent to exist! What am I doing wrong?
The function is the following:
to TeamRecruiting
;; I ask non-complete teams to...
ask teams with [ teamsize != (count membership-neighbors) ]
[
;; ... count how many individuals they have...
let actualteammembers count membership-neighbors
;; ... to save locally how many individuals they can share...
let teamoverlap overlap
;; ... their target size...
let neededsize teamsize
;; ... and their identity.
let teamwho who
;; then I ask those individuals that have not yet more things than they can handle...
ask individuals with [ indMTM != (count membership-neighbors) ]
[
;; ... to save locally who they are...
let indwho who
let createdalink 0
;; ... then if some conditions have been met ...
if(some conditions)
[
;; I create a link (of my specific type) with the team...
create-membership-with team teamwho
;; I do the following because more than one individual could join the team teamwho in the same run of the function
ask team teamwho [ set actualteammembers (actualteammembers + 1) ]
set createdalink 1
]
;; if the association occurred, ...
if(createdalink = 1)
[
;; we ask all other teams to evaluate if the new connection violates their maximum overlap constraint between the team I am considering from the beginning of the function, and all other teams, in other words...
ask teams with [ who != teamwho ]
[
let numpaths 0
let team2who who
;; I count how many individuals say that they are shared by the two teams
ask individuals
[
if((membership-neighbor? team teamwho) and (membership-neighbor? team team2who)) [ set numpaths (numpaths + 1) ]
]
;; ... and if the number of paths is more than the maximum allowed overlap...
if(numpaths > teamoverlap)
[
;; I take the connection away...
ask membership teamwho indwho [ die ]
;; and I reduce the actual number of team members
set actualteammembers (actualteammembers - 1)
]
]
]
]
]
end
Thank you for your precious help!
I think that the problem is likely to be in the way you refer to the link you are asking to die. membership is an undirected link and so which agent is end1 and which is end2 depends upon the order in which the agents were created. The one with the lower who number is end1 and the other is end2. So, if the team agent was created after the individual agent, that particular link would be membership indwho teamwho. In general, using who numbers at all is bad practice, but the same problem would arise if you used the team and individual agents themselves rather than their who numbers.
Someone with more experience in the use of undirected links than I might have better advice on how to easily refer to an undirected link when you don't know offhand which agent is the older, but something like
ifelse (indwho < teamwho) [
ask membership indwho teamwho [ die ]
]
[
ask membership teamwho indwho [ die ]
]
should work. Using directed links obviates this problem as the creator agent is always end1 and the target agent end2. So, if membership links always are created by the individual, you'll always know that the individual is at end1.
Hope this helps.
Charles
Greeting,
This is the scenario:
I have 2 breed namely: "dog" and "cat"
Links are established within dog breed only and cat breed only, and temporarily there is no cross linkages.
I am looking for a way to hide dog breed and links that is associated with dog only. I would like to add that the links are not randomly generated, they are known links given to the breed. The purpose of doing it this way is that I am doing a network calculation on each breed individually using nw:mean-path-length
In netlogo documentation, I will be using
ask dog[ hide-turtle ] to hide the dog breed. However, I do not know how to hide link associated with dog only. And similarly, I will be using ask dog[ show-turtle ] to make dog breed appear again(with the links associated with dog too) and use ask cat[ hide-turtle ] for my calculation on the other breed.
Thanks for helping out!
ask dogs [ ask my-links [ hide-link ] ]
...will hide the dogs' links.
That being said, if you want to perform calculations on a separate part of a network, you will need to use nw:set-context: just hiding the turtles and links won't affect the results of primitives like nw:mean-path-length.
The netlogo docs give the following example
show count turtles-here
=> 10
show count other turtles-here
=> 9
and the documentation says the "other" command excludes "this" agent. My question is ... WHICH agent? Seems like this command can be run in the observer context and so no agent. Or at least in this example, the context could be a patch context in which case the "other" would exclude ALL the turtles? Is there some mechanism to set the context for a particular agent? Maybe:
ask agent [
show count other turtles-here
]
in which case why didn't the NetLogo code snippet include that?
The agent excluded is the agent being asked. ask, ask-concurrent, and of set the context. For example,
ask turtle 0 [ show count other turtles ]
counts all turtles except for turtle 0.
ask turtles [ show count other turtles ]
iterates over each turtle individually. In each iteration, other excludes the current turtle.
other never excludes agents of a different type. That is,
ask patch 0 0 [ show count other turtles ]
will just count all the turtles since none of the turtles are patch 0 0.
The agent of the current context can be referred to with self. The agent that other excludes will always be self. Thus,
ask agents [ show count other agents ]
is exactly equivalent to
ask agents [
let this-agent self
show count agents with [ self != this-agent ]
]
(note that this can be expressed more succinctly using myself, but since myself is way more confusing, and way worse named, than other I'm avoiding it here)
Seems like this command can be run in the observer context and so no agent.
This is in fact a bug! I've created an issue for it here: https://github.com/NetLogo/NetLogo/issues/757