In my Anylogic model I have a option list "Issue". In "Issue" I put twelve values ("a", "b" and so on...). How can I assign randomly one of these values to each agent (in my model agents are customers) and be sure that value assigned is different for each agent entered?
1 Answers
If you want a random option list value (say for each agent you create from a Source block), use a Custom Distribution which returns each option list value with a given probability. (In the Custom Distribution properties interface, it talks about "Number of observations" but these can also just be probabilities; it just uses the relative values of these settings to determine how likely each outcome is.)
If you want to uniquely assign the option list values (but in a random order) you'll need to use some Java to do so:
Store the option list values (which you can get an array of via the option list's
values()
function) in a list (AnyLogic Collection). Use aLinkedList
because that is more efficient to remove them from.Store the number of alternatives remaining in a variable. (Let's call this
n
for simplicity.)Each time you want to allocate a value, sample a random number from 1 to n (sample from a discrete uniform distribution using
uniform_discr(1,n)
) and remove that entry from the list (list'sremove(int index)
function), assigning it to the agent. Decrement the num-alternatives-remaining variable.
Obviously you have to ensure that the number of agents created does not exceed the number of option list values (or have some scheme to 'reset' the situation in some way at that point).

- 2,432
- 1
- 17
- 20
-
Thanks for your answer. But I don't understand how to connect single outcome to single agent that enters in the discrete process (I want that each customer agent is associated to one type of Issue) – Stranieri Andrea Cosimo Jun 27 '21 at 10:12
-
OK added alternative for the uniquely-allocate-randomly interpretation. – Stuart Rossiter Jun 28 '21 at 08:31