Reputation: 263
I have some agents on lattice. If we consider an agent $i$, then I will assign different probabilities to all remaining agents depending on agent $i$ characteristics. Now my goal is to pick one of agent $j$ from the remaining agents with specified probabilities and create link from agent $i$ to agent $j$. This I have to do for all agents lattice. [ each time the probabilities change according to the different agents $i$] Can some one help how to implement this on netlogo. Thanks.
Upvotes: 0
Views: 718
Reputation: 9620
If you do not constrain the problem more, computation will get expensive. Here is the basic idea, assuming you have an assign-probabilities
reporter:
to form-links ;;turtle proc
let %others [self] of other turtles ;;list of other turltes
let %p assign-probabilities %others
let %idx random-index %p
create-link-with item %idx %others
end
to-report random-index [#p] ;;input probability dist as list
let %draw random-float 1
let %cum-p item 0 #p
let %ct 0
while [%draw > %cum-p] [
set %ct (%ct + 1)
set %cum-p (%cum-p + item %ct #p)
]
report %ct
end
Here are some things that can help make the computations less costly. If turtles are not created or dying, you can compute the others only once during setup (and set as a turtle attribute). If the probabilities do not change over time, you can do the same with the probabilities. In the latter case, you will then probably want to compute the cumulative probabilities (once), and use a bisection algorithm to produce the random index.
Upvotes: 1