Reputation: 35
I am trying to model an "online forum" where the model starts with 2 connected agents that are of 2 breeds (A-agents and B-agents).
How do I make the newly created agent attach to one of the 2 breeds of agents based on probability of selection?
Here is my code so far, up to point 1.
breed [A-agents A-agent]
breed [B-agents B-agent]
to setup
clear-all
reset-ticks
create-A-agents 1
[ set shape "triangle"
set size 1
set color blue
setxy random-xcor random-ycor
]
create-B-agents 1
[ set shape "circle"
set size 1
set color red
setxy random-xcor random-ycor
]
ask B-agents [create-links-with A-agents [set color green]]
tick
end
to go ;; create a new node based on the emprical user distribution of A-agents/B-agents
let p random-float 100 ;; create a random number between 1-100
if (p >= 97) [create-A-agents 1
[ set shape "triangle"
set size 1
set color blue
setxy random-xcor random-ycor]]
if (p < 97) [create-B-agents 1
[ set shape "circle"
set size 1
set color red
setxy random-xcor random-ycor
]]
tick
end
Upvotes: 1
Views: 140
Reputation: 17678
you need something like this (for A-agents, you can write a similar for B-agents) - not tested and probably has syntax errors.
let test-num random-float 1
ifelse test-num < 0.58
[ create-link-with one-of other A-agents ]
[ create-link-with one-of B-agents ]
I haven't included any testing for whether there are actually any agents to connect to, but this should get you going in the right direction.
Upvotes: 3