0

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 Answers1

0

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 a LinkedList 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's remove(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).

Stuart Rossiter
  • 2,432
  • 1
  • 17
  • 20