Search code examples
variablesnumbersanylogicagent

AnyLogic - assign number to agent and use it for calculations


I need help programming a process in AnyLogic.

I want to assign a specific number to an Agent (50%=1,20%=2,30%=3). And later I want to use the number to add to a stock. For example: if the Agent has the number 3 I want the stock (variable) to go down exaclly this amount.

I tried using a Parameter on the Agent, but I am only able to create a string and with that I can't calculate later…

I would be very happy if anyone knows a solution to the Problem! :)


Solution

  • Here is a simple solution for your case:

    1. set the parameter type to "int"
    2. Assign the initial value according to your probabilities, as below. Note that for numbers 2 and 3, it is a relative probability, given that it was not drawing value 1

    Each agent instance will draw a number between 1 and 3 now (50% 1, 20% 2 and 30% 3). Then, you can do your stock adjustments with that param

    enter image description here