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.
Related
I was trying to personB's own variable to update in personA's own list type variable. when I tried to run this code i recived an error message "PERSONB breed does not own variable LEDGER
error while personbs 1 running LEDGER, called by procedure UPDATE-LEDGER...."
I cant change the ownership(If I make it global others can alter). how can I solve this?
My code is:
breed [personAs personA]
breed [personBs personB]
personAs-own [
wallet
ledger
]
personBs-own [
packid
batch-num
]
to start
ca
create-personAs 1 [
setxy random-xcor random-ycor
set shape "person"
set ledger []
]
create-personBs 1 [
setxy random-xcor random-ycor
set shape "person"
set packid 10
set batch-num who
]
update-ledger
end
to update-ledger
ask personBs [
set ledger fput (list packid batch-num) ledger
]
end
[Before starting: please note that in NetLogo breeds are defined first in their collective form and later in their individual form, e.g. breed [cats cat] instead of breed [cat cats], so you should change your breeds declarations accordingly. I'll give my answer as if you used the correct declaration, e.g. breed [personAs personA]. Also, note that breeds in NetLogo are not sensible to lower/upper case, so in general you might also want to give more meaningful names to make it easier to read]
--
It is possible to change turtles' breed by just asking them to
set breed newbreed
This will change their breed and, accordingly, all their breed-own variables (i.e. the turtle will lose its previous breed's variables and will gain its new breed's variables).
However your problem seems to be more fundamental: why did you make ledger a personAs-own variable if you want personBs to use set ledger? This is the crucial point.
There are two possibilities here:
You want each turtle to have a ledger to operate on. In that case, ledger must not be a personAs-own variable; it has to be a turtles-own variable (or, if in your full model you have other breeds who do not need ledger, then make it both a personAs-own and personBs-own variable). In any case, no global variables involved (a global variable only has one value for everyone, so that's not what you need).
You want personBs to be able to operate on the ledger of personAs. In that case, personBs will have to ask personAs to modify their ledger; or, alternatively, some personBs can operate on the ledger of some personAs by indeed using the of reporter (see here); for example:
; Solution with 'ask':
ask one-of personBs [
ask one-of personAs [
set ledger 10000
]
]
; Solution with 'of':
ask one-of personBs [
set [ledger] of one-of personAs 10000
]
Important update
Your expression "If I make it global others can alter" suggests me that you're thinking in terms of other programming languages, where you classify variables based on the level of access to that variable that other parts of the programme have.
Note that this is not the case in NetLogo: all parts of the programme (in this case: all agents) have access (even if indirect) to every variable through ask and/or of. No matter whether a variable is turtles-own, links-own, breed-own or patches-own. Every agent can read any other agent's variables. But also: every agent can modify any other agent's variables (see the code examples that I made regarding point 2 above). Therefore, making a variable something-own simply means that those are the agents carrying that variable.
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.
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